Extending a schema using discriminator does not work
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 25.9k
- Forks
- 2.4k
- Avg merge
- 13h 10m
- Merged PRs (30d)
- 4
Description
Schemas can be extended with new parameters using allOf, however, if you try to extend a schema which uses discriminator, the new parameters are not shown.
In the example below, if I extend #/components/schemas/Simple ReDoc works as expected, but if I extend #/components/schemas/Pet then the extension field is not present in the resulting doc.
Workaround is to duplicate the discriminated schema as many times as you need (in my case three), which can mean quite a lot of duplicated lines.
openapi: 3.0.0
info:
title: Test
version: 1.0.0
components:
schemas:
Simple:
type: object
properties:
simple:
type: string
Pet:
type: object
required:
- pet_type
properties:
pet_type:
type: string
discriminator:
propertyName: pet_type
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Cat`
properties:
name:
type: string
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Dog`
properties:
bark:
type: string
paths:
/rest/stuff:
post:
summary: Create extended pet
requestBody:
content:
application/json:
schema:
allOf:
# If referencing /Simple the extension works, but not on /Pet:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
extension:
type: string
responses:
"200":
description: pet is created
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start by reproducing the provided OpenAPI example and trace how ReDoc resolves and renders allOf schemas with a discriminator. Done means the extension field appears when Pet is extended without duplicating the discriminated schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100