Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ns-workflows-1): Add Failure Action Obj #3429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -192,7 +192,7 @@ Only fully implemented specification objects should be checked here.
- [ ] [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)
- [x] [Success Action Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#success-action-object)
- [ ] [Failure Action Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#failure-action-object)
- [x] [Failure Action Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#failure-action-object)
- [ ] [Component Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#component-object)
- [x] [Criterion Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#criterion-object)
- [ ] [Reference Object](https://github.com/OAI/sig-workflows/blob/main/versions/1.0.0.md#reference-object)
Expand Down
65 changes: 65 additions & 0 deletions packages/apidom-ns-workflows-1/src/elements/FailureAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
ObjectElement,
ArrayElement,
StringElement,
NumberElement,
Attributes,
Meta,
} from '@swagger-api/apidom-core';

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

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

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

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

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

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

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

get retryAfter(): NumberElement | undefined {
return this.get('retryAfter');
}

set retryAfter(retryAfter: NumberElement | undefined) {
this.set('retryAfter', retryAfter);
}

get retryLimit(): NumberElement | undefined {
return this.get('retryLimit');
}

set retryLimit(retryLimit: NumberElement | undefined) {
this.set('retryLimit', retryLimit);
}

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

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

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

class FailureActionCriteria extends ArrayElement {
static primaryClass = 'failure-action-criteria';

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

export default FailureActionCriteria;
4 changes: 4 additions & 0 deletions packages/apidom-ns-workflows-1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export {
isSourceDescriptionsElement,
isSuccessActionElement,
isSuccessActionCriteriaElement,
isFailureActionElement,
isFailureActionCriteriaElement,
isCriterionElement,
} from './predicates';

Expand All @@ -50,8 +52,10 @@ export {
InfoElement,
SourceDescriptionElement,
SuccessActionElement,
FailureActionElement,
CriterionElement,
} from './refractor/registration';
// NCE types
export { default as SourceDescriptionsElement } from './elements/nces/SourceDescriptions';
export { default as SuccessActionCriteriaElement } from './elements/nces/SuccessActionCriteria';
export { default as FailureActionCriteriaElement } from './elements/nces/FailureActionCriteria';
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 @@ -5,6 +5,7 @@ import WorkflowsSpecElement from './elements/WorkflowsSpec';
import InfoElement from './elements/Info';
import SourceDescriptionElement from './elements/SourceDescription';
import SuccessActionElement from './elements/SuccessAction';
import FailureActionElement from './elements/FailureAction';
import CriterionElement from './elements/Criterion';

const workflows1 = {
Expand All @@ -16,6 +17,7 @@ const workflows1 = {
base.register('info', InfoElement);
base.register('sourceDescription', SourceDescriptionElement);
base.register('successAction', SuccessActionElement);
base.register('failureAction', FailureActionElement);
base.register('criterion', CriterionElement);

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 @@ -5,10 +5,12 @@ import WorkflowsSpecElement from './elements/WorkflowsSpec';
import InfoElement from './elements/Info';
import SourceDescriptionElement from './elements/SourceDescription';
import SuccessActionElement from './elements/SuccessAction';
import FailureActionElement from './elements/FailureAction';
import CriterionElement from './elements/Criterion';
// NCE types
import SourceDescriptionsElement from './elements/nces/SourceDescriptions';
import SuccessActionCriteriaElement from './elements/nces/SuccessActionCriteria';
import FailureActionCriteriaElement from './elements/nces/FailureActionCriteria';

export const isWorkflowsSpecElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq }) => {
Expand Down Expand Up @@ -95,3 +97,25 @@ export const isSuccessActionCriteriaElement = createPredicate(
hasClass('criteria', element));
},
);

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

export const isFailureActionCriteriaElement = createPredicate(
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => {
return (element: unknown): element is FailureActionCriteriaElement =>
element instanceof FailureActionCriteriaElement ||
(hasBasicElementProps(element) &&
isElementType('array', element) &&
primitiveEq('array', element) &&
hasClass('failure-action-criteria', element) &&
hasClass('criteria', element));
},
);
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 @@ -3,6 +3,7 @@ import WorkflowsSpecElement from '../elements/WorkflowsSpec';
import InfoElement from '../elements/Info';
import SourceDescriptionElement from '../elements/SourceDescription';
import SuccessActionElement from '../elements/SuccessAction';
import FailureActionElement from '../elements/FailureAction';
import CriterionElement from '../elements/Criterion';
import { createRefractor } from './index';

Expand Down Expand Up @@ -36,6 +37,13 @@ SuccessActionElement.refract = createRefractor([
'SuccessAction',
'$visitor',
]);
FailureActionElement.refract = createRefractor([
'visitors',
'document',
'objects',
'FailureAction',
'$visitor',
]);
CriterionElement.refract = createRefractor([
'visitors',
'document',
Expand All @@ -50,5 +58,6 @@ export {
InfoElement,
SourceDescriptionElement,
SuccessActionElement,
FailureActionElement,
CriterionElement,
};
13 changes: 13 additions & 0 deletions packages/apidom-ns-workflows-1/src/refractor/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import FallbackVisitor from './visitors/FallbackVisitor';
import SpecificationExtensionVisitor from './visitors/SpecificationExtensionVisitor';
import SuccessActionVisitor from './visitors/workflows-1/success-action';
import SuccessActionCriteriaVisitor from './visitors/workflows-1/SuccessActionCriteriaVisitor';
import FailureActionVisitor from './visitors/workflows-1/failure-action';
import FailureActionCriteriaVisitor from './visitors/workflows-1/FailureActionCriteriaVisitor';

/**
* Specification object allows us to have complete control over visitors
Expand Down Expand Up @@ -61,6 +63,17 @@ const specification = {
criteria: SuccessActionCriteriaVisitor,
},
},
FailureAction: {
$visitor: FailureActionVisitor,
fixedFields: {
type: { $ref: '#/visitors/value' },
workflowId: { $ref: '#/visitors/value' },
stepId: { $ref: '#/visitors/value' },
retryAfter: { $ref: '#/visitors/value' },
retryLimit: { $ref: '#/visitors/value' },
criteria: FailureActionCriteriaVisitor,
},
},
Criterion: {
$visitor: CriterionVisitor,
fixedFields: {
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 FailureActionCriteriaElement from '../../../elements/nces/FailureActionCriteria';
import SpecificationVisitor from '../SpecificationVisitor';
import FallbackVisitor from '../FallbackVisitor';

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

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

this.copyMetaAndAttributes(arrayElement, this.element);

return BREAK;
},
},
});

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

import FailureActionElement from '../../../../elements/FailureAction';
import FallbackVisitor from '../../FallbackVisitor';
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor';

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

export default FailureActionVisitor;
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 @@ -17,6 +17,7 @@ export const keyMap = {
InfoElement: ['content'],
SourceDescriptionElement: ['content'],
SuccessActionElement: ['content'],
FailureActionElement: ['content'],
CriterionElement: ['content'],
...keyMapBase,
};
Loading