Skip to content

Commit fe4211f

Browse files
SamerJaser96dpopp07
authored andcommitted
fix: skips validation for non-string enum values (#67)
1 parent 8c1a38b commit fe4211f

File tree

2 files changed

+48
-18
lines changed

2 files changed

+48
-18
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,15 @@ function checkEnumValues(schema, contextPath, config) {
363363

364364
for (let i = 0; i < schema.enum.length; i++) {
365365
const enumValue = schema.enum[i];
366-
367-
const checkStatus = config.snake_case_only || 'off';
368-
if (checkStatus.match('error|warning')) {
369-
if (!isSnakecase(enumValue)) {
370-
result[checkStatus].push({
371-
path: contextPath.concat(['enum', i.toString()]),
372-
message: 'Enum values must be lower snake case.'
373-
});
366+
if (typeof enumValue === 'string') {
367+
const checkStatus = config.snake_case_only || 'off';
368+
if (checkStatus.match('error|warning')) {
369+
if (!isSnakecase(enumValue)) {
370+
result[checkStatus].push({
371+
path: contextPath.concat(['enum', i.toString()]),
372+
message: 'Enum values must be lower snake case.'
373+
});
374+
}
374375
}
375376
}
376377
}
@@ -398,16 +399,17 @@ function checkEnumCaseConvention(schema, contextPath, caseConvention) {
398399

399400
for (let i = 0; i < schema.enum.length; i++) {
400401
const enumValue = schema.enum[i];
401-
402-
const checkStatus = caseConvention[0] || 'off';
403-
if (checkStatus.match('error|warning')) {
404-
const caseConventionValue = caseConvention[1];
405-
const isCorrectCase = checkCase(enumValue, caseConventionValue);
406-
if (!isCorrectCase) {
407-
result[checkStatus].push({
408-
path: contextPath.concat(['enum', i.toString()]),
409-
message: `Enum values must follow case convention: ${caseConventionValue}`
410-
});
402+
if (typeof enumValue === 'string') {
403+
const checkStatus = caseConvention[0] || 'off';
404+
if (checkStatus.match('error|warning')) {
405+
const caseConventionValue = caseConvention[1];
406+
const isCorrectCase = checkCase(enumValue, caseConventionValue);
407+
if (!isCorrectCase) {
408+
result[checkStatus].push({
409+
path: contextPath.concat(['enum', i.toString()]),
410+
message: `Enum values must follow case convention: ${caseConventionValue}`
411+
});
412+
}
411413
}
412414
}
413415
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,4 +1328,32 @@ describe('validation plugin - semantic - schema-ibm - OpenAPI 3', () => {
13281328
'Enum values must follow case convention: lower_snake_case'
13291329
);
13301330
});
1331+
1332+
it('should skip validation for non string values', () => {
1333+
const config = {
1334+
schemas: {
1335+
snake_case_only: 'warning'
1336+
}
1337+
};
1338+
1339+
const spec = {
1340+
definitions: {
1341+
Thing: {
1342+
type: 'object',
1343+
description: 'thing',
1344+
properties: {
1345+
integer: {
1346+
type: 'integer',
1347+
description: 'an integer',
1348+
enum: [1, 2, 3]
1349+
}
1350+
}
1351+
}
1352+
}
1353+
};
1354+
1355+
const res = validate({ jsSpec: spec, isOAS3: true }, config);
1356+
expect(res.errors.length).toEqual(0);
1357+
expect(res.warnings.length).toEqual(0);
1358+
});
13311359
});

0 commit comments

Comments
 (0)