diff --git a/README.md b/README.md index 433192d45..bfe02bc29 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/src/.defaultsForValidator.js b/src/.defaultsForValidator.js index d1110d52d..0e93f6271 100644 --- a/src/.defaultsForValidator.js +++ b/src/.defaultsForValidator.js @@ -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'], diff --git a/src/plugins/validation/2and3/semantic-validators/schema-ibm.js b/src/plugins/validation/2and3/semantic-validators/schema-ibm.js index 8a7e1d1e4..280a9c0e8 100644 --- a/src/plugins/validation/2and3/semantic-validators/schema-ibm.js +++ b/src/plugins/validation/2and3/semantic-validators/schema-ibm.js @@ -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 + }; + } } } } diff --git a/test/plugins/validation/2and3/schema-ibm.test.js b/test/plugins/validation/2and3/schema-ibm.test.js index 5c37244d0..826d25a5e 100644 --- a/test/plugins/validation/2and3/schema-ibm.test.js +++ b/test/plugins/validation/2and3/schema-ibm.test.js @@ -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); + }); });