-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: warn when error response content type is not application/json
- Loading branch information
1 parent
733b534
commit 82f6398
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
test/spectral/tests/custom-rules/ibm-error-content-type-is-json.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const inCodeValidator = require('../../../../src/lib'); | ||
|
||
describe('spectral - test error response content type is application/json', function() { | ||
it('should error only when the error response content type is not application/json', async () => { | ||
const spec = { | ||
openapi: '3.0.0', | ||
paths: { | ||
path1: { | ||
get: { | ||
responses: { | ||
'200': { | ||
content: { | ||
// no error | ||
'application/octet-stream': { | ||
$ref: '#/components/schemas/GenericSchema' | ||
} | ||
} | ||
}, | ||
'400': { | ||
content: { | ||
// error 1 | ||
'application/octet-stream': { | ||
$ref: '#/components/schemas/GenericSchema' | ||
} | ||
} | ||
}, | ||
'404': { | ||
content: { | ||
// no error | ||
'application/json': { | ||
$ref: '#/components/schemas/GenericSchema' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
components: { | ||
schemas: { | ||
GenericSchema: { | ||
type: 'object', | ||
properties: { | ||
prop: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const res = await inCodeValidator(spec, true); | ||
const expectedWarnings = res.warnings.filter( | ||
warn => warn.message === 'error response should support application/json' | ||
); | ||
expect(expectedWarnings.length).toBe(1); | ||
}); | ||
}); |