From d7f041458c5676d3e521c407eac8b587ea67e990 Mon Sep 17 00:00:00 2001 From: Frank Kilcommins Date: Mon, 4 Dec 2023 16:58:51 +0000 Subject: [PATCH 1/6] feat(ns-workflows-1): Add Workflows Spec Object --- packages/apidom-ns-workflows-1/README.md | 2 +- .../src/elements/WorkflowsSpecification1.ts | 17 ++++++++++++++ .../src/refractor/specification.ts | 2 ++ .../__snapshots__/index.ts.snap | 22 +++++++++++++++++++ .../elements/WorkflowsSpecification1/index.ts | 22 +++++++++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/__snapshots__/index.ts.snap create mode 100644 packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/index.ts diff --git a/packages/apidom-ns-workflows-1/README.md b/packages/apidom-ns-workflows-1/README.md index bf9fffa25d..42319b77e9 100644 --- a/packages/apidom-ns-workflows-1/README.md +++ b/packages/apidom-ns-workflows-1/README.md @@ -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) diff --git a/packages/apidom-ns-workflows-1/src/elements/WorkflowsSpecification1.ts b/packages/apidom-ns-workflows-1/src/elements/WorkflowsSpecification1.ts index 174073fe46..f8ba41911b 100644 --- a/packages/apidom-ns-workflows-1/src/elements/WorkflowsSpecification1.ts +++ b/packages/apidom-ns-workflows-1/src/elements/WorkflowsSpecification1.ts @@ -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, meta?: Meta, attributes?: Attributes) { @@ -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; diff --git a/packages/apidom-ns-workflows-1/src/refractor/specification.ts b/packages/apidom-ns-workflows-1/src/refractor/specification.ts index 900f6c5e1a..ad8cf101a9 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/specification.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/specification.ts @@ -61,6 +61,8 @@ const specification = { $ref: '#/visitors/document/objects/Info', }, sourceDescriptions: SourceDescriptionsVisitor, + workflows: WorkflowVisitor, + components: ComponentsVisitor, }, }, Info: { diff --git a/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/__snapshots__/index.ts.snap b/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/__snapshots__/index.ts.snap new file mode 100644 index 0000000000..c259ca33e4 --- /dev/null +++ b/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/__snapshots__/index.ts.snap @@ -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 + (ObjectElement))) + (MemberElement + (StringElement) + (ComponentsElement))) +`; diff --git a/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/index.ts b/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/index.ts new file mode 100644 index 0000000000..0c72288197 --- /dev/null +++ b/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/index.ts @@ -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(); + }); + }); + }); +}); From 3c4769be08d999a5e12edcfc9e09bcccec45e51e Mon Sep 17 00:00:00 2001 From: Frank Kilcommins Date: Mon, 4 Dec 2023 19:46:01 +0000 Subject: [PATCH 2/6] chore: add missing nce and visitor --- .../src/elements/nces/Workflows.ts | 12 ++++++++ packages/apidom-ns-workflows-1/src/index.ts | 1 + .../apidom-ns-workflows-1/src/predicates.ts | 12 ++++++++ .../src/refractor/specification.ts | 7 +++-- .../visitors/workflows-1/WorkflowsVisitor.ts | 28 +++++++++++++++++++ .../__snapshots__/index.ts.snap | 2 +- 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 packages/apidom-ns-workflows-1/src/elements/nces/Workflows.ts create mode 100644 packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsVisitor.ts diff --git a/packages/apidom-ns-workflows-1/src/elements/nces/Workflows.ts b/packages/apidom-ns-workflows-1/src/elements/nces/Workflows.ts new file mode 100644 index 0000000000..92968570cf --- /dev/null +++ b/packages/apidom-ns-workflows-1/src/elements/nces/Workflows.ts @@ -0,0 +1,12 @@ +import { ArrayElement, Attributes, Meta } from '@swagger-api/apidom-core'; + +class Workflows extends ArrayElement { + static primaryClass = 'workflows'; + + constructor(content?: Array, meta?: Meta, attributes?: Attributes) { + super(content, meta, attributes); + this.classes.push(Workflows.primaryClass); + } +} + +export default Workflows; diff --git a/packages/apidom-ns-workflows-1/src/index.ts b/packages/apidom-ns-workflows-1/src/index.ts index ae0e81c8a1..a1357838f3 100644 --- a/packages/apidom-ns-workflows-1/src/index.ts +++ b/packages/apidom-ns-workflows-1/src/index.ts @@ -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'; diff --git a/packages/apidom-ns-workflows-1/src/predicates.ts b/packages/apidom-ns-workflows-1/src/predicates.ts index 9e9b94eb42..ea76f74fdc 100644 --- a/packages/apidom-ns-workflows-1/src/predicates.ts +++ b/packages/apidom-ns-workflows-1/src/predicates.ts @@ -14,6 +14,7 @@ import CriterionElement from './elements/Criterion'; import ReferenceElement from './elements/Reference'; import JSONSchemaElement from './elements/JSONSchema'; // NCE types +import WorkflowWorkflowsElement from './elements/nces/Workflows'; import SourceDescriptionsElement from './elements/nces/SourceDescriptions'; import WorkflowStepsElement from './elements/nces/WorkflowSteps'; import WorkflowOutputsElement from './elements/nces/WorkflowOutputs'; @@ -80,6 +81,17 @@ export const isSourceDescriptionsElement = createPredicate( }, ); +export const isWorkflowWorkflowsElement = createPredicate( + ({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => { + return (element: unknown): element is WorkflowWorkflowsElement => + element instanceof WorkflowWorkflowsElement || + (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 => diff --git a/packages/apidom-ns-workflows-1/src/refractor/specification.ts b/packages/apidom-ns-workflows-1/src/refractor/specification.ts index ad8cf101a9..512464f921 100644 --- a/packages/apidom-ns-workflows-1/src/refractor/specification.ts +++ b/packages/apidom-ns-workflows-1/src/refractor/specification.ts @@ -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'; @@ -61,8 +62,10 @@ const specification = { $ref: '#/visitors/document/objects/Info', }, sourceDescriptions: SourceDescriptionsVisitor, - workflows: WorkflowVisitor, - components: ComponentsVisitor, + workflows: WorkflowsVisitor, + components: { + $ref: '#/visitors/document/objects/Components', + }, }, }, Info: { diff --git a/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsVisitor.ts b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsVisitor.ts new file mode 100644 index 0000000000..84fd3e78a8 --- /dev/null +++ b/packages/apidom-ns-workflows-1/src/refractor/visitors/workflows-1/WorkflowsVisitor.ts @@ -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; diff --git a/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/__snapshots__/index.ts.snap b/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/__snapshots__/index.ts.snap index c259ca33e4..08f57a87d0 100644 --- a/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/__snapshots__/index.ts.snap +++ b/packages/apidom-ns-workflows-1/test/refractor/elements/WorkflowsSpecification1/__snapshots__/index.ts.snap @@ -15,7 +15,7 @@ exports[`refractor elements WorkflowsSpecification1Element should refract to sem (MemberElement (StringElement) (ArrayElement - (ObjectElement))) + (WorkflowElement))) (MemberElement (StringElement) (ComponentsElement))) From 882ad5ca6c2bbec746c1b70dabd6d90030374cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Mon, 4 Dec 2023 21:49:35 +0100 Subject: [PATCH 3/6] Update packages/apidom-ns-workflows-1/src/predicates.ts --- packages/apidom-ns-workflows-1/src/predicates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-ns-workflows-1/src/predicates.ts b/packages/apidom-ns-workflows-1/src/predicates.ts index ea76f74fdc..d0a9a22e77 100644 --- a/packages/apidom-ns-workflows-1/src/predicates.ts +++ b/packages/apidom-ns-workflows-1/src/predicates.ts @@ -14,7 +14,7 @@ import CriterionElement from './elements/Criterion'; import ReferenceElement from './elements/Reference'; import JSONSchemaElement from './elements/JSONSchema'; // NCE types -import WorkflowWorkflowsElement from './elements/nces/Workflows'; +import WorkflowsElement from './elements/nces/Workflows'; import SourceDescriptionsElement from './elements/nces/SourceDescriptions'; import WorkflowStepsElement from './elements/nces/WorkflowSteps'; import WorkflowOutputsElement from './elements/nces/WorkflowOutputs'; From 1997139904bbca0d49c6ece35d0983e7b7155c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Mon, 4 Dec 2023 21:49:41 +0100 Subject: [PATCH 4/6] Update packages/apidom-ns-workflows-1/src/predicates.ts --- packages/apidom-ns-workflows-1/src/predicates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-ns-workflows-1/src/predicates.ts b/packages/apidom-ns-workflows-1/src/predicates.ts index d0a9a22e77..bfd9bac891 100644 --- a/packages/apidom-ns-workflows-1/src/predicates.ts +++ b/packages/apidom-ns-workflows-1/src/predicates.ts @@ -81,7 +81,7 @@ export const isSourceDescriptionsElement = createPredicate( }, ); -export const isWorkflowWorkflowsElement = createPredicate( +export const isWorkflowsElement = createPredicate( ({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => { return (element: unknown): element is WorkflowWorkflowsElement => element instanceof WorkflowWorkflowsElement || From 40d51aa0f4194d3a0321af8d45ee3b722f5b094b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Mon, 4 Dec 2023 21:49:47 +0100 Subject: [PATCH 5/6] Update packages/apidom-ns-workflows-1/src/predicates.ts --- packages/apidom-ns-workflows-1/src/predicates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-ns-workflows-1/src/predicates.ts b/packages/apidom-ns-workflows-1/src/predicates.ts index bfd9bac891..7c855df248 100644 --- a/packages/apidom-ns-workflows-1/src/predicates.ts +++ b/packages/apidom-ns-workflows-1/src/predicates.ts @@ -84,7 +84,7 @@ export const isSourceDescriptionsElement = createPredicate( export const isWorkflowsElement = createPredicate( ({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => { return (element: unknown): element is WorkflowWorkflowsElement => - element instanceof WorkflowWorkflowsElement || + element instanceof WorkflowsElement || (hasBasicElementProps(element) && isElementType('workflows', element) && primitiveEq('array', element) && From e1df741503f7b314c782fb9f0f5e0919c217c775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Mon, 4 Dec 2023 22:05:06 +0100 Subject: [PATCH 6/6] Update packages/apidom-ns-workflows-1/src/predicates.ts --- packages/apidom-ns-workflows-1/src/predicates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apidom-ns-workflows-1/src/predicates.ts b/packages/apidom-ns-workflows-1/src/predicates.ts index 7c855df248..eae6ba5ba9 100644 --- a/packages/apidom-ns-workflows-1/src/predicates.ts +++ b/packages/apidom-ns-workflows-1/src/predicates.ts @@ -83,7 +83,7 @@ export const isSourceDescriptionsElement = createPredicate( export const isWorkflowsElement = createPredicate( ({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => { - return (element: unknown): element is WorkflowWorkflowsElement => + return (element: unknown): element is WorkflowsElement => element instanceof WorkflowsElement || (hasBasicElementProps(element) && isElementType('workflows', element) &&