Skip to content

Commit 2b1d876

Browse files
csWendpopp07
andauthored
fix: allow rules with flexible second options
* fix: customize ignore names for inconsistent property * chore: update comment Co-authored-by: Dustin Popp <[email protected]>
1 parent 76f0eba commit 2b1d876

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/cli-validator/utils/processConfiguration.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ const validateConfigOption = function(userOption, defaultOption) {
363363
optionType = option;
364364
}
365365
});
366+
// if optionType doesn't match, there are no predefined options for this rule
367+
if (!optionType) {
368+
return result;
369+
}
366370
// verify the given option is valid
367371
const validOptions = configOptions[optionType];
368372
if (!validOptions.includes(userOption)) {

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,4 +1800,51 @@ describe('validation plugin - semantic - schema-ibm - OpenAPI 3', () => {
18001800
expect(res.warnings.length).toEqual(0);
18011801
expect(res.errors.length).toEqual(0);
18021802
});
1803+
1804+
it('should not produce a warning for properties with duplicate custom names', () => {
1805+
const customConfig = {
1806+
schemas: {
1807+
inconsistent_property_type: ['warning', ['year']]
1808+
}
1809+
};
1810+
1811+
const spec = {
1812+
components: {
1813+
schemas: {
1814+
person: {
1815+
description: 'Produce warnings',
1816+
properties: {
1817+
year: {
1818+
description: 'type integer',
1819+
type: 'integer'
1820+
}
1821+
}
1822+
},
1823+
adult: {
1824+
description: 'Causes first warnings',
1825+
properties: {
1826+
year: {
1827+
description: 'different type',
1828+
type: 'number'
1829+
}
1830+
}
1831+
},
1832+
kid: {
1833+
description: 'Causes second warning',
1834+
properties: {
1835+
year: {
1836+
type: 'string',
1837+
description: 'differnt type'
1838+
}
1839+
}
1840+
}
1841+
}
1842+
}
1843+
};
1844+
1845+
const res = validate({ jsSpec: spec }, customConfig);
1846+
1847+
expect(res.warnings.length).toEqual(0);
1848+
expect(res.errors.length).toEqual(0);
1849+
});
18031850
});

0 commit comments

Comments
 (0)