asyncapi-react icon indicating copy to clipboard operation
asyncapi-react copied to clipboard

Support polymorphism

Open Tamriel opened this issue 5 years ago • 17 comments

The following example is found in the chapter Composition and Inheritance (Polymorphism) of the specification.

Current behavior in the generated html: If Pet is used in a message payload, only the attributes of the Pet class are shown.

My desired behavior: A dropdown is shown next to the attribute petType. It has the entries Cat and Dog. Depending on the selection, additional attributes are shown. This is the case in the OpenApi html generator ReDoc.

schemas:
  Pet:
    type: object
    discriminator: petType
    properties:
      name:
        type: string
      petType:
        type: string
    required:
    - name
    - petType
  Cat:  ## "Cat" will be used as the discriminator value
    description: A representation of a cat
    allOf:
    - $ref: '#/components/schemas/Pet'
    - type: object
      properties:
        huntingSkill:
          type: string
          description: The measured skill for hunting
          enum:
          - clueless
          - lazy
          - adventurous
          - aggressive
      required:
      - huntingSkill
  Dog:  ## "Dog" will be used as the discriminator value
    description: A representation of a dog
    allOf:
    - $ref: '#/components/schemas/Pet'
    - type: object
      properties:
        packSize:
          type: integer
          format: int32
          description: the size of the pack the dog is from
          minimum: 0
      required:
      - packSize

Tamriel avatar Jul 16 '19 12:07 Tamriel

This would be great.

Note for the implementer: keep in mind that discriminator is something from OpenAPI schemas and it's not part of JSON Schema. So this feature can only be present when people specify schemaFormat as application/vnd.oai.openapi and similar.

fmvilas avatar Jul 18 '19 23:07 fmvilas

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Mar 12 '20 00:03 github-actions[bot]

It may also be useful to note that discriminator is implemented differently in OpenAPI vs AsyncAPI so the logic cannot be ported over.

trajano avatar Apr 14 '20 18:04 trajano

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Jun 14 '20 00:06 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Aug 15 '20 00:08 github-actions[bot]

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

github-actions[bot] avatar Sep 16 '20 10:09 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Nov 16 '20 00:11 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Mar 17 '21 00:03 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar May 17 '21 00:05 github-actions[bot]

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.

Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

github-actions[bot] avatar Jun 22 '21 08:06 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Aug 22 '21 00:08 github-actions[bot]

@Tamriel hey, can you check current behavior, HTML template (used in playground) changed a lot. Please update the issue if it is still valid

derberg avatar Aug 23 '21 10:08 derberg

@derberg react-component still doesn't support the discriminator property.

magicmatatjahu avatar Aug 23 '21 10:08 magicmatatjahu

Any updates on this topic?

dominik3131 avatar Nov 26 '21 13:11 dominik3131

@dominik3131 Hi. The discriminator is the only thing we don't currently render, and that's because we don't know how to render it nicely. I don't know if this will be implemented in the 1.0.0 release, probably later, but contributions are always welcome :) Why is this so hard to render?

The discriminator only works for schemes of type object, but the problem is how to render it when someone defines a scheme like:

type: 
  type: [object, string, array]
  oneOf: ...
  allOf:
    - .. base schema with discriminiatir
    - .. new properties
  items: ...

From a spec point of view this is still correct, and currently next branch renders this, however how do we render the discriminator in such cases?

magicmatatjahu avatar Nov 29 '21 09:11 magicmatatjahu

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Mar 30 '22 00:03 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Sep 24 '22 00:09 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Apr 19 '23 00:04 github-actions[bot]