Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Format2 validation for Any type #75

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/gx-workflow-ls-format2/src/schema/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
Expand Down
15 changes: 15 additions & 0 deletions server/gx-workflow-ls-format2/tests/integration/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down