Skip to content

Commit c8b07ff

Browse files
authored
fix: make operationId naming convention check configurable (#149)
1 parent 7286284 commit c8b07ff

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ The supported rules are described below:
210210
| no_summary | Flag any operations that do not have a `summary` field. | shared |
211211
| no_array_responses | Flag any operations with a top-level array response. | shared |
212212
| parameter_order | Flag any operations with optional parameters before a required param. | shared |
213+
| operation_id_naming_convention | Flag any `operationId` that does not follow consistent naming convention. | shared |
213214
| no_request_body_content | [Flag any operations with a `requestBody` that does not have a `content` field.][3] | oas3 |
214215
| no_request_body_name | Flag any operations with a non-form `requestBody` that does not have a name set with `x-codegen-request-body-name`. | oas3|
215216

@@ -388,6 +389,7 @@ The default values for each rule are described below.
388389
| no_summary | warning |
389390
| no_array_responses | error |
390391
| parameter_order | warning |
392+
| operation_id_naming_convention | warning |
391393

392394
###### pagination
393395
| Rule | Default |

src/.defaultsForValidator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const defaults = {
2626
'no_summary': 'warning',
2727
'no_array_responses': 'error',
2828
'parameter_order': 'warning',
29-
'unused_tag': 'warning'
29+
'unused_tag': 'warning',
30+
'operation_id_naming_convention': 'warning'
3031
},
3132
'pagination': {
3233
'pagination_style': 'warning'

src/plugins/validation/2and3/semantic-validators/operation-ids.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ const merge = require('lodash/merge');
88
const each = require('lodash/each');
99
const MessageCarrier = require('../../../utils/messageCarrier');
1010

11-
module.exports.validate = function({ resolvedSpec }) {
11+
module.exports.validate = function({ resolvedSpec }, config) {
1212
const messages = new MessageCarrier();
1313

14+
config = config.operations;
15+
1416
const validOperationKeys = [
1517
'get',
1618
'head',
@@ -160,7 +162,7 @@ module.exports.validate = function({ resolvedSpec }) {
160162
',',
161163
' or '
162164
),
163-
'warning'
165+
config.operation_id_naming_convention
164166
);
165167
}
166168
}

test/plugins/validation/2and3/operation-ids.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const resolver = require('json-schema-ref-parser');
33
const {
44
validate
55
} = require('../../../../src/plugins/validation/2and3/semantic-validators/operation-ids');
6+
const config = require('../../../../src/.defaultsForValidator').defaults.shared;
67

78
describe('validation plugin - semantic - operation-ids', function() {
89
it('should complain about a repeated operationId in the same path', function() {
@@ -21,7 +22,7 @@ describe('validation plugin - semantic - operation-ids', function() {
2122
}
2223
};
2324

24-
const res = validate({ resolvedSpec: spec });
25+
const res = validate({ resolvedSpec: spec }, config);
2526
expect(res.errors.length).toEqual(1);
2627
expect(res.errors[0].path).toEqual('paths./coolPath.get.operationId');
2728
expect(res.errors[0].message).toEqual('operationIds must be unique');
@@ -50,7 +51,7 @@ describe('validation plugin - semantic - operation-ids', function() {
5051
}
5152
};
5253

53-
const res = validate({ resolvedSpec: spec });
54+
const res = validate({ resolvedSpec: spec }, config);
5455
expect(res.errors.length).toEqual(1);
5556
expect(res.errors[0].path).toEqual('paths./greatPath.put.operationId');
5657
expect(res.errors[0].message).toEqual('operationIds must be unique');
@@ -91,7 +92,7 @@ describe('validation plugin - semantic - operation-ids', function() {
9192

9293
const resolvedSpec = await resolver.dereference(spec);
9394

94-
const res = validate({ resolvedSpec });
95+
const res = validate({ resolvedSpec }, config);
9596
expect(res.errors.length).toEqual(1);
9697
expect(res.errors[0].path).toEqual('paths./greatPath.get.operationId');
9798
expect(res.errors[0].message).toEqual('operationIds must be unique');
@@ -164,7 +165,7 @@ describe('validation plugin - semantic - operation-ids', function() {
164165
};
165166

166167
const resolvedSpec = await resolver.dereference(spec);
167-
const res = validate({ resolvedSpec });
168+
const res = validate({ resolvedSpec }, config);
168169

169170
expect(res.errors.length).toEqual(0);
170171
expect(res.warnings.length).toEqual(12);
@@ -243,7 +244,7 @@ describe('validation plugin - semantic - operation-ids', function() {
243244
};
244245

245246
const resolvedSpec = await resolver.dereference(spec);
246-
const res = validate({ resolvedSpec });
247+
const res = validate({ resolvedSpec }, config);
247248

248249
expect(res.errors.length).toEqual(0);
249250
expect(res.warnings.length).toEqual(0);

0 commit comments

Comments
 (0)