Skip to content

Commit

Permalink
Fixed an issue where allOf schemas with both having enum were not res…
Browse files Browse the repository at this point in the history
…olved correctly
  • Loading branch information
VShingala committed Jan 12, 2024
1 parent b7439b8 commit a26279f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/deref.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ module.exports = {
}), {
resolvers: {
// for keywords in OpenAPI schema that are not standard defined JSON schema keywords, use default resolver
defaultResolver: (compacted) => { return compacted[0]; }
defaultResolver: (compacted) => { return compacted[0]; },

// Default resolver seems to fail for enum, so adding custom resolver that will return all unique enum values
enum: (values) => {
return _.uniq(_.concat(...values));
}
}
});
}
Expand Down
5 changes: 4 additions & 1 deletion libV2/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,10 @@ let QUERYPARAM = 'query',
}), {
resolvers: {
// for keywords in OpenAPI schema that are not standard defined JSON schema keywords, use default resolver
defaultResolver: (compacted) => { return compacted[0]; }
defaultResolver: (compacted) => { return compacted[0]; },
enum: (values) => {
return _.uniq(_.concat(...values));
}
}
});
}
Expand Down
22 changes: 22 additions & 0 deletions test/unit/convertV2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,28 @@ describe('The convert v2 Function', function() {
});
});

it('[GITHUB #417] - should convert file with enum as conflicts while merging allOf keyword', function() {
const fileSource = path.join(__dirname, VALID_OPENAPI_PATH, 'enumAllOfConflicts.yaml'),
fileData = fs.readFileSync(fileSource, 'utf8'),
input = {
type: 'string',
data: fileData
};

Converter.convertV2(input, {
optimizeConversion: false
}, (err, result) => {
const expectedResponseBody = JSON.parse(result.output[0].data.item[0].item[0].response[0].body);
expect(err).to.be.null;
expect(result.result).to.be.true;
expect(expectedResponseBody).to.be.an('object');
expect(expectedResponseBody).to.have.property('status');
expect(expectedResponseBody.status).to.be.a('string');
expect(expectedResponseBody.status).to.be.oneOf(['no_market', 'too_small', 'too_large',
'incomplete', 'completed', 'refunded']);
});
});

it('Should convert a swagger document with XML example correctly', function(done) {
const fileData = fs.readFileSync(path.join(__dirname, SWAGGER_20_FOLDER_YAML, 'xml_example.yaml'), 'utf8'),
input = {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/deref.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ describe('DEREF FUNCTION TESTS ', function() {
'type': 'string',
'format': 'uuid'
},
'status': {
'type': 'string',
'enum': ['incomplete', 'completed', 'refunded']
},
'actionId': { 'type': 'integer', 'minimum': 5 },
'result': { 'type': 'object' }
},
Expand All @@ -390,6 +394,10 @@ describe('DEREF FUNCTION TESTS ', function() {
'err': { 'type': 'string' },
'data': { 'type': 'object' }
}
},
'status': {
'type': 'string',
'enum': ['no_market', 'too_small', 'too_large']
}
}
}
Expand All @@ -408,6 +416,10 @@ describe('DEREF FUNCTION TESTS ', function() {
type: 'string',
format: 'uuid'
},
status: {
type: 'string',
enum: ['incomplete', 'completed', 'refunded', 'no_market', 'too_small', 'too_large']
},
actionId: { 'type': 'integer', 'minimum': 5 },
result: {
type: 'object',
Expand Down

0 comments on commit a26279f

Please sign in to comment.