Ask a Question

Error with discriminator

SOLVED
MattiasO
New Contributor

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.

 

MattiasO_0-1666941181285.png

 

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

 

1 REPLY 1
MattiasO
New Contributor

This seems to have been a bug, and it was resolved in this PR, released in the 4.15.2 release 

cancel
Showing results for 
Search instead for 
Did you mean: