Skip to content

Commit 4a467cb

Browse files
feat(ns-workflows-1): add support Workflows Spec Object (#3496)
Refs #3392
1 parent 69d0f95 commit 4a467cb

File tree

9 files changed

+120
-1
lines changed

9 files changed

+120
-1
lines changed

packages/apidom-ns-workflows-1/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ const workflowsElement = WorkflowsSpecification1Element.refract(apiDOM.result, {
185185

186186
Only fully implemented specification objects should be checked here.
187187

188-
- [ ] [Workflows Specification Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#workflows-specification-object)
188+
- [x] [Workflows Specification Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#workflows-specification-object)
189189
- [x] [Info Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#info-object)
190190
- [x] [Source Description Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#source-description-object)
191191
- [x] [Workflow Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#workflow-object)

packages/apidom-ns-workflows-1/src/elements/WorkflowsSpecification1.ts

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ObjectElement, ArrayElement, Attributes, Meta } from '@swagger-api/apid
22

33
import WorkflowsSpecElement from './WorkflowsSpec';
44
import InfoElement from './Info';
5+
import ComponentsElement from './Components';
56

67
class WorkflowsSpecification1 extends ObjectElement {
78
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) {
@@ -34,6 +35,22 @@ class WorkflowsSpecification1 extends ObjectElement {
3435
set sourceDescriptions(sourceDescriptions: ArrayElement | undefined) {
3536
this.set('sourceDescriptions', sourceDescriptions);
3637
}
38+
39+
get workflows(): ArrayElement | undefined {
40+
return this.get('workflows');
41+
}
42+
43+
set workflows(workflows: ArrayElement | undefined) {
44+
this.set('workflows', workflows);
45+
}
46+
47+
get components(): ComponentsElement | undefined {
48+
return this.get('components');
49+
}
50+
51+
set components(components: ComponentsElement | undefined) {
52+
this.set('components', components);
53+
}
3754
}
3855

3956
export default WorkflowsSpecification1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core';
2+
3+
class Workflows extends ArrayElement {
4+
static primaryClass = 'workflows';
5+
6+
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) {
7+
super(content, meta, attributes);
8+
this.classes.push(Workflows.primaryClass);
9+
}
10+
}
11+
12+
export default Workflows;

packages/apidom-ns-workflows-1/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export {
7777
} from './refractor/registration';
7878
// NCE types
7979
export { default as SourceDescriptionsElement } from './elements/nces/SourceDescriptions';
80+
export { default as WorkflowsElement } from './elements/nces/Workflows';
8081
export { default as WorkflowStepsElement } from './elements/nces/WorkflowSteps';
8182
export { default as WorkflowOutputsElement } from './elements/nces/WorkflowOutputs';
8283
export { default as StepParametersElement } from './elements/nces/StepParameters';

packages/apidom-ns-workflows-1/src/predicates.ts

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import CriterionElement from './elements/Criterion';
1414
import ReferenceElement from './elements/Reference';
1515
import JSONSchemaElement from './elements/JSONSchema';
1616
// NCE types
17+
import WorkflowsElement from './elements/nces/Workflows';
1718
import SourceDescriptionsElement from './elements/nces/SourceDescriptions';
1819
import WorkflowStepsElement from './elements/nces/WorkflowSteps';
1920
import WorkflowOutputsElement from './elements/nces/WorkflowOutputs';
@@ -80,6 +81,17 @@ export const isSourceDescriptionsElement = createPredicate(
8081
},
8182
);
8283

84+
export const isWorkflowsElement = createPredicate(
85+
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
86+
return (element: unknown): element is WorkflowsElement =>
87+
element instanceof WorkflowsElement ||
88+
(hasBasicElementProps(element) &&
89+
isElementType('workflows', element) &&
90+
primitiveEq('array', element) &&
91+
hasClass('workflows', element));
92+
},
93+
);
94+
8395
export const isWorkflowStepsElement = createPredicate(
8496
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
8597
return (element: unknown): element is WorkflowStepsElement =>

packages/apidom-ns-workflows-1/src/refractor/specification.ts

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import StepOnSuccessVisitor from './visitors/workflows-1/step/OnSuccessVisitor';
1919
import StepOnFailureVisitor from './visitors/workflows-1/step/OnFailureVisitor';
2020
import ParameterVisitor from './visitors/workflows-1/parameter';
2121
import SourceDescriptionsVisitor from './visitors/workflows-1/SourceDescriptionsVisitor';
22+
import WorkflowsVisitor from './visitors/workflows-1/WorkflowsVisitor';
2223
import SuccessActionVisitor from './visitors/workflows-1/success-action';
2324
import SuccessActionCriteriaVisitor from './visitors/workflows-1/SuccessActionCriteriaVisitor';
2425
import FailureActionVisitor from './visitors/workflows-1/failure-action';
@@ -61,6 +62,10 @@ const specification = {
6162
$ref: '#/visitors/document/objects/Info',
6263
},
6364
sourceDescriptions: SourceDescriptionsVisitor,
65+
workflows: WorkflowsVisitor,
66+
components: {
67+
$ref: '#/visitors/document/objects/Components',
68+
},
6469
},
6570
},
6671
Info: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import stampit from 'stampit';
2+
import { ArrayElement, Element, BREAK } from '@swagger-api/apidom-core';
3+
4+
import WorkflowsElement from '../../../elements/nces/Workflows';
5+
import SpecificationVisitor from '../SpecificationVisitor';
6+
import FallbackVisitor from '../FallbackVisitor';
7+
8+
const WorkflowsVisitor = stampit(SpecificationVisitor, FallbackVisitor, {
9+
init() {
10+
this.element = new WorkflowsElement();
11+
},
12+
methods: {
13+
ArrayElement(arrayElement: ArrayElement) {
14+
arrayElement.forEach((item: Element): void => {
15+
const specPath = ['document', 'objects', 'Workflow'];
16+
const element = this.toRefractedElement(specPath, item);
17+
18+
this.element.push(element);
19+
});
20+
21+
this.copyMetaAndAttributes(arrayElement, this.element);
22+
23+
return BREAK;
24+
},
25+
},
26+
});
27+
28+
export default WorkflowsVisitor;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`refractor elements WorkflowsSpecification1Element should refract to semantic ApiDOM tree 1`] = `
4+
(WorkflowsSpecification1Element
5+
(MemberElement
6+
(StringElement)
7+
(StringElement))
8+
(MemberElement
9+
(StringElement)
10+
(InfoElement))
11+
(MemberElement
12+
(StringElement)
13+
(ArrayElement
14+
(SourceDescriptionElement)))
15+
(MemberElement
16+
(StringElement)
17+
(ArrayElement
18+
(WorkflowElement)))
19+
(MemberElement
20+
(StringElement)
21+
(ComponentsElement)))
22+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { expect } from 'chai';
2+
import { sexprs } from '@swagger-api/apidom-core';
3+
4+
import { WorkflowsSpecification1Element } from '../../../../src';
5+
6+
describe('refractor', function () {
7+
context('elements', function () {
8+
context('WorkflowsSpecification1Element', function () {
9+
specify('should refract to semantic ApiDOM tree', function () {
10+
const workflowsSpecification1Element = WorkflowsSpecification1Element.refract({
11+
workflowsSpec: '1.0.0',
12+
info: {},
13+
sourceDescriptions: [{}],
14+
workflows: [{}],
15+
components: {},
16+
});
17+
18+
expect(sexprs(workflowsSpecification1Element)).toMatchSnapshot();
19+
});
20+
});
21+
});
22+
});

0 commit comments

Comments
 (0)