Skip to content

Commit

Permalink
feat(ns-workflows-1): add support for Workflow Object (#3492)
Browse files Browse the repository at this point in the history
Refs #3392
  • Loading branch information
frankkilcommins committed Dec 4, 2023
1 parent c35931d commit fce4096
Show file tree
Hide file tree
Showing 18 changed files with 447 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/apidom-ns-workflows-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Only fully implemented specification objects should be checked here.
- [ ] [Workflows Specification Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#workflows-specification-object)
- [x] [Info Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#info-object)
- [x] [Source Description Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#source-description-object)
- [ ] [Workflow Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#workflow-object)
- [x] [Workflow Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#workflow-object)
- [x] [Step Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#step-object)
- [x] [Parameter Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#parameter-object)
- [x] [Success Action Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#success-action-object)
Expand Down
66 changes: 66 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/Workflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
ObjectElement,
ArrayElement,
StringElement,
Attributes,
Meta,
} from '@swagger-api/apidom-core';

import JSONSchemaElement from './JSONSchema';

class Workflow extends ObjectElement {
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.element = 'workflow';
}

get workflowId(): StringElement | undefined {
return this.get('workflowId');
}

set workflowId(workflowId: StringElement | undefined) {
this.set('workflowId', workflowId);
}

get summary(): StringElement | undefined {
return this.get('summary');
}

set summary(summary: StringElement | undefined) {
this.set('summary', summary);
}

get description(): StringElement | undefined {
return this.get('description');
}

set description(description: StringElement | undefined) {
this.set('description', description);
}

get inputs(): JSONSchemaElement | undefined {
return this.get('inputs');
}

set inputs(inputs: JSONSchemaElement | undefined) {
this.set('inputs', inputs);
}

get steps(): ArrayElement | undefined {
return this.get('steps');
}

set steps(steps: ArrayElement | undefined) {
this.set('steps', steps);
}

get outputs(): ObjectElement | undefined {
return this.get('outputs');
}

set outputs(outputs: ObjectElement | undefined) {
this.set('outputs', outputs);
}
}

export default Workflow;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ObjectElement, Attributes, Meta } from '@swagger-api/apidom-core';

class WorkflowOutputs extends ObjectElement {
static primaryClass = 'workflow-outputs';

constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(WorkflowOutputs.primaryClass);
}
}

export default WorkflowOutputs;
12 changes: 12 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/nces/WorkflowSteps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core';

class WorkflowSteps extends ArrayElement {
static primaryClass = 'workflow-steps';

constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(WorkflowSteps.primaryClass);
}
}

export default WorkflowSteps;
6 changes: 6 additions & 0 deletions packages/apidom-ns-workflows-1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export {
isInfoElement,
isSourceDescriptionElement,
isSourceDescriptionsElement,
isWorkflowElement,
isWorkflowStepsElement,
isWorkflowOutputsElement,
isStepElement,
isStepParametersElement,
isStepDependsOnElement,
Expand Down Expand Up @@ -62,6 +65,7 @@ export {
WorkflowsSpecElement,
InfoElement,
SourceDescriptionElement,
WorkflowElement,
StepElement,
ParameterElement,
SuccessActionElement,
Expand All @@ -73,6 +77,8 @@ export {
} from './refractor/registration';
// NCE types
export { default as SourceDescriptionsElement } from './elements/nces/SourceDescriptions';
export { default as WorkflowStepsElement } from './elements/nces/WorkflowSteps';
export { default as WorkflowOutputsElement } from './elements/nces/WorkflowOutputs';
export { default as StepParametersElement } from './elements/nces/StepParameters';
export { default as StepDependsOnElement } from './elements/nces/StepDependsOn';
export { default as StepSuccessCriteriaElement } from './elements/nces/StepSuccessCriteria';
Expand Down
2 changes: 2 additions & 0 deletions packages/apidom-ns-workflows-1/src/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WorkflowsSpecification1Element from './elements/WorkflowsSpecification1';
import WorkflowsSpecElement from './elements/WorkflowsSpec';
import InfoElement from './elements/Info';
import SourceDescriptionElement from './elements/SourceDescription';
import WorkflowElement from './elements/Workflow';
import StepElement from './elements/Step';
import ParameterElement from './elements/Parameter';
import SuccessActionElement from './elements/SuccessAction';
Expand All @@ -21,6 +22,7 @@ const workflows1 = {
base.register('workflowsSpec', WorkflowsSpecElement);
base.register('info', InfoElement);
base.register('sourceDescription', SourceDescriptionElement);
base.register('workflow', WorkflowElement);
base.register('step', StepElement);
base.register('parameter', ParameterElement);
base.register('successAction', SuccessActionElement);
Expand Down
35 changes: 35 additions & 0 deletions packages/apidom-ns-workflows-1/src/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WorkflowsSpecification1Element from './elements/WorkflowsSpecification1';
import WorkflowsSpecElement from './elements/WorkflowsSpec';
import InfoElement from './elements/Info';
import SourceDescriptionElement from './elements/SourceDescription';
import WorkflowElement from './elements/Workflow';
import StepElement from './elements/Step';
import ParameterElement from './elements/Parameter';
import SuccessActionElement from './elements/SuccessAction';
Expand All @@ -14,6 +15,8 @@ import ReferenceElement from './elements/Reference';
import JSONSchemaElement from './elements/JSONSchema';
// NCE types
import SourceDescriptionsElement from './elements/nces/SourceDescriptions';
import WorkflowStepsElement from './elements/nces/WorkflowSteps';
import WorkflowOutputsElement from './elements/nces/WorkflowOutputs';
import StepParametersElement from './elements/nces/StepParameters';
import StepDependsOnElement from './elements/nces/StepDependsOn';
import StepSuccessCriteriaElement from './elements/nces/StepSuccessCriteria';
Expand Down Expand Up @@ -77,6 +80,38 @@ export const isSourceDescriptionsElement = createPredicate(
},
);

export const isWorkflowStepsElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is WorkflowStepsElement =>
element instanceof WorkflowStepsElement ||
(hasBasicElementProps(element) &&
isElementType('array', element) &&
primitiveEq('array', element) &&
hasClass('workflow-steps', element));
},
);

export const isWorkflowOutputsElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is WorkflowOutputsElement =>
element instanceof WorkflowOutputsElement ||
(hasBasicElementProps(element) &&
isElementType('array', element) &&
primitiveEq('array', element) &&
hasClass('workflow-outputs', element));
},
);

export const isWorkflowElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
return (element: unknown): element is WorkflowElement =>
element instanceof WorkflowElement ||
(hasBasicElementProps(element) &&
isElementType('workflow', element) &&
primitiveEq('object', element));
},
);

