Skip to content

Commit

Permalink
feat(ns-workflows-1): add support for Source Description Object (#3403)
Browse files Browse the repository at this point in the history
Refs #3392
  • Loading branch information
frankkilcommins committed Nov 20, 2023
1 parent e60194b commit 893f125
Show file tree
Hide file tree
Showing 17 changed files with 322 additions and 10 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 @@ -187,7 +187,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)
- [ ] [Source Description Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#source-description-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)
- [ ] [Step Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#step-object)
- [ ] [Parameter Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#parameter-object)
Expand Down
34 changes: 34 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/SourceDescription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ObjectElement, StringElement, Attributes, Meta } from '@swagger-api/apidom-core';

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

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

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

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

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

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

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

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

import WorkflowsSpecElement from './WorkflowsSpec';
import InfoElement from './Info';
Expand Down Expand Up @@ -26,6 +26,14 @@ class WorkflowsSpecification1 extends ObjectElement {
set info(info: InfoElement | undefined) {
this.set('info', info);
}

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

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

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

class SourceDescriptions extends ArrayElement {
static primaryClass = 'sourceDescriptions';

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

export default SourceDescriptions;
5 changes: 5 additions & 0 deletions packages/apidom-ns-workflows-1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export {
isWorkflowsSpecElement,
isWorkflowsSpecification1Element,
isInfoElement,
isSourceDescriptionElement,
isSourceDescriptionsElement,
} from './predicates';

export { isWorkflowsSpecificationExtension } from './refractor/predicates';
Expand All @@ -43,4 +45,7 @@ export {
WorkflowsSpecification1Element,
WorkflowsSpecElement,
InfoElement,
SourceDescriptionElement,
} from './refractor/registration';
// NCE types
export { default as SourceDescriptionsElement } from './elements/nces/SourceDescriptions';
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 @@ -3,6 +3,7 @@ import { NamespacePluginOptions } from '@swagger-api/apidom-core';
import WorkflowsSpecification1Element from './elements/WorkflowsSpecification1';
import WorkflowsSpecElement from './elements/WorkflowsSpec';
import InfoElement from './elements/Info';
import SourceDescriptionElement from './elements/SourceDescription';

const workflows1 = {
namespace: (options: NamespacePluginOptions) => {
Expand All @@ -11,6 +12,7 @@ const workflows1 = {
base.register('workflowsSpecification1', WorkflowsSpecification1Element);
base.register('workflowsSpec', WorkflowsSpecElement);
base.register('info', InfoElement);
base.register('sourceDescription', SourceDescriptionElement);

return base;
},
Expand Down
24 changes: 24 additions & 0 deletions packages/apidom-ns-workflows-1/src/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { createPredicate } from '@swagger-api/apidom-core';
import WorkflowsSpecification1Element from './elements/WorkflowsSpecification1';
import WorkflowsSpecElement from './elements/WorkflowsSpec';
import InfoElement from './elements/Info';
import SourceDescriptionElement from './elements/SourceDescription';
// NCE types
import SourceDescriptionsElement from './elements/nces/SourceDescriptions';

export const isWorkflowsSpecElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
Expand Down Expand Up @@ -36,3 +39,24 @@ export const isInfoElement = createPredicate(
hasClass('info', element));
},
);

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

export const isSourceDescriptionsElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is SourceDescriptionsElement =>
element instanceof SourceDescriptionsElement ||
(hasBasicElementProps(element) &&
isElementType('sourceDescriptions', element) &&
primitiveEq('array', element) &&
hasClass('sourceDescriptions', element));
},
);
15 changes: 14 additions & 1 deletion packages/apidom-ns-workflows-1/src/refractor/registration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import WorkflowsSpecification1Element from '../elements/WorkflowsSpecification1';
import WorkflowsSpecElement from '../elements/WorkflowsSpec';
import InfoElement from '../elements/Info';
import SourceDescriptionElement from '../elements/SourceDescription';
import { createRefractor } from './index';

InfoElement.refract = createRefractor(['visitors', 'document', 'objects', 'Info', '$visitor']);
Expand All @@ -19,5 +20,17 @@ WorkflowsSpecification1Element.refract = createRefractor([
'WorkflowsSpecification',
'$visitor',
]);
SourceDescriptionElement.refract = createRefractor([
'visitors',
'document',
'objects',
'SourceDescription',
'$visitor',
]);

export { WorkflowsSpecification1Element, WorkflowsSpecElement, InfoElement };
export {
WorkflowsSpecification1Element,
WorkflowsSpecElement,
InfoElement,
SourceDescriptionElement,
};
12 changes: 12 additions & 0 deletions packages/apidom-ns-workflows-1/src/refractor/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import WorkflowsSpecificationVisitor from './visitors/workflows-1/index';
import WorkflowsSpecVisitor from './visitors/workflows-1/WorkflowsSpecVisitor';
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 SourceDescriptionsVisitor from './visitors/workflows-1/SourceDescriptionsVisitor';
import FallbackVisitor from './visitors/FallbackVisitor';
import SpecificationExtensionVisitor from './visitors/SpecificationExtensionVisitor';

Expand All @@ -26,6 +29,7 @@ const specification = {
info: {
$ref: '#/visitors/document/objects/Info',
},
sourceDescriptions: SourceDescriptionsVisitor,
},
},
Info: {
Expand All @@ -37,6 +41,14 @@ const specification = {
version: InfoVersionVisitor,
},
},
SourceDescription: {
$visitor: SourceDescriptionVisitor,
fixedFields: {
name: { $ref: '#/visitors/value' },
url: SourceDescriptionUrlVisitor,
type: { $ref: '#/visitors/value' },
},
},
},
extension: {
$visitor: SpecificationExtensionVisitor,
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 SourceDescriptionsElement from '../../../elements/nces/SourceDescriptions';
import SpecificationVisitor from '../SpecificationVisitor';
import FallbackVisitor from '../FallbackVisitor';

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

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

this.copyMetaAndAttributes(arrayElement, this.element);

return BREAK;
},
},
});

export default SourceDescriptionsVisitor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import stampit from 'stampit';
import { StringElement, BREAK, cloneDeep } from '@swagger-api/apidom-core';

import FallbackVisitor from '../../FallbackVisitor';

const UrlVisitor = stampit(FallbackVisitor, {
methods: {
StringElement(stringElement: StringElement) {
this.element = cloneDeep(stringElement);
this.element.classes.push('source-description-url');

return BREAK;
},
},
});

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

import SourceDescriptionElement from '../../../../elements/SourceDescription';
import FallbackVisitor from '../../FallbackVisitor';
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor';

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

export default SourceDescriptionVisitor;
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 @@ -15,5 +15,6 @@ export const getNodeType = <T extends Element>(element: T): string | undefined =
export const keyMap = {
WorkflowsSpecification1Element: ['content'],
InfoElement: ['content'],
SourceDescriptionElement: ['content'],
...keyMapBase,
};
7 changes: 0 additions & 7 deletions packages/apidom-ns-workflows-1/test/index.ts

This file was deleted.

0 comments on commit 893f125

Please sign in to comment.