Skip to content

Commit

Permalink
feat: exclude common inconsistent property names
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Compton committed Jan 26, 2021
1 parent ecf2a44 commit 7c59cc7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ The default values for each rule are described below.
| no_property_description | warning |
| description_mentions_json | warning |
| array_of_arrays | warning |
| inconsistent_property_type | warning |
| inconsistent_property_type | warning, code, default, type, value] |
| property_case_convention | error, lower_snake_case |
| property_case_collision | error |
| enum_case_convention | warning, lower_snake_case |
Expand Down
2 changes: 1 addition & 1 deletion src/.defaultsForValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const defaults = {
'no_property_description': 'warning',
'description_mentions_json': 'warning',
'array_of_arrays': 'warning',
'inconsistent_property_type': 'warning',
'inconsistent_property_type': ['warning', 'code', 'default', 'type', 'value'],
'property_case_convention': [ 'error', 'lower_snake_case'],
'property_case_collision': 'error',
'enum_case_convention': [ 'warning', 'lower_snake_case'],
Expand Down
17 changes: 10 additions & 7 deletions src/plugins/validation/2and3/semantic-validators/schema-ibm.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,23 +617,26 @@ function checkProperties(
messages.addMessage(
propertiesToCompare[key].path,
`Property has inconsistent type: ${key}.`,
configOption,
configOption[0],
'inconsistent_property_type'
);
}
messages.addMessage(
contextPath.concat(['properties', key]).join('.'),
`Property has inconsistent type: ${key}.`,
configOption,
configOption[0],
'inconsistent_property_type'
);
}
} else {
propertiesToCompare[key] = {
type: value.type,
path: contextPath.concat(['properties', key]).join('.'),
printed: false
};
if (configOption && !configOption.includes(key)) {
// add property if the name is not generic
propertiesToCompare[key] = {
type: value.type,
path: contextPath.concat(['properties', key]).join('.'),
printed: false
};
}
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions test/plugins/validation/2and3/schema-ibm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1759,4 +1759,45 @@ describe('validation plugin - semantic - schema-ibm - OpenAPI 3', () => {
'components.schemas.kid.properties.name'
);
});

it('should not produce a warning for properties with duplicate common names', () => {
const spec = {
components: {
schemas: {
person: {
description: 'Produce warnings',
properties: {
name: {
description: 'type integer',
type: 'integer'
}
}
},
adult: {
description: 'Causes first warnings',
properties: {
code: {
description: 'different type',
type: 'number'
}
}
},
kid: {
description: 'Causes second warning',
properties: {
code: {
type: 'string',
description: 'differnt type'
}
}
}
}
}
};

const res = validate({ jsSpec: spec }, config);

expect(res.warnings.length).toEqual(0);
expect(res.errors.length).toEqual(0);
});
});

0 comments on commit 7c59cc7

Please sign in to comment.