Skip to content

Commit

Permalink
Update WorkflowInput definition to include optional flag + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jun 19, 2024
1 parent cccdddd commit e598454
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,6 +35,7 @@ inputs:
name: "input_2",
doc: "This is the input 2",
type: "File",
optional: false,
},
{
name: "the_collection",
Expand All @@ -50,6 +52,7 @@ inputs:
doc: "",
type: "text",
default: "text value",
optional: true,
},
]);
});
Expand Down
1 change: 1 addition & 0 deletions server/gx-workflow-ls-native/src/nativeWorkflowDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down
4 changes: 2 additions & 2 deletions server/packages/server-common/src/ast/nodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
1 change: 1 addition & 0 deletions shared/src/requestsDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface WorkflowInput {
type: WorkflowDataType;
doc: string;
default?: unknown;
optional?: boolean;
}

export interface GetWorkflowInputsResult {
Expand Down

0 comments on commit e598454

Please sign in to comment.