-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle additional OAS keywords (#141)
* log errors in strict mode * add changeset * fix typos * change changeset message * change title * update comment * remove unused line * add line between functions --------- Co-authored-by: nthapa <[email protected]>
- Loading branch information
1 parent
35ee143
commit e81f606
Showing
5 changed files
with
122 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'oas3-chow-chow': patch | ||
--- | ||
|
||
handle additional open api keywords |
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,51 @@ | ||
import { OpenAPIObject } from 'openapi3-ts'; | ||
import ChowChow from '../src'; | ||
const doc: (additionalKeywords: Record<string, any>) => OpenAPIObject = ( | ||
additionalKeywords = {} | ||
) => ({ | ||
openapi: '3.0.1', | ||
info: { | ||
title: 'service open api spec', | ||
version: '1.0.1', | ||
}, | ||
components: { | ||
schemas: { | ||
ResolveUnsupportedError: { | ||
type: 'object', | ||
properties: { | ||
error: {}, | ||
}, | ||
...additionalKeywords, | ||
}, | ||
}, | ||
}, | ||
paths: { | ||
'/resolve': { | ||
post: { | ||
operationId: 'resolve', | ||
responses: { | ||
'404': { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
$ref: '#/components/schemas/ResolveUnsupportedError', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
describe('additional open api keywords', () => { | ||
it.each([ | ||
{ discriminator: '' }, | ||
{ example: '' }, | ||
{ externalDocs: '' }, | ||
{ xml: '' }, | ||
])('"%s" keyword should be allowed by default', async (additionalKeyword) => { | ||
expect(await ChowChow.create(doc(additionalKeyword))).toBeDefined(); | ||
}); | ||
}); |
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,49 @@ | ||
import { OpenAPIObject, PathItemObject } from 'openapi3-ts'; | ||
import ChowChow from '../src'; | ||
|
||
/** | ||
* https://ajv.js.org/strict-mode.html | ||
*/ | ||
describe('strict mode', () => { | ||
it('show log warn and not throw by default', async () => { | ||
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(); | ||
const doc: OpenAPIObject = { | ||
openapi: '3.0.1', | ||
info: { | ||
title: 'service open api spec', | ||
version: '1.0.1', | ||
}, | ||
components: { | ||
schemas: { | ||
ResolveUnsupportedError: { | ||
type: 'array', | ||
additionalItems: false, | ||
}, | ||
}, | ||
}, | ||
paths: { | ||
'/resolve': { | ||
post: { | ||
operationId: 'resolve', | ||
responses: { | ||
'404': { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
$ref: '#/components/schemas/ResolveUnsupportedError', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(await ChowChow.create(doc)).toBeDefined(); | ||
expect(warnSpy).toHaveBeenCalledWith( | ||
'strict mode: "additionalItems" is ignored when "items" is not an array of schemas' | ||
); | ||
warnSpy.mockRestore(); | ||
}); | ||
}); |
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