Skip to content

Commit

Permalink
feat(ns-openapi-3-1): finish Calback Object
Browse files Browse the repository at this point in the history
Refs #386
  • Loading branch information
char0n committed May 21, 2021
1 parent 382fccf commit b11a5c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apidom/packages/apidom-ns-openapi-3-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Only fully implemented specification objects should be checked here.
- [ ] [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#mediaTypeObject) (partial)
- [ ] [Encoding Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#encodingObject)
- [x] [Responses Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#responsesObject)
- [ ] [Callback Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#callbackObject) (partial)
- [x] [Callback Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#callbackObject)
- [x] [Example Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#exampleObject)
- [x] [Link Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#linkObject)
- [x] [Header Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#headerObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const isServerLikeElement = <T extends Element>(element: T): boolean => {
return isObjectElement(element) && element.hasKey('url');
};

export const isPathItemLikeElement = isObjectElement;

export const isOpenApiExtension = (element: MemberElement): boolean => {
// @ts-ignore
return isStringElement(element.key) && startsWith('x-', element.key.toValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import stampit from 'stampit';
import { always } from 'ramda';
import { test } from 'ramda';
import { Element } from 'apidom';

import CallbackElement from '../../../../elements/Callback';
import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor';
import PatternedFieldsJsonObjectVisitor from '../../generics/PatternedFieldsVisitor';
import FallbackVisitor from '../../FallbackVisitor';
import { isReferenceLikeElement, isPathItemLikeElement } from '../../../predicates';

const CallbackVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, {
const CallbackVisitor = stampit(PatternedFieldsJsonObjectVisitor, FallbackVisitor, {
props: {
specPath: always(['document', 'objects', 'Callback']),
fieldPatternPredicate: test(/^{(?<expression>.*)}$/),
specPath: (element: Element) => {
// eslint-disable-next-line no-nested-ternary
return isReferenceLikeElement(element)
? ['document', 'objects', 'Reference']
: isPathItemLikeElement(element)
? ['document', 'objects', 'PathItem']
: ['value'];
},
canSupportSpecificationExtensions: true,
},
init() {
this.element = new CallbackElement();
Expand Down

0 comments on commit b11a5c8

Please sign in to comment.