redoc
redoc copied to clipboard
Multi-level inheritance support
Hi team
Does ReDoc supports multi-level polymorphism? I'm able to get ReDoc working for 1 level inheritance, but the second level values just appear as enum values and not as drop down list of values. Any idea if there is no support right now and if in future it can be available?
Regards
@suds123 could you share your spec or at least the minimal reproducible example. Or at least screenshot
Thanks
Taking petstore example. The definition is in yaml and not showing correct indentation, so I have attached the spec file and also ReDoc screenshot. I would expect on selecting Dog from dropdown, it should show a dropdown for dogGroup with values - [HoundDog, SportingDog]. But doesn't seem to work - dogGroup is showing values as enum only.
definitions: Pet: type: object discriminator: petType properties: id: type: string name: type: string petType: type: string required: - name - petType Cat: description: A representation of a cat allOf: - $ref: '#/definitions/Pet' - type: object properties: coat: type: string required: - coat Dog: description: A representation of a dog discriminator: dogGroup allOf: - $ref: '#/definitions/Pet' - type: object properties: packSize: type: integer dogGroup: type: string enum: - SportingDog - HoundDog required: - packSize - dogGroup SportingDog: allOf: - $ref: '#/definitions/Dog' - type: object properties: huntingSkill: type: string HoundDog:: allOf: - $ref: '#/definitions/Dog' - type: object properties: scentSkill: type: string
ReDoc screenshot -
OpenAPI spec - openapi.yaml.txt
@suds123 thank you for clarification. Unfortunately this is currently not supported by ReDoc as this requires some rewrite Will be implemented in the future
I think that this is a part of more generic issue related to the support of oneOf, anyOf, allOf. Discriminator from v2 of the spec does not make things simple and will be conflicting with the xxxOf features, once implemented. And it would be easier to get rid of the discriminator. I have removed it from my APIs and use standard JSON-schema xxxOf features. Redoc may render a nested section per each xxxOf declaration with a headline indicating type of xxx constraint and with "carousel-like" (horizontal) scroller to slide through subtype definitions from inside of the xxxOf. This would be simpler, because it would not require any schema introspection to determine discriminator-like field, would not require "select" based field and reactive response to it. The ReDoc view of sections would map one to one definitions in the JSON-schema, what would be easier to understand for API consumers. What do you think?
Hey, there! Trying to make multi-level inheritance with this:
product:
type: object
discriminator: uuid
required:
- group
- name
- uuid
properties:
uuid:
$ref: '#/productUuid'
name:
$ref: '#/name'
parentUuid:
$ref: '#/parentUuid'
group:
$ref: '#/group'
true:
description: Позиция является группой товаров.
allOf:
- $ref: '#/product'
false:
description: Позиция является отдельным товаром.
allOf:
- $ref: '#/product'
- discriminator: type
required:
- type
- tax
- measureName
- price
properties:
code:
$ref: '#/code'
articleNumber:
$ref: '#/articleNumber'
barCodes:
$ref: '#/barCodes'
allowToSell:
$ref: '#/allowToSell'
description:
$ref: '#/productDescription'
price:
$ref: '#/price'
measureName:
$ref: '#/measureName'
tax:
$ref: '#/tax'
type:
$ref: '#/productType'
Are there any updates about this enhancement? Should I keep trying?
Thanks in advance.
Hey @Lytkini, no, you shouldn't keep trying. The behavior you want to achieve is not yet supported by ReDoc. Maybe it will come together with https://github.com/Rebilly/ReDoc/issues/327
@RomanGotsiy, got it. Thanks a lot for the quick response!
@RomanGotsiy does current library supports this functionality in 2.0.x ? We have a trouble with inheritance and params overriding due to out response object construction. In a response section override params is just ignored and shows only base one. But in a "Response samples" section response structure build ok with all proper data.
@am0nshi Unfortunately, it is not supported yet.
But I think your issue is not related to this. Could you open a separate issue with a minimal reproducible sample of your issue! Thanks
@RomanGotsiy done, could you please take a look once you have time? https://github.com/Rebilly/ReDoc/issues/520 Demo: https://rebilly.github.io/ReDoc/?url=https://gist.githubusercontent.com/am0nshi/311c9c85489002859ae9314462870791/raw/5733da90e5462d8ba313588efea02218d0ae9182/swagger_redoc.json#
An ETA when it will be available?
@raderio not really. This requires some clarification from OpenAPI spec authors about discriminator.
Thanks for reminding me about this issue!
I will open an issue in https://github.com/OAI/OpenAPI-Specification on weekends.
@RomanGotsiy can you please add the issue link here?
@RomanGotsiy have you open an issue in OpenAPI repository?
Unfortunately not yet :(
Super busy. Will try to find time soon
Hopefully we can get this soon! I was following this reference https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/ for inherited request parameters and it doesn't render properly. 🎉
@RomanGotsiy could you please tell, is there any progress with this issue? We have to make a documentation for an existing API and we really need a multi-level discriminator support or any workaround.
Thanks in advance.
This requires some clarification from OpenAPI spec authors about discriminator.
@RomanGotsiy can you please describe what clarification do you need from OpenAPI?
Any update?
We're getting this too. Our first level are abstract types so it's very unhelpful!
Yep, this would be great to support! :pray:
Any update?
Might have to be one of us that opens a PR 😆