Skip to content

Commit

Permalink
feat(ns-workflows-1): add support Workflows Spec Object (#3496)
Browse files Browse the repository at this point in the history
Refs #3392
  • Loading branch information
frankkilcommins authored Dec 4, 2023
1 parent 69d0f95 commit 4a467cb
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 1 deletion.
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 @@ -185,7 +185,7 @@ const workflowsElement = WorkflowsSpecification1Element.refract(apiDOM.result, {

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] [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)
- [x] [Workflow Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#workflow-object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ObjectElement, ArrayElement, Attributes, Meta } from '@swagger-api/apid

import WorkflowsSpecElement from './WorkflowsSpec';
import InfoElement from './Info';
import ComponentsElement from './Components';

class WorkflowsSpecification1 extends ObjectElement {
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) {
Expand Down Expand Up @@ -34,6 +35,22 @@ class WorkflowsSpecification1 extends ObjectElement {
set sourceDescriptions(sourceDescriptions: ArrayElement | undefined) {
this.set('sourceDescriptions', sourceDescriptions);
}

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

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

get components(): ComponentsElement | undefined {
return this.get('components');
}

set components(components: ComponentsElement | undefined) {
this.set('components', components);
}
}

export default WorkflowsSpecification1;
12 changes: 12 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/nces/Workflows.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 Workflows extends ArrayElement {
static primaryClass = 'workflows';

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

export default Workflows;
1 change: 1 addition & 0 deletions packages/apidom-ns-workflows-1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export {
} from './refractor/registration';
// NCE types
export { default as SourceDescriptionsElement } from './elements/nces/SourceDescriptions';
export { default as WorkflowsElement } from './elements/nces/Workflows';
export { default as WorkflowStepsElement } from './elements/nces/WorkflowSteps';
export { default as WorkflowOutputsElement } from './elements/nces/WorkflowOutputs';
export { default as StepParametersElement } from './elements/nces/StepParameters';
Expand Down
12 changes: 12 additions & 0 deletions packages/apidom-ns-workflows-1/src/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CriterionElement from './elements/Criterion';
import ReferenceElement from './elements/Reference';
import JSONSchemaElement from './elements/JSONSchema';
// NCE types
import WorkflowsElement from './elements/nces/Workflows';
import SourceDescriptionsElement from './elements/nces/SourceDescriptions';
import WorkflowStepsElement from './elements/nces/WorkflowSteps';
import WorkflowOutputsElement from './elements/nces/WorkflowOutputs';
Expand Down Expand Up @@ -80,6 +81,17 @@ export const isSourceDescriptionsElement = createPredicate(
},
);

export const isWorkflowsElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is WorkflowsElement =>
element instanceof WorkflowsElement ||
(hasBasicElementProps(element) &&
isElementType('workflows', element) &&
primitiveEq('array', element) &&
hasClass('workflows', element));
},
);

export const isWorkflowStepsElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is WorkflowStepsElement =>
Expand Down
5 changes: 5 additions & 0 deletions packages/apidom-ns-workflows-1/src/refractor/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import StepOnSuccessVisitor from './visitors/workflows-1/step/OnSuccessVisitor';
import StepOnFailureVisitor from './visitors/workflows-1/step/OnFailureVisitor';
import ParameterVisitor from './visitors/workflows-1/parameter';
import SourceDescriptionsVisitor from './visitors/workflows-1/SourceDescriptionsVisitor';
import WorkflowsVisitor from './visitors/workflows-1/WorkflowsVisitor';
import SuccessActionVisitor from './visitors/workflows-1/success-action';
import SuccessActionCriteriaVisitor from './visitors/workflows-1/SuccessActionCriteriaVisitor';
import FailureActionVisitor from './visitors/workflows-1/failure-action';
Expand Down Expand Up @@ -61,6 +62,10 @@ const specification = {
$ref: '#/visitors/document/objects/Info',
},
sourceDescriptions: SourceDescriptionsVisitor,
workflows: WorkflowsVisitor,
components: {
$ref: '#/visitors/document/objects/Components',
},
},
},
Info: {
Expand Down
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 WorkflowsElement from '../../../elements/nces/Workflows';
import SpecificationVisitor from '../SpecificationVisitor';
import FallbackVisitor from '../FallbackVisitor';

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

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

this.copyMetaAndAttributes(arrayElement, this.element);

return BREAK;
},
},
});

export default WorkflowsVisitor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`refractor elements WorkflowsSpecification1Element should refract to semantic ApiDOM tree 1`] = `
(WorkflowsSpecification1Element
(MemberElement
(StringElement)
(StringElement))
(MemberElement
(StringElement)
(InfoElement))
(MemberElement
(StringElement)
(ArrayElement
(SourceDescriptionElement)))
(MemberElement
(StringElement)
(ArrayElement
(WorkflowElement)))
(MemberElement
(StringElement)
(ComponentsElement)))
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect } from 'chai';
import { sexprs } from '@swagger-api/apidom-core';

import { WorkflowsSpecification1Element } from '../../../../src';

describe('refractor', function () {
context('elements', function () {
context('WorkflowsSpecification1Element', function () {
specify('should refract to semantic ApiDOM tree', function () {
const workflowsSpecification1Element = WorkflowsSpecification1Element.refract({
workflowsSpec: '1.0.0',
info: {},
sourceDescriptions: [{}],
workflows: [{}],
components: {},
});

expect(sexprs(workflowsSpecification1Element)).toMatchSnapshot();
});
});
});
});

0 comments on commit 4a467cb

Please sign in to comment.