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(OpenApi3.1-Yaml): add support for OpenApi.security field #126

Merged
merged 1 commit into from
Oct 13, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const specification = {
components: {
$ref: '#/visitors/document/objects/Components',
},
security: SecurityVisitor,
paths: {
$ref: '#/visitors/document/objects/Paths',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
}
}
},
"security": [
{},
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"servers": [
{
"url": "http://api.example.com/v1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import ServerVariableVisitor from './visitors/open-api-3-1/server-variable';
import ServerVariableEnumVisitor from './visitors/open-api-3-1/server-variable/EnumVisitor';
import ServerVariableDefaultVisitor from './visitors/open-api-3-1/server-variable/DefaultVisitor';
import ServerVariableDescriptionVisitor from './visitors/open-api-3-1/server-variable/DescriptionVisitor';
import SecurityVisitor from './visitors/open-api-3-1/SecurityVisitor';
import SecurityRequirementVisitor from './visitors/open-api-3-1/security-requirement';

/**
* Specification object allows us to have complete control over visitors
Expand Down Expand Up @@ -59,6 +61,7 @@ const specification = {
$ref: '#/visitors/document/objects/Info',
},
servers: ServersVisitor,
security: SecurityVisitor,
},
},
Info: {
Expand Down Expand Up @@ -109,6 +112,9 @@ const specification = {
description: ServerVariableDescriptionVisitor,
},
},
SecurityRequirement: {
$visitor: SecurityRequirementVisitor,
},
},
extension: SpecificationExtensionVisitor,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const PatternedFieldsYamlMappingVisitor = stampit(SpecificationVisitor, {
const visitor = this.retrieveVisitorInstance(specPath);
const keyElement = new this.namespace.elements.String(keyName);

visit(keyValuePairNode, visitor);
visit(valueNode, visitor);

const memberElement = this.maybeAddSourceMap(
keyValuePairNode,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import stampit from 'stampit';
import { isYamlMapping, YamlSequence } from 'apidom-ast';

import { BREAK } from '..';
import SpecificationVisitor from '../SpecificationVisitor';
import { KindVisitor } from '../generics';

const SecurityVisitor = stampit(KindVisitor, SpecificationVisitor, {
init() {
this.element = new this.namespace.elements.Array();
this.element.classes.push('security');
},
methods: {
sequence(sequenceNode: YamlSequence) {
sequenceNode.content.forEach((item) => {
if (isYamlMapping(item)) {
const element = this.nodeToElement(['document', 'objects', 'SecurityRequirement'], item);
this.element.push(element);
} else {
const element = this.nodeToElement(['kind'], item);
this.element.push(element);
}
});

this.maybeAddSourceMap(sequenceNode, this.element);

return BREAK;
},
},
});

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

import MapYamlMappingVisitor from '../../generics/MapYamlMappingVisitor';
import { KindVisitor } from '../../generics';

const SecurityRequirementVisitor = stampit(KindVisitor, MapYamlMappingVisitor, {
props: {
specPath: always(['kind']),
},
init() {
this.element = new this.namespace.elements.SecurityRequirement();
},
});

export default SecurityRequirementVisitor;
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ servers:
variables:
port:
enum:
- '8443'
- '443'
default: '8443'
- 8443
- 443
default: 8443
description: Port description
security:
- {}
- petstore_auth:
- write:pets
- read:pets
...
prop: value