Description
Describe the bug
When having a schema as follows
MetaOrganisationMembership:
oneOf:
- $ref: '#/components/schemas/OrganisationMembership'
- type: array
items:
$ref: '#/components/schemas/OrganisationMembership'
Redoc renders only one example, and the content is an empty array [ ]
.
The request body schema on the other hand correctly shows two options, with one of them being the type itself and the other being an array of the same type.
Only the example generation is the issue here.
Edit for clarification:
- Redoc is only generating one example while it should generate two (this is due to the examples having the same key and overwriting each other).
- The generated example is wrong (an empty array).
Expected behavior
There are two examples, one example of the type and other of the type in an array.
Minimal reproducible OpenAPI snippet(if possible)
If you give me an editor where I can edit the openapi.yaml
and see the Redoc result I can create one.
Below is how the schema currently uses the MetaOrganisation schema.
post:
operationId: organisations_members_create
parameters:
- in: path
name: organisation_id
schema:
type: string
required: true
tags:
- organisations-members
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MetaOrganisationMembership'
Screenshots
This is correct:
This is the generated example(s):
This is how it looks like in swagger-ui:
Swagger-ui only displays one of the examples. If the oneOf
order is swapped then it renders this:
Additional context
Redoc version: 2.4.0
After debugging this a bit, there are actually two issues here:
- The
subSchema.title
here has the same value ("OrganisationMembership"
) for both the type and the array of the same type, which means that only the last example inoneOf
is kept. https://github.com/Redocly/redoc/blob/v2.4.0/src/services/models/MediaType.ts#L69 - The
Sampler
returns[]
as the sample for the array of type example. https://github.com/Redocly/redoc/blob/v2.4.0/src/services/models/MediaType.ts#L63