redoc icon indicating copy to clipboard operation
redoc copied to clipboard

Multi-level inheritance support

Open sudsk opened this issue 8 years ago • 24 comments

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

sudsk avatar Feb 21 '17 15:02 sudsk

@suds123 could you share your spec or at least the minimal reproducible example. Or at least screenshot

Thanks

RomanHotsiy avatar Feb 21 '17 16:02 RomanHotsiy

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 - petstore

OpenAPI spec - openapi.yaml.txt

sudsk avatar Feb 21 '17 18:02 sudsk

@suds123 thank you for clarification. Unfortunately this is currently not supported by ReDoc as this requires some rewrite Will be implemented in the future

RomanHotsiy avatar Feb 22 '17 08:02 RomanHotsiy

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?

avkonst avatar May 22 '17 03:05 avkonst

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.

Lytkini avatar Sep 11 '17 13:09 Lytkini

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

RomanHotsiy avatar Sep 12 '17 04:09 RomanHotsiy

@RomanGotsiy, got it. Thanks a lot for the quick response!

Lytkini avatar Sep 12 '17 09:09 Lytkini

@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 avatar May 30 '18 08:05 am0nshi

@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

RomanHotsiy avatar May 30 '18 09:05 RomanHotsiy

@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#

am0nshi avatar May 30 '18 13:05 am0nshi

An ETA when it will be available?

raderio avatar Jul 03 '18 07:07 raderio

@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.

RomanHotsiy avatar Oct 26 '18 07:10 RomanHotsiy

@RomanGotsiy can you please add the issue link here?

raderio avatar Nov 01 '18 12:11 raderio

@RomanGotsiy have you open an issue in OpenAPI repository?

raderio avatar Nov 19 '18 12:11 raderio

Unfortunately not yet :(

Super busy. Will try to find time soon

RomanHotsiy avatar Nov 19 '18 13:11 RomanHotsiy

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. 🎉

bzon avatar Feb 17 '19 13:02 bzon

@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.

doctornick42 avatar Apr 15 '19 13:04 doctornick42

This requires some clarification from OpenAPI spec authors about discriminator.

@RomanGotsiy can you please describe what clarification do you need from OpenAPI?

raderio avatar Apr 15 '19 20:04 raderio

Any update?

liquid207 avatar Dec 09 '21 09:12 liquid207

We're getting this too. Our first level are abstract types so it's very unhelpful!

dave-yotta avatar Aug 14 '23 11:08 dave-yotta

Yep, this would be great to support! :pray:

dorrogeray avatar Sep 22 '23 08:09 dorrogeray

Any update?

ilaoud avatar Feb 22 '24 14:02 ilaoud

Might have to be one of us that opens a PR 😆

dave-yotta avatar Feb 23 '24 13:02 dave-yotta