Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit eea078b

Browse files
Marco Frisokylef
authored andcommitted
feat(oas3): add support to 'servers' in 'operation' object
Closes APIARY-6502
1 parent c16f5aa commit eea078b

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

packages/fury-adapter-oas3-parser/lib/parser/oas/parseOperationObject.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const parseObject = require('../parseObject');
1313
const parseString = require('../parseString');
1414
const parseResponsesObject = require('./parseResponsesObject');
1515
const parseParameterObjects = require('./parseParameterObjects');
16+
const parseServersArray = require('./parseServersArray');
1617
const parseRequestBodyObject = require('./parseRequestBodyObject');
1718
const parseSecurityRequirementsArray = require('./parseSecurityRequirementsArray');
1819
const parseReference = require('../parseReference');
@@ -110,6 +111,7 @@ function parseOperationObject(context, path, member) {
110111
[hasKey('responses'), R.compose(parseResponsesObject(context), getValue)],
111112
[hasKey('requestBody'), R.compose(parseRequestBodyObjectOrRef(context), getValue)],
112113
[hasKey('parameters'), R.compose(parseParameterObjects(context, name), getValue)],
114+
[hasKey('servers'), R.compose(parseServersArray(context, name), getValue)],
113115
[hasKey('security'), R.compose(parseSecurityRequirementsArray(context), getValue)],
114116

115117
[isUnsupportedKey, createUnsupportedMemberWarning(namespace, name)],
@@ -163,6 +165,8 @@ function parseOperationObject(context, path, member) {
163165
}
164166
}
165167

168+
transition.hosts = operation.get('servers');
169+
166170
const security = operation.get('security');
167171
if (security) {
168172
transactions.forEach((transaction) => {

packages/fury-adapter-oas3-parser/test/unit/parser/oas/parseOperationObject-test.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,77 @@ describe('Operation Object', () => {
494494
});
495495
});
496496

497+
describe('#servers', () => {
498+
it('warns when servers is not an array', () => {
499+
const operation = new namespace.elements.Member('get', {
500+
servers: {},
501+
responses: {},
502+
});
503+
504+
const parseResult = parse(context, path, operation);
505+
506+
expect(parseResult.length).to.equal(2);
507+
expect(parseResult.get(0)).to.be.instanceof(namespace.elements.Transition);
508+
509+
expect(parseResult).to.contain.warning("'Operation Object' 'servers' is not an array");
510+
});
511+
512+
it('exposes servers as an array in the transition', () => {
513+
const operation = new namespace.elements.Member('get', {
514+
servers: [
515+
{
516+
url: 'https://{username}.server.com/1.0',
517+
variables: {
518+
username: {
519+
default: 'Mario',
520+
enum: ['Tony', 'Nina'],
521+
},
522+
},
523+
},
524+
{
525+
url: 'https://user.server.com/2.0',
526+
description: 'The production API server',
527+
},
528+
],
529+
responses: {},
530+
});
531+
532+
const parseResult = parse(context, path, operation);
533+
534+
expect(parseResult.length).to.equal(1);
535+
expect(parseResult.get(0)).to.be.instanceof(namespace.elements.Transition);
536+
537+
const hostsCategory = parseResult.get(0).hosts;
538+
expect(hostsCategory).to.be.instanceof(namespace.elements.Category);
539+
expect(hostsCategory.classes.toValue()).to.deep.equal(['hosts']);
540+
expect(hostsCategory.length).to.equal(2);
541+
542+
const firstHost = hostsCategory.get(0);
543+
expect(firstHost).to.be.instanceof(namespace.elements.Resource);
544+
expect(firstHost.href.toValue()).to.equal('https://{username}.server.com/1.0');
545+
546+
const { hrefVariables } = firstHost;
547+
expect(hrefVariables).to.be.instanceof(namespace.elements.HrefVariables);
548+
expect(hrefVariables.length).to.equal(1);
549+
550+
const hrefVariable = hrefVariables.content.content[0];
551+
expect(hrefVariable).to.be.instanceof(namespace.elements.Member);
552+
expect(hrefVariable.key.toValue()).to.equal('username');
553+
expect(hrefVariable.value.default).to.equal('Mario');
554+
555+
const { enumerations } = hrefVariable.value;
556+
expect(enumerations).to.be.instanceof(namespace.elements.Array);
557+
expect(enumerations.length).to.equal(2);
558+
expect(enumerations.toValue()).to.deep.equal(['Tony', 'Nina']);
559+
560+
const secondHost = hostsCategory.get(1);
561+
expect(secondHost).to.be.instanceof(namespace.elements.Resource);
562+
expect(secondHost.classes.toValue()).to.deep.equal(['host']);
563+
expect(secondHost.description.toValue()).to.equal('The production API server');
564+
expect(secondHost.href.toValue()).to.equal('https://user.server.com/2.0');
565+
});
566+
});
567+
497568
describe('#security', () => {
498569
it('parses correctly when there is a security requirement', () => {
499570
const operation = new namespace.elements.Member('get', {

0 commit comments

Comments
 (0)