From 85e3cd60ca392f3a627d1c5474be81c99c6f669e Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:55:42 +0200 Subject: [PATCH 1/2] Add validation test for properties with Any type --- .../tests/integration/validation.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server/gx-workflow-ls-format2/tests/integration/validation.test.ts b/server/gx-workflow-ls-format2/tests/integration/validation.test.ts index a1f234b..5fca011 100644 --- a/server/gx-workflow-ls-format2/tests/integration/validation.test.ts +++ b/server/gx-workflow-ls-format2/tests/integration/validation.test.ts @@ -111,6 +111,21 @@ steps: expect(diagnostics[0].message).toContain("Type mismatch for field 'top'. Expected 'float' but found 'string'."); }); + it("should not report error for properties with Any type", async () => { + const content = ` +class: GalaxyWorkflow +inputs: +outputs: +steps: + step: + tool_state: + value: "any value" + another_value: 42 + `; + const diagnostics = await validateDocument(content); + expect(diagnostics).toHaveLength(0); + }); + describe("Custom Rules", () => { let rule: ValidationRule; From 9fe28acc4736c5679dbb39007032ad668d5ef300 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:55:56 +0200 Subject: [PATCH 2/2] Fix validation of properties with Any type --- server/gx-workflow-ls-format2/src/schema/definitions.ts | 4 ++++ .../src/services/schemaValidationService.ts | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/gx-workflow-ls-format2/src/schema/definitions.ts b/server/gx-workflow-ls-format2/src/schema/definitions.ts index 0568f86..2b1c880 100644 --- a/server/gx-workflow-ls-format2/src/schema/definitions.ts +++ b/server/gx-workflow-ls-format2/src/schema/definitions.ts @@ -199,6 +199,10 @@ export class EnumSchemaNode implements SchemaNode { return this._schemaEnum.name; } + public matchesType(typeName: string): boolean { + return this.name === "Any" || this.symbols.includes(typeName); + } + //Override toString for debugging purposes public toString(): string { return `EnumSchemaNode: ${this.name} - ${this.symbols}`; diff --git a/server/gx-workflow-ls-format2/src/services/schemaValidationService.ts b/server/gx-workflow-ls-format2/src/services/schemaValidationService.ts index d4425fe..2dc0ba1 100644 --- a/server/gx-workflow-ls-format2/src/services/schemaValidationService.ts +++ b/server/gx-workflow-ls-format2/src/services/schemaValidationService.ts @@ -54,17 +54,20 @@ export class GxFormat2SchemaValidationService implements WorkflowValidator { } } } + private validateEnumValue( node: StringASTNode, - schemaRecord: EnumSchemaNode, + enumSchemaNode: EnumSchemaNode, range: Range, diagnostics: Diagnostic[] ): void { - if (!schemaRecord.symbols.includes(node.value)) { + if (!enumSchemaNode.matchesType(node.value)) { diagnostics.push( Diagnostic.create( range, - `The value is not a valid '${schemaRecord.name}'. Allowed values are: ${schemaRecord.symbols.join(", ")}.`, + `The value is not a valid '${enumSchemaNode.name}'. Allowed values are: ${enumSchemaNode.symbols.join( + ", " + )}.`, DiagnosticSeverity.Error ) );