-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly host oneOf inside allOf
- Loading branch information
1 parent
e0f58dc
commit 7e5b6d9
Showing
4 changed files
with
188 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { OpenAPIParser } from '../OpenAPIParser'; | ||
import { RedocNormalizedOptions } from '../RedocNormalizedOptions'; | ||
|
||
const opts = new RedocNormalizedOptions({}); | ||
|
||
describe('Models', () => { | ||
describe('Schema', () => { | ||
let parser; | ||
|
||
test('should hoist oneOfs when mergin allOf', () => { | ||
const spec = require('./fixtures/oneOfHoist.json'); | ||
parser = new OpenAPIParser(spec, undefined, opts); | ||
expect(parser.mergeAllOf(spec.components.schemas.test)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
src/services/__tests__/__snapshots__/OpenAPIParser.test.ts.snap
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,84 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = ` | ||
Object { | ||
"oneOf": Array [ | ||
Object { | ||
"oneOf": Array [ | ||
Object { | ||
"allOf": undefined, | ||
"parentRefs": Array [], | ||
"properties": Object { | ||
"extra": Object { | ||
"type": "string", | ||
}, | ||
"password": Object { | ||
"description": "The user's password", | ||
"type": "string", | ||
}, | ||
"username": Object { | ||
"description": "The user's name", | ||
"type": "string", | ||
}, | ||
}, | ||
}, | ||
Object { | ||
"allOf": undefined, | ||
"parentRefs": Array [], | ||
"properties": Object { | ||
"extra": Object { | ||
"type": "string", | ||
}, | ||
"mobile": Object { | ||
"description": "The user's mobile", | ||
"type": "string", | ||
}, | ||
"username": Object { | ||
"description": "The user's name", | ||
"type": "string", | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
Object { | ||
"oneOf": Array [ | ||
Object { | ||
"allOf": undefined, | ||
"parentRefs": Array [], | ||
"properties": Object { | ||
"email": Object { | ||
"description": "The user's email", | ||
"type": "string", | ||
}, | ||
"extra": Object { | ||
"type": "string", | ||
}, | ||
"password": Object { | ||
"description": "The user's password", | ||
"type": "string", | ||
}, | ||
}, | ||
}, | ||
Object { | ||
"allOf": undefined, | ||
"parentRefs": Array [], | ||
"properties": Object { | ||
"email": Object { | ||
"description": "The user's email", | ||
"type": "string", | ||
}, | ||
"extra": Object { | ||
"type": "string", | ||
}, | ||
"mobile": Object { | ||
"description": "The user's mobile", | ||
"type": "string", | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
`; |
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,62 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"version": "1.0", | ||
"title": "Foo" | ||
}, | ||
"components": { | ||
"schemas": { | ||
"test": { | ||
"allOf": [ | ||
{ | ||
"oneOf": [ | ||
{ | ||
"properties": { | ||
"username": { | ||
"description": "The user's name", | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"email": { | ||
"description": "The user's email", | ||
"type": "string" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"properties": { | ||
"extra": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
{ | ||
"oneOf": [ | ||
{ | ||
"properties": { | ||
"password": { | ||
"description": "The user's password", | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"mobile": { | ||
"description": "The user's mobile", | ||
"type": "string" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |