mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-10 19:06:34 +03:00
fix: do not use discriminator when specific schema was referenced in oneOf or anyOf (#2153)
This commit is contained in:
parent
8dc03eb7ed
commit
6ac1e1eb18
|
@ -595,5 +595,65 @@ describe('Models', () => {
|
|||
Tag -> <object> !circular
|
||||
`);
|
||||
});
|
||||
|
||||
test('should not use discriminator for direct schemas refs in oneOf/anyOf', () => {
|
||||
const spec = parseYaml(outdent`
|
||||
openapi: 3.0.0
|
||||
components:
|
||||
schemas:
|
||||
Parent:
|
||||
type: object
|
||||
discriminator:
|
||||
propertyName: type
|
||||
mapping:
|
||||
foo: '#/components/schemas/Foo'
|
||||
bar: '#/components/schemas/Bar'
|
||||
baz: '#/components/schemas/Baz'
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
Foo:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Parent'
|
||||
- type: object
|
||||
Bar:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Parent'
|
||||
- type: object
|
||||
Baz:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Parent'
|
||||
- type: object
|
||||
properties:
|
||||
nested:
|
||||
anyOf:
|
||||
- $ref: '#/components/schemas/Foo'
|
||||
- $ref: '#/components/schemas/Bar'
|
||||
|
||||
`) as any;
|
||||
|
||||
parser = new OpenAPIParser(spec, undefined, opts);
|
||||
const schema = new SchemaModel(
|
||||
parser,
|
||||
spec.components.schemas.Parent,
|
||||
'#/components/schemas/Parent',
|
||||
opts,
|
||||
);
|
||||
|
||||
expect(printSchema(schema, circularDetailsPrinter)).toMatchInlineSnapshot(`
|
||||
oneOf
|
||||
foo ->
|
||||
type: <string>
|
||||
bar ->
|
||||
type: <string>
|
||||
baz ->
|
||||
type: <string>
|
||||
nested: oneOf
|
||||
Foo ->
|
||||
type: <string>
|
||||
Bar ->
|
||||
type: <string>
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -253,6 +253,8 @@ export class SchemaModel {
|
|||
...merged,
|
||||
title,
|
||||
allOf: [{ ...this.schema, oneOf: undefined, anyOf: undefined }],
|
||||
// if specific child schemas are listed in oneOf/anyOf, they are not supposed to be discriminated
|
||||
discriminator: derefVariant.allOf ? undefined : merged.discriminator,
|
||||
} as OpenAPISchema,
|
||||
variant.$ref || this.pointer + '/oneOf/' + idx,
|
||||
this.options,
|
||||
|
|
Loading…
Reference in New Issue
Block a user