Skip to content

Commit

Permalink
fix: exapand check for operation id duplciates to include referenced …
Browse files Browse the repository at this point in the history
…paths
  • Loading branch information
dpopp07 committed Apr 10, 2019
1 parent cb3545a commit 21e2460
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const reduce = require('lodash/reduce');
const merge = require('lodash/merge');
const each = require('lodash/each');

module.exports.validate = function({ jsSpec }) {
module.exports.validate = function({ resolvedSpec }) {
const errors = [];
const warnings = [];

Expand All @@ -21,7 +21,7 @@ module.exports.validate = function({ jsSpec }) {
];

const operations = reduce(
jsSpec.paths,
resolvedSpec.paths,
(arr, path, pathKey) => {
const pathOps = pickBy(path, (obj, k) => {
return validOperationKeys.indexOf(k) > -1;
Expand Down
46 changes: 44 additions & 2 deletions test/plugins/validation/2and3/operation-ids.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const expect = require('expect');
const resolver = require('json-schema-ref-parser');
const {
validate
} = require('../../../../src/plugins/validation/2and3/semantic-validators/operation-ids');
Expand All @@ -20,7 +21,7 @@ describe('validation plugin - semantic - operation-ids', function() {
}
};

const res = validate({ jsSpec: spec });
const res = validate({ resolvedSpec: spec });
expect(res.errors.length).toEqual(1);
expect(res.errors[0].path).toEqual('paths./coolPath.get.operationId');
expect(res.errors[0].message).toEqual('operationIds must be unique');
Expand Down Expand Up @@ -49,10 +50,51 @@ describe('validation plugin - semantic - operation-ids', function() {
}
};

const res = validate({ jsSpec: spec });
const res = validate({ resolvedSpec: spec });
expect(res.errors.length).toEqual(1);
expect(res.errors[0].path).toEqual('paths./greatPath.put.operationId');
expect(res.errors[0].message).toEqual('operationIds must be unique');
expect(res.warnings.length).toEqual(0);
});

it('should complain about a repeated operationId in a shared path item', async function() {
const spec = {
paths: {
'/coolPath': {
$ref: '#/components/paths/SharedPath'
},
'/greatPath': {
$ref: '#/components/paths/SharedPath'
}
},
components: {
paths: {
SharedPath: {
get: {
operationId: 'shouldBeUnique',
responses: {
'200': {
content: {
'application/json': {
schema: {
type: 'string'
}
}
}
}
}
}
}
}
}
};

const resolvedSpec = await resolver.dereference(spec);

const res = validate({ resolvedSpec });
expect(res.errors.length).toEqual(1);
expect(res.errors[0].path).toEqual('paths./greatPath.get.operationId');
expect(res.errors[0].message).toEqual('operationIds must be unique');
expect(res.warnings.length).toEqual(0);
});
});

0 comments on commit 21e2460

Please sign in to comment.