-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve preprocess logic and skip unneeded clones (#515)
* feat: skip visited nodes * fix: remove uneeded clones * fix: cleanup * fix: remove yaml parse * fix: remove merge * fix: remove uneeded deps * chore: beta * fix: skip schemas * fix: update path to $refs * fix: visit ref and update deref path * chore: comment * test: add polymorphism test for #511
- Loading branch information
Showing
10 changed files
with
190 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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,155 @@ | ||
import * as request from 'supertest'; | ||
import { createApp } from './common/app'; | ||
|
||
describe('511 schema.preprocessor inheritance', () => { | ||
let app = null; | ||
|
||
before(async () => { | ||
// set up express app | ||
app = await createApp( | ||
{ | ||
apiSpec: apiSpec(), | ||
validateResponses: true, | ||
}, | ||
3001, | ||
(app) => { | ||
app.post('/example', (req, res) => { | ||
res.status(201).json({ | ||
object_type: 'PolyObject1', | ||
shared_prop1: 'sp1', | ||
shared_prop2: 'sp2', | ||
polyObject1SpecificProp1: 'poly1', | ||
}); | ||
}); | ||
}, | ||
false, | ||
); | ||
return app; | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it('should return 201', async () => | ||
request(app) | ||
.post(`/example`) | ||
.send({ | ||
object_type: 'PolyObject1', | ||
shared_prop1: 'sp1', | ||
shared_prop2: 'sp2', | ||
polyObject1SpecificProp1: 'poly1', | ||
}) | ||
.expect(201)); | ||
}); | ||
|
||
function apiSpec(): any { | ||
return { | ||
openapi: '3.0.0', | ||
info: { | ||
title: 'Example API', | ||
version: '0.1.0', | ||
}, | ||
servers: [ | ||
{ | ||
url: 'https://localhost/', | ||
}, | ||
], | ||
paths: { | ||
'/example': { | ||
post: { | ||
description: 'Request', | ||
requestBody: { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
$ref: '#/components/schemas/PolyObject', | ||
}, | ||
}, | ||
}, | ||
}, | ||
responses: { | ||
'201': { | ||
description: 'Response', | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'object', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
components: { | ||
schemas: { | ||
PolyObject: { | ||
type: 'object', | ||
discriminator: { | ||
propertyName: 'object_type', | ||
mapping: { | ||
PolyObject1: '#/components/schemas/PolyObject1', | ||
PolyObject2: '#/components/schemas/PolyObject2', | ||
}, | ||
}, | ||
oneOf: [ | ||
{ | ||
$ref: '#/components/schemas/PolyObject1', | ||
}, | ||
{ | ||
$ref: '#/components/schemas/PolyObject2', | ||
}, | ||
], | ||
}, | ||
PolyObjectBase: { | ||
type: 'object', | ||
required: ['object_type'], | ||
properties: { | ||
object_type: { | ||
type: 'string', | ||
enum: ['PolyObject1', 'PolyObject2'], | ||
}, | ||
shared_prop1: { | ||
type: 'string', | ||
}, | ||
shared_prop2: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
PolyObject1: { | ||
allOf: [ | ||
{ | ||
$ref: '#/components/schemas/PolyObjectBase', | ||
}, | ||
{ | ||
type: 'object', | ||
properties: { | ||
polyObject1SpecificProp1: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
PolyObject2: { | ||
allOf: [ | ||
{ | ||
$ref: '#/components/schemas/PolyObjectBase', | ||
}, | ||
{ | ||
type: 'object', | ||
properties: { | ||
polyObject2SpecificProp1: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |