-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ns-workflows-1): add support for Info Object (#3393)
Refs: #3392 Co-authored-by: Vladimir Gorej <[email protected]>
- Loading branch information
1 parent
ea33e51
commit 5508c54
Showing
37 changed files
with
1,326 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { StringElement, ObjectElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class Info extends ObjectElement { | ||
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'info'; | ||
this.classes.push('info'); | ||
} | ||
|
||
get title(): StringElement | undefined { | ||
return this.get('title'); | ||
} | ||
|
||
set title(title: StringElement | undefined) { | ||
this.set('title', title); | ||
} | ||
|
||
get summary(): StringElement | undefined { | ||
return this.get('summary'); | ||
} | ||
|
||
set summary(summary: StringElement | undefined) { | ||
this.set('summary', summary); | ||
} | ||
|
||
get description(): StringElement | undefined { | ||
return this.get('description'); | ||
} | ||
|
||
set description(description: StringElement | undefined) { | ||
this.set('description', description); | ||
} | ||
|
||
get version(): StringElement | undefined { | ||
return this.get('version'); | ||
} | ||
|
||
set version(version: StringElement | undefined) { | ||
this.set('version', version); | ||
} | ||
} | ||
|
||
export default Info; |
12 changes: 12 additions & 0 deletions
12
packages/apidom-ns-workflows-1/src/elements/WorkflowsSpec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { StringElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
class WorkflowsSpec extends StringElement { | ||
constructor(content?: string, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'workflowsSpec'; | ||
this.classes.push('spec-version'); | ||
this.classes.push('version'); | ||
} | ||
} | ||
|
||
export default WorkflowsSpec; |
31 changes: 31 additions & 0 deletions
31
packages/apidom-ns-workflows-1/src/elements/WorkflowsSpecification1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ObjectElement, Attributes, Meta } from '@swagger-api/apidom-core'; | ||
|
||
import WorkflowsSpecElement from './WorkflowsSpec'; | ||
import InfoElement from './Info'; | ||
|
||
class WorkflowsSpecification1 extends ObjectElement { | ||
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes) { | ||
super(content, meta, attributes); | ||
this.element = 'workflowsSpecification1'; | ||
this.classes.push('api'); | ||
this.classes.push('workflow'); | ||
} | ||
|
||
get workflowsSpec(): WorkflowsSpecElement | undefined { | ||
return this.get('workflowsSpec'); | ||
} | ||
|
||
set workflowsSpec(workflowsSpec: WorkflowsSpecElement | undefined) { | ||
this.set('workflowsSpec', workflowsSpec); | ||
} | ||
|
||
get info(): InfoElement | undefined { | ||
return this.get('info'); | ||
} | ||
|
||
set info(info: InfoElement | undefined) { | ||
this.set('info', info); | ||
} | ||
} | ||
|
||
export default WorkflowsSpecification1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,46 @@ | ||
const variable = 'value'; | ||
export { | ||
isRefElement, | ||
isLinkElement as isLinkPrimitiveElement, | ||
isMemberElement, | ||
isObjectElement, | ||
isArrayElement, | ||
isBooleanElement, | ||
isNullElement, | ||
isElement, | ||
isNumberElement, | ||
isStringElement, | ||
} from '@swagger-api/apidom-core'; | ||
|
||
export default variable; | ||
export { default as mediaTypes, WorkflowsMediaTypes } from './media-types'; | ||
|
||
// eslint-disable-next-line no-restricted-exports | ||
export { default } from './namespace'; | ||
|
||
export { default as refractorPluginReplaceEmptyElement } from './refractor/plugins/replace-empty-element'; | ||
|
||
export { default as refract, createRefractor } from './refractor'; | ||
export { default as specificationObj } from './refractor/specification'; | ||
|
||
export { | ||
isWorkflowsSpecElement, | ||
isWorkflowsSpecification1Element, | ||
isInfoElement, | ||
} from './predicates'; | ||
|
||
export { isWorkflowsSpecificationExtension } from './refractor/predicates'; | ||
|
||
export { default as FixedFieldsVisitor } from './refractor/visitors/generics/FixedFieldsVisitor'; | ||
export { default as MapVisitor } from './refractor/visitors/generics/MapVisitor'; | ||
export { default as MixedFieldsVisitor } from './refractor/visitors/generics/MixedFieldsVisitor'; | ||
export { default as FallbackVisitor } from './refractor/visitors/FallbackVisitor'; | ||
export { default as SpecificationVisitor } from './refractor/visitors/SpecificationVisitor'; | ||
export { default as Visitor } from './refractor/visitors/Visitor'; | ||
|
||
export { keyMap, getNodeType } from './traversal/visitor'; | ||
|
||
// Workflows 1.0.0 elements | ||
export { | ||
WorkflowsSpecification1Element, | ||
WorkflowsSpecElement, | ||
InfoElement, | ||
} from './refractor/registration'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { last } from 'ramda'; | ||
import { MediaTypes } from '@swagger-api/apidom-core'; | ||
|
||
type Format = 'generic' | 'json' | 'yaml'; | ||
|
||
export class WorkflowsMediaTypes extends MediaTypes<string> { | ||
filterByFormat(format: Format = 'generic') { | ||
const effectiveFormat = format === 'generic' ? 'workflows;version' : format; | ||
return this.filter((mediaType) => mediaType.includes(effectiveFormat)); | ||
} | ||
|
||
findBy(version = '1.0.0', format: Format = 'generic') { | ||
const search = | ||
format === 'generic' | ||
? `vnd.oai.workflows;version=${version}` | ||
: `vnd.oai.workflows+${format};version=${version}`; | ||
const found = this.find((mediaType) => mediaType.includes(search)); | ||
|
||
return found || this.unknownMediaType; | ||
} | ||
|
||
latest(format: Format = 'generic') { | ||
return last(this.filterByFormat(format)) as string; | ||
} | ||
} | ||
|
||
const mediaTypes = new WorkflowsMediaTypes( | ||
'application/vnd.oai.workflows;version=3.0.0', | ||
'application/vnd.oai.workflows+json;version=3.0.0', | ||
'application/vnd.oai.workflows+yaml;version=3.0.0', | ||
); | ||
|
||
export default mediaTypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NamespacePluginOptions } from '@swagger-api/apidom-core'; | ||
|
||
import WorkflowsSpecification1Element from './elements/WorkflowsSpecification1'; | ||
import WorkflowsSpecElement from './elements/WorkflowsSpec'; | ||
import InfoElement from './elements/Info'; | ||
|
||
const workflows1 = { | ||
namespace: (options: NamespacePluginOptions) => { | ||
const { base } = options; | ||
|
||
base.register('workflowsSpecification1', WorkflowsSpecification1Element); | ||
base.register('workflowsSpec', WorkflowsSpecElement); | ||
base.register('info', InfoElement); | ||
|
||
return base; | ||
}, | ||
}; | ||
|
||
export default workflows1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createPredicate } from '@swagger-api/apidom-core'; | ||
|
||
import WorkflowsSpecification1Element from './elements/WorkflowsSpecification1'; | ||
import WorkflowsSpecElement from './elements/WorkflowsSpec'; | ||
import InfoElement from './elements/Info'; | ||
|
||
export const isWorkflowsSpecElement = createPredicate( | ||
({ hasBasicElementProps, isElementType, primitiveEq }) => { | ||
return (element: unknown): element is WorkflowsSpecElement => | ||
element instanceof WorkflowsSpecElement || | ||
(hasBasicElementProps(element) && | ||
isElementType('workflowsSpec', element) && | ||
primitiveEq('string', element)); | ||
}, | ||
); | ||
|
||
export const isWorkflowsSpecification1Element = createPredicate( | ||
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => { | ||
return (element: unknown): element is WorkflowsSpecification1Element => | ||
element instanceof WorkflowsSpecification1Element || | ||
(hasBasicElementProps(element) && | ||
isElementType('workflowsSpecification1', element) && | ||
primitiveEq('object', element) && | ||
hasClass('api', element) && | ||
hasClass('workflow', element)); | ||
}, | ||
); | ||
|
||
export const isInfoElement = createPredicate( | ||
({ hasBasicElementProps, isElementType, primitiveEq, hasClass }) => { | ||
return (element: unknown): element is InfoElement => | ||
element instanceof InfoElement || | ||
(hasBasicElementProps(element) && | ||
isElementType('info', element) && | ||
primitiveEq('object', element) && | ||
hasClass('info', element)); | ||
}, | ||
); |
Oops, something went wrong.