Forum Discussion

MattiasO's avatar
MattiasO
New Contributor
3 years ago

Error with discriminator

I'm trying to create an OpenAPI specification with a body with a discriminator field and two models, using oneOf. However, when I try to put the discriminator field itself in each of the models, to get that in the documentation as well, the UI throws an error "😱 Could not render rt, see the console.". In the console, I get an opaque "TypeError: e.$$ref is undefined" error message.

 

 

Reproducible example:

openapi: 3.0.2
info:
title: FastAPI
version: 0.1.0
paths:
/test:
post:
summary: Test Post
operationId: test_post_test_post
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Body'
required: true
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
components:
schemas:
Body:
title: Body
required:
- either
type: object
properties:
either:
title: Either
oneOf:
- $ref: '#/components/schemas/ModelA'
- $ref: '#/components/schemas/ModelB'
discriminator:
propertyName: q_type
mapping:
A: '#/components/schemas/ModelA'
B: '#/components/schemas/ModelB'
ModelA:
title: ModelA
required:
- q_type
- x
type: object
properties:
q_type:
title: Q Type
enum:
- A
type: string
x:
title: X
type: integer
ModelB:
title: ModelB
required:
- q_type
- 'y'
type: object
properties:
q_type:
title: Q Type
enum:
- B
type: string
'y':
title: 'Y'
type: string