Skip to content

Commit 6b195aa

Browse files
author
Mike Kistler
authored
fix: Skip case_convention checks on deprecated parameters and properties (#88)
1 parent 0b66384 commit 6b195aa

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88

99
# OpenAPI Validator
10-
This command line tool lets you validate OpenAPI documents according to their specification, either [2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) or [3.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md), as well as [custom IBM-defined best practices](http://watson-developer-cloud.github.io/api-guidelines/swagger-coding-style).
10+
This command line tool lets you validate OpenAPI documents according to their specification, either [2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) or [3.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md),
11+
as well as IBM-defined best practices.
1112

1213
#### Notice
1314
Support for Node v8 is deprecated. Support will be officially dropped when it reaches end of life (31 December 2019) or when v1.0 of this package is released, whichever happens first.
@@ -156,12 +157,12 @@ It is recommended to place these files in the root directory of your project. Th
156157

157158
#### Specs
158159

159-
The validator supports two API definition specifications - Swagger 2.0 and OpenAPI 3.0. The validator will automatically determine which spec a document is written in. There are some rules in the validator that only apply to one of the specs and some rules that apply to both. The configuration structure is organized by these "specs".
160+
The validator supports two API definition specifications - OpenAPI 2.0, aka Swagger 2.0, and OpenAPI 3.0. The validator will automatically determine which spec a document is written in. There are some rules in the validator that only apply to one of the specs and some rules that apply to both. The configuration structure is organized by these "specs".
160161
The supported specs are described below:
161162

162163
| Spec | Description |
163164
| -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
164-
| swagger2 | Rules pertaining only to the [Swagger 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) specification. |
165+
| swagger2 | Rules pertaining only to the [OpenAPI 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) specification. |
165166
| oas3 | Rules pertaining only to the [OpenAPI 3.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md) specification |
166167
| shared | Rules pertaining to both of the above specifications. |
167168

@@ -256,7 +257,7 @@ The supported rules are described below:
256257
| Rule | Description | Spec |
257258
| ----------------------------- | ---------------------------------------------------------------------------- | ------ |
258259
| no_empty_descriptions | Flag any `description` field in the spec with an empty or whitespace string. | shared |
259-
| has_circular_references | Flag any circular references found in the Swagger spec. | shared |
260+
| has_circular_references | Flag any circular references found in the API document. | shared |
260261
| $ref_siblings | Flag any properties that are siblings of a `$ref` property. | shared |
261262
| duplicate_sibling_description | Flag descriptions sibling to `$ref` if identical to referenced description. | shared |
262263
| incorrect_ref_pattern | Flag internal `$ref` values that do not point to the section they should (e.g. referencing `parameters` from a `schema` field). | shared |

src/plugins/validation/2and3/semantic-validators/parameters-ibm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ module.exports.validate = function({ jsSpec, isOAS3 }, config) {
4646

4747
const isParameter = obj.in; // the `in` property is required by OpenAPI for parameters - this should be true (unless obj is a ref)
4848
const isHeaderParameter = obj.in && obj.in.toLowerCase() === 'header'; // header params need not be checked for case
49+
const isDeprecated = obj.deprecated === true;
4950

50-
if (isParameter && !isHeaderParameter && !isRef) {
51+
if (isParameter && !isHeaderParameter && !isRef && !isDeprecated) {
5152
const checkStatus = config.param_name_case_convention[0];
5253
if (checkStatus !== 'off') {
5354
const caseConvention = config.param_name_case_convention[1];

src/plugins/validation/2and3/semantic-validators/schema-ibm.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ function checkPropNames(schema, contextPath, config) {
299299
forIn(schema.properties, (property, propName) => {
300300
if (propName.slice(0, 2) === 'x-') return;
301301

302+
// Skip snake_case_only checks for deprecated properties
303+
if (property.deprecated === true) return;
304+
302305
const checkStatus = config.snake_case_only || 'off';
303306
if (checkStatus.match('error|warning')) {
304307
if (!isSnakecase(propName)) {
@@ -335,6 +338,9 @@ function checkPropNamesCaseConvention(schema, contextPath, caseConvention) {
335338
forIn(schema.properties, (property, propName) => {
336339
if (propName.slice(0, 2) === 'x-') return;
337340

341+
// Skip case_convention checks for deprecated properties
342+
if (property.deprecated === true) return;
343+
338344
const checkStatus = caseConvention[0] || 'off';
339345
if (checkStatus.match('error|warning')) {
340346
const caseConventionValue = caseConvention[1];

test/plugins/validation/2and3/parameters-ibm.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@ describe('validation plugin - semantic - parameters-ibm', () => {
9595
expect(res.warnings.length).toEqual(0);
9696
});
9797

98+
it('should not return a case_convention error when parameter is deprecated', () => {
99+
const spec = {
100+
paths: {
101+
'/pets': {
102+
get: {
103+
parameters: [
104+
{
105+
name: 'camelCase',
106+
in: 'query',
107+
description: 'description',
108+
type: 'string',
109+
deprecated: true
110+
}
111+
]
112+
}
113+
}
114+
}
115+
};
116+
117+
const res = validate({ jsSpec: spec }, config);
118+
expect(res.errors.length).toEqual(0);
119+
expect(res.warnings.length).toEqual(0);
120+
});
121+
98122
it('should return an error when type does not match format', () => {
99123
const spec = {
100124
paths: {

test/plugins/validation/2and3/schema-ibm.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,35 @@ describe('validation plugin - semantic - schema-ibm - Swagger 2', () => {
492492
expect(res.warnings.length).toEqual(0);
493493
});
494494

495+
it('should not return a case_convention error when property is deprecated', () => {
496+
const config = {
497+
schemas: {
498+
snake_case_only: 'off',
499+
property_case_convention: ['error', 'lower_snake_case']
500+
}
501+
};
502+
503+
const spec = {
504+
definitions: {
505+
Thing: {
506+
type: 'object',
507+
description: 'thing',
508+
properties: {
509+
thingName: {
510+
type: 'string',
511+
description: 'thing name',
512+
deprecated: true
513+
}
514+
}
515+
}
516+
}
517+
};
518+
519+
const res = validate({ jsSpec: spec }, config);
520+
expect(res.errors.length).toEqual(0);
521+
expect(res.warnings.length).toEqual(0);
522+
});
523+
495524
it('should return an error when a schema has no description', () => {
496525
const config = {
497526
schemas: {

0 commit comments

Comments
 (0)