Skip to content

Commit

Permalink
fix: skips validation for non-string enum values (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamerJaser96 authored and dpopp07 committed Jun 19, 2019
1 parent 8c1a38b commit fe4211f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/plugins/validation/2and3/semantic-validators/schema-ibm.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,15 @@ function checkEnumValues(schema, contextPath, config) {

for (let i = 0; i < schema.enum.length; i++) {
const enumValue = schema.enum[i];

const checkStatus = config.snake_case_only || 'off';
if (checkStatus.match('error|warning')) {
if (!isSnakecase(enumValue)) {
result[checkStatus].push({
path: contextPath.concat(['enum', i.toString()]),
message: 'Enum values must be lower snake case.'
});
if (typeof enumValue === 'string') {
const checkStatus = config.snake_case_only || 'off';
if (checkStatus.match('error|warning')) {
if (!isSnakecase(enumValue)) {
result[checkStatus].push({
path: contextPath.concat(['enum', i.toString()]),
message: 'Enum values must be lower snake case.'
});
}
}
}
}
Expand Down Expand Up @@ -398,16 +399,17 @@ function checkEnumCaseConvention(schema, contextPath, caseConvention) {

for (let i = 0; i < schema.enum.length; i++) {
const enumValue = schema.enum[i];

const checkStatus = caseConvention[0] || 'off';
if (checkStatus.match('error|warning')) {
const caseConventionValue = caseConvention[1];
const isCorrectCase = checkCase(enumValue, caseConventionValue);
if (!isCorrectCase) {
result[checkStatus].push({
path: contextPath.concat(['enum', i.toString()]),
message: `Enum values must follow case convention: ${caseConventionValue}`
});
if (typeof enumValue === 'string') {
const checkStatus = caseConvention[0] || 'off';
if (checkStatus.match('error|warning')) {
const caseConventionValue = caseConvention[1];
const isCorrectCase = checkCase(enumValue, caseConventionValue);
if (!isCorrectCase) {
result[checkStatus].push({
path: contextPath.concat(['enum', i.toString()]),
message: `Enum values must follow case convention: ${caseConventionValue}`
});
}
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions test/plugins/validation/2and3/schema-ibm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1328,4 +1328,32 @@ describe('validation plugin - semantic - schema-ibm - OpenAPI 3', () => {
'Enum values must follow case convention: lower_snake_case'
);
});

it('should skip validation for non string values', () => {
const config = {
schemas: {
snake_case_only: 'warning'
}
};

const spec = {
definitions: {
Thing: {
type: 'object',
description: 'thing',
properties: {
integer: {
type: 'integer',
description: 'an integer',
enum: [1, 2, 3]
}
}
}
}
};

const res = validate({ jsSpec: spec, isOAS3: true }, config);
expect(res.errors.length).toEqual(0);
expect(res.warnings.length).toEqual(0);
});
});

0 comments on commit fe4211f

Please sign in to comment.