diff --git a/server/gx-workflow-ls-format2/src/gxFormat2WorkflowDocument.ts b/server/gx-workflow-ls-format2/src/gxFormat2WorkflowDocument.ts index fc0fcde..245a0f4 100644 --- a/server/gx-workflow-ls-format2/src/gxFormat2WorkflowDocument.ts +++ b/server/gx-workflow-ls-format2/src/gxFormat2WorkflowDocument.ts @@ -65,11 +65,13 @@ export class GxFormat2WorkflowDocument extends WorkflowDocument { const inputDocNode = this.nodeManager.getPropertyNodeByName(input, "doc"); const inputDescription = String(inputDocNode?.valueNode?.value ?? ""); const defaultValueNode = this.nodeManager.getPropertyNodeByName(input, "default"); + const optionalValue = this.nodeManager.getPropertyValueByName(input, "optional"); const inputDefinition: WorkflowInput = { name: inputName, doc: inputDescription, type: inputType, default: defaultValueNode?.valueNode?.value, + optional: optionalValue === undefined ? undefined : optionalValue === true, }; return inputDefinition; } diff --git a/server/gx-workflow-ls-format2/src/validation/rules/InputTypeValidationRule.ts b/server/gx-workflow-ls-format2/src/validation/rules/InputTypeValidationRule.ts index ced1137..6798f63 100644 --- a/server/gx-workflow-ls-format2/src/validation/rules/InputTypeValidationRule.ts +++ b/server/gx-workflow-ls-format2/src/validation/rules/InputTypeValidationRule.ts @@ -18,7 +18,7 @@ export class InputTypeValidationRule implements ValidationRule { const inputName = String(input.keyNode.value); const inputTypeValue = documentContext.nodeManager.getPropertyValueByName(input, "type"); const defaultValueNode = documentContext.nodeManager.getPropertyNodeByName(input, "default"); - const defaultValue = defaultValueNode.valueNode?.value; + const defaultValue = defaultValueNode?.valueNode?.value; const defaultValueType = typeof defaultValue; if (inputTypeValue && defaultValue) { diff --git a/server/gx-workflow-ls-format2/tests/integration/document.test.ts b/server/gx-workflow-ls-format2/tests/integration/document.test.ts index 10cfe54..1e4440a 100644 --- a/server/gx-workflow-ls-format2/tests/integration/document.test.ts +++ b/server/gx-workflow-ls-format2/tests/integration/document.test.ts @@ -9,6 +9,7 @@ inputs: input_2: type: File doc: This is the input 2 + optional: false the_collection: type: collection doc: This is a collection @@ -34,6 +35,7 @@ inputs: name: "input_2", doc: "This is the input 2", type: "File", + optional: false, }, { name: "the_collection", @@ -50,6 +52,7 @@ inputs: doc: "", type: "text", default: "text value", + optional: true, }, ]); }); diff --git a/server/gx-workflow-ls-native/src/nativeWorkflowDocument.ts b/server/gx-workflow-ls-native/src/nativeWorkflowDocument.ts index fc0e4dc..83d5f75 100644 --- a/server/gx-workflow-ls-native/src/nativeWorkflowDocument.ts +++ b/server/gx-workflow-ls-native/src/nativeWorkflowDocument.ts @@ -70,6 +70,7 @@ export class NativeWorkflowDocument extends WorkflowDocument { doc: String(annotationValue ?? ""), type: this.getInputType(stepTypeValue, toolStateValue), default: toolStateValue.default, + optional: toolStateValue.optional, }; result.inputs.push(inputDefinition); } diff --git a/server/gx-workflow-ls-native/tests/unit/nativeWorkflowDocument.test.ts b/server/gx-workflow-ls-native/tests/unit/nativeWorkflowDocument.test.ts index 7b0c29d..0ab3134 100644 --- a/server/gx-workflow-ls-native/tests/unit/nativeWorkflowDocument.test.ts +++ b/server/gx-workflow-ls-native/tests/unit/nativeWorkflowDocument.test.ts @@ -50,13 +50,13 @@ describe("NativeWorkflowDocument", () => { [ TestWorkflowProvider.workflows.validation.withOnlyInputs, [ - { default: undefined, doc: "", name: "Dataset Input", type: "data" }, - { default: undefined, doc: "", name: "Collection Input", type: "collection" }, - { default: undefined, doc: "", name: "Text Param", type: "text" }, - { default: 10, doc: "", name: "Integer Param", type: "integer" }, - { default: undefined, doc: "", name: "Float Param", type: "float" }, - { default: undefined, doc: "", name: "Boolean Param", type: "boolean" }, - { default: undefined, doc: "", name: "Color Param", type: "color" }, + { default: undefined, doc: "", name: "Dataset Input", optional: false, type: "data" }, + { default: undefined, doc: "", name: "Collection Input", optional: false, type: "collection" }, + { default: undefined, doc: "", name: "Text Param", optional: false, type: "text" }, + { default: 10, doc: "", name: "Integer Param", optional: true, type: "integer" }, + { default: undefined, doc: "", name: "Float Param", optional: false, type: "float" }, + { default: undefined, doc: "", name: "Boolean Param", optional: false, type: "boolean" }, + { default: undefined, doc: "", name: "Color Param", optional: false, type: "color" }, ], ], ])("returns the expected inputs", (wfContent: string, expectedInputs: WorkflowInput[]) => { diff --git a/server/packages/server-common/src/ast/nodeManager.ts b/server/packages/server-common/src/ast/nodeManager.ts index be157ea..90561a6 100644 --- a/server/packages/server-common/src/ast/nodeManager.ts +++ b/server/packages/server-common/src/ast/nodeManager.ts @@ -208,7 +208,7 @@ export class ASTNodeManager { } } - public getPropertyNodeByName(node: PropertyASTNode, propertyName: string): PropertyASTNode { + public getPropertyNodeByName(node: PropertyASTNode, propertyName: string): PropertyASTNode | undefined { const targetProperty = node.valueNode?.children?.find( (prop) => prop.type === "property" && prop.keyNode.value === propertyName ) as PropertyASTNode; @@ -217,7 +217,7 @@ export class ASTNodeManager { public getPropertyValueByName(node: PropertyASTNode, propertyName: string): ValueTypes | undefined { const targetProperty = this.getPropertyNodeByName(node, propertyName); - const targetValue = targetProperty.valueNode?.value; + const targetValue = targetProperty?.valueNode?.value; return targetValue; } } diff --git a/shared/src/requestsDefinitions.ts b/shared/src/requestsDefinitions.ts index 48280fd..90bd7a3 100644 --- a/shared/src/requestsDefinitions.ts +++ b/shared/src/requestsDefinitions.ts @@ -48,6 +48,7 @@ export interface WorkflowInput { type: WorkflowDataType; doc: string; default?: unknown; + optional?: boolean; } export interface GetWorkflowInputsResult {