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

Commit d7cfd5f

Browse files
Marco Frisokylef
authored andcommitted
fix(oas3): set default property as attribute
1 parent 55e1a41 commit d7cfd5f

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

packages/openapi3-parser/lib/parser/oas/parseServerVariableObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const parseServerVariableObject = (context, element) => pipeParseResult(context.
5656
(object) => {
5757
const variable = R.or(object.get('enum'), new context.namespace.elements.String());
5858

59-
variable.default = object.getValue('default');
59+
variable.attributes.set('default', object.get('default'));
6060

6161
if (object.hasKey('description')) {
6262
variable.description = object.getValue('description');

packages/openapi3-parser/test/unit/parser/oas/parseOpenAPIObject-test.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ describe('#parseOpenAPIObject', () => {
5757
paths: {},
5858
servers: [
5959
{
60-
url: 'https://user.server.com/1.0',
60+
url: 'https://{username}.server.com/1.0',
61+
variables: {
62+
username: {
63+
default: 'Mario',
64+
enum: ['Tony', 'Nina'],
65+
},
66+
},
6167
},
6268
{
6369
url: 'https://user.server.com/2.0',
@@ -77,9 +83,23 @@ describe('#parseOpenAPIObject', () => {
7783
expect(hostsCategory.classes.toValue()).to.deep.equal(['hosts']);
7884
expect(hostsCategory.length).to.equal(2);
7985

80-
const firstServer = hostsCategory.get(0);
81-
expect(firstServer).to.be.instanceof(namespace.elements.Resource);
82-
expect(firstServer.href.toValue()).to.equal('https://user.server.com/1.0');
86+
const firstHost = hostsCategory.get(0);
87+
expect(firstHost).to.be.instanceof(namespace.elements.Resource);
88+
expect(firstHost.href.toValue()).to.equal('https://{username}.server.com/1.0');
89+
90+
const { hrefVariables } = firstHost;
91+
expect(hrefVariables).to.be.instanceof(namespace.elements.HrefVariables);
92+
expect(hrefVariables.length).to.equal(1);
93+
94+
const hrefVariable = hrefVariables.content.content[0];
95+
expect(hrefVariable).to.be.instanceof(namespace.elements.Member);
96+
expect(hrefVariable.key.toValue()).to.equal('username');
97+
expect(hrefVariable.value.attributes.get('default').toValue()).to.equal('Mario');
98+
99+
const { enumerations } = hrefVariable.value;
100+
expect(enumerations).to.be.instanceof(namespace.elements.Array);
101+
expect(enumerations.length).to.equal(2);
102+
expect(enumerations.toValue()).to.deep.equal(['Tony', 'Nina']);
83103
});
84104

85105
describe('with schema components', () => {

packages/openapi3-parser/test/unit/parser/oas/parseOperationObject-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ describe('Operation Object', () => {
571571
const hrefVariable = hrefVariables.content.content[0];
572572
expect(hrefVariable).to.be.instanceof(namespace.elements.Member);
573573
expect(hrefVariable.key.toValue()).to.equal('username');
574-
expect(hrefVariable.value.default).to.equal('Mario');
574+
expect(hrefVariable.value.attributes.get('default').toValue()).to.equal('Mario');
575575

576576
const { enumerations } = hrefVariable.value;
577577
expect(enumerations).to.be.instanceof(namespace.elements.Array);

packages/openapi3-parser/test/unit/parser/oas/parsePathItemObject-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ describe('Path Item Object', () => {
481481
const hrefVariable = hrefVariables.content.content[0];
482482
expect(hrefVariable).to.be.instanceof(namespace.elements.Member);
483483
expect(hrefVariable.key.toValue()).to.equal('username');
484-
expect(hrefVariable.value.default).to.equal('Mario');
484+
expect(hrefVariable.value.attributes.get('default').toValue()).to.equal('Mario');
485485

486486
const { enumerations } = hrefVariable.value;
487487
expect(enumerations).to.be.instanceof(namespace.elements.Array);

packages/openapi3-parser/test/unit/parser/oas/parseServerObject-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ describe('#parseServerObject', () => {
136136

137137
expect(firstHrefVariable).to.be.instanceof(namespace.elements.Member);
138138
expect(firstHrefVariable.key.toValue()).to.equal('username');
139-
expect(firstHrefVariable.value.default).to.equal('Mario');
139+
expect(firstHrefVariable.value.attributes.get('default').toValue()).to.equal('Mario');
140140
expect(firstHrefVariable.value.description.toValue()).to.equal('API user name');
141141

142142
expect(secondHrefVariable).to.be.instanceof(namespace.elements.Member);
143143
expect(secondHrefVariable.key.toValue()).to.equal('version');
144-
expect(secondHrefVariable.value.default).to.equal('1.0');
144+
expect(secondHrefVariable.value.attributes.get('default').toValue()).to.equal('1.0');
145145
});
146146

147147
it('warns when variables is defined, but no variables are in the url', () => {
@@ -195,12 +195,12 @@ describe('#parseServerObject', () => {
195195

196196
expect(firstHrefVariable).to.be.instanceof(namespace.elements.Member);
197197
expect(firstHrefVariable.key.toValue()).to.equal('username');
198-
expect(firstHrefVariable.value.default).to.equal('Mario');
198+
expect(firstHrefVariable.value.attributes.get('default').toValue()).to.equal('Mario');
199199
expect(firstHrefVariable.value.description.toValue()).to.equal('API user name');
200200

201201
expect(secondHrefVariable).to.be.instanceof(namespace.elements.Member);
202202
expect(secondHrefVariable.key.toValue()).to.equal('version');
203-
expect(secondHrefVariable.value.default).to.equal('1.0');
203+
expect(secondHrefVariable.value.attributes.get('default').toValue()).to.equal('1.0');
204204
});
205205

206206
it('parse server object with variables', () => {
@@ -233,12 +233,12 @@ describe('#parseServerObject', () => {
233233

234234
expect(firstHrefVariable).to.be.instanceof(namespace.elements.Member);
235235
expect(firstHrefVariable.key.toValue()).to.equal('username');
236-
expect(firstHrefVariable.value.default).to.equal('Mario');
236+
expect(firstHrefVariable.value.attributes.get('default').toValue()).to.equal('Mario');
237237
expect(firstHrefVariable.value.description.toValue()).to.equal('API user name');
238238

239239
expect(secondHrefVariable).to.be.instanceof(namespace.elements.Member);
240240
expect(secondHrefVariable.key.toValue()).to.equal('version');
241-
expect(secondHrefVariable.value.default).to.equal('1.0');
241+
expect(secondHrefVariable.value.attributes.get('default').toValue()).to.equal('1.0');
242242
});
243243
});
244244
});

packages/openapi3-parser/test/unit/parser/oas/parseServerVariableObject-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('#parseServerVariableObject', () => {
5151

5252
const member = parseResult.get(0);
5353
expect(member).to.be.instanceof(namespace.elements.String);
54-
expect(member.default).to.be.equal('Mario');
54+
expect(member.attributes.get('default').toValue()).to.be.equal('Mario');
5555
});
5656
});
5757

0 commit comments

Comments
 (0)