Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/validator/src/cli-validator/run-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ async function runValidator(cliArgs, parseOptions = {}) {
// jsonValidator looks through the originalFile for duplicate JSON keys
// this is checked for by default in readYaml
const duplicateKeysError = jsonValidator.validate(originalFile);
if (fileExtension === 'json' && duplicateKeysError) {
if (
fileExtension === 'json' &&
duplicateKeysError &&
!duplicateKeysError.startsWith('Syntax error: empty string near')
) {
throw duplicateKeysError;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"openapi": "3.0.0",
"info": {
"title": "Empty string key test",
"version": "1.0.0"
},
"paths": {},
"components": {
"schemas": {
"Sample": {
"type": "object",
"properties": {
"": {
"type": "string"
}
}
}
}
}
}
16 changes: 16 additions & 0 deletions packages/validator/test/cli-validator/tests/error-handling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ describe('cli tool - test error handling', function () {
);
});

it('should not reject valid JSON that uses an empty string key', async function () {
let exitCode;
try {
exitCode = await testValidator([
'./test/cli-validator/mock-files/oas3/empty-string-key.json',
]);
} catch (err) {
exitCode = err;
}

const capturedText = getCapturedText(consoleSpy.mock.calls);

expect(exitCode).toEqual(0);
expect(capturedText.join('\n')).not.toContain('Syntax error: empty string near');
});

it('should return an error when a JSON document contains a trailing comma', async function () {
let exitCode;
try {
Expand Down