export const isStepOnSuccessElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is StepOnSuccessElement =>
Expand Down
9 changes: 9 additions & 0 deletions packages/apidom-ns-workflows-1/src/refractor/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import WorkflowsSpecification1Element from '../elements/WorkflowsSpecification1'
import WorkflowsSpecElement from '../elements/WorkflowsSpec';
import InfoElement from '../elements/Info';
import SourceDescriptionElement from '../elements/SourceDescription';
import WorkflowElement from '../elements/Workflow';
import StepElement from '../elements/Step';
import ParameterElement from '../elements/Parameter';
import SuccessActionElement from '../elements/SuccessAction';
Expand Down Expand Up @@ -35,6 +36,13 @@ SourceDescriptionElement.refract = createRefractor([
'SourceDescription',
'$visitor',
]);
WorkflowElement.refract = createRefractor([
'visitors',
'document',
'objects',
'Workflow',
'$visitor',
]);
StepElement.refract = createRefractor(['visitors', 'document', 'objects', 'Step', '$visitor']);
ParameterElement.refract = createRefractor([
'visitors',
Expand Down Expand Up @@ -91,6 +99,7 @@ export {
WorkflowsSpecElement,
InfoElement,
SourceDescriptionElement,
WorkflowElement,
StepElement,
ParameterElement,
SuccessActionElement,
Expand Down
14 changes: 14 additions & 0 deletions packages/apidom-ns-workflows-1/src/refractor/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import InfoVisitor from './visitors/workflows-1/info';
import InfoVersionVisitor from './visitors/workflows-1/info/VersionVisitor';
import SourceDescriptionVisitor from './visitors/workflows-1/source-description';
import SourceDescriptionUrlVisitor from './visitors/workflows-1/source-description/UrlVisitor';
import WorkflowVisitor from './visitors/workflows-1/workflow';
import WorkflowStepsVisitor from './visitors/workflows-1/workflow/StepsVisitor';
import workflowOutputsVisitor from './visitors/workflows-1/workflow/OutputsVisitor';
import StepVisitor from './visitors/workflows-1/step';
import StepOutputsVisitor from './visitors/workflows-1/step/OutputsVisitor';
import StepParametersVisitor from './visitors/workflows-1/step/ParametersVisitor';
Expand Down Expand Up @@ -77,6 +80,17 @@ const specification = {
type: { $ref: '#/visitors/value' },
},
},
Workflow: {
$visitor: WorkflowVisitor,
fixedFields: {
workflowId: { $ref: '#/visitors/value' },
summary: { $ref: '#/visitors/value' },
description: { $ref: '#/visitors/value' },
inputs: JSONSchemaVisitor,
steps: WorkflowStepsVisitor,
outputs: workflowOutputsVisitor,
},
},
Step: {
$visitor: StepVisitor,
fixedFields: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import stampit from 'stampit';
import { always } from 'ramda';

import MapVisitor from '../../generics/MapVisitor';
import FallbackVisitor from '../../FallbackVisitor';
import WorkflowOutputsElement from '../../../../elements/nces/WorkflowOutputs';

const OutputsVisitor = stampit(MapVisitor, FallbackVisitor, {
props: {
specPath: always(['value']),
},
init() {
this.element = new WorkflowOutputsElement();
},
});

export default OutputsVisitor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import stampit from 'stampit';
import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core';

import WorkflowStepsElement from '../../../../elements/nces/WorkflowSteps';
import SpecificationVisitor from '../../SpecificationVisitor';
import FallbackVisitor from '../../FallbackVisitor';

const StepsVisitor = stampit(SpecificationVisitor, FallbackVisitor, {
init() {
this.element = new WorkflowStepsElement();
},
methods: {
ArrayElement(arrayElement: ArrayElement) {
arrayElement.forEach((item: Element): void => {
const specPath = ['document', 'objects', 'Step'];
const element = this.toRefractedElement(specPath, item);

this.element.push(element);
});

this.copyMetaAndAttributes(arrayElement, this.element);

return BREAK;
},
},
});

export default StepsVisitor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import stampit from 'stampit';
import { always } from 'ramda';

import WorkflowElement from '../../../../elements/Workflow';
import FallbackVisitor from '../../FallbackVisitor';
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor';

const WorkflowVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, {
props: {
specPath: always(['document', 'objects', 'Workflow']),
canSupportSpecificationExtensions: true,
},
init() {
this.element = new WorkflowElement();
},
});

export default WorkflowVisitor;
1 change: 1 addition & 0 deletions packages/apidom-ns-workflows-1/src/traversal/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const keyMap = {
WorkflowsSpecification1Element: ['content'],
InfoElement: ['content'],
SourceDescriptionElement: ['content'],
WorkflowElement: ['content'],
StepElement: ['content'],
ParameterElement: ['content'],
SuccessActionElement: ['content'],
Expand Down

0 comments on commit fce4096

Please sign in to comment.