Forum Discussion

nandan's avatar
nandan
New Contributor
11 months ago
Solved

how to change the order of display when using inheritance

hi  Experts/colleagues,

i'm using the the swagger UI latest version for my swagger API documentation.

When using the inheritance via allOf capability, the swagger UI does not respect the order in which the properties are added.

pseudo code:

Approach 1 : 

Customer:

  properties:

    id:...

    userName:...

    allOf:

      - $ref: #/component/schemas/Address

      - type: object

Approach 2:

Customer:

  type: object

   allOf:

      - $ref: #/component/schemas/Address

      - type: object

         properties:

             id:...

             userName:...

 

irrespective of the above two approaches, the swagger UI displays the properties of the Address first and then later the individual properties of the Address object.

 

Can you please share , how i could control the order of the display using the YAML representation  of openAPI specification.

thanks!!

Sharing an Example using the User and Address.

my goal: i would like to have the ID first in the Swagger UI

 

  • chichepo ,

    thanks!! for the work around approach. can be an alternative solution. For completeness if would be good if we have this capability supported out of the box. thanks!! again, appreciate your help and recommendation.

2 Replies

  • chichepo's avatar
    chichepo
    Champion Level 3

    nandan Hi and sorry for this very late answer.
    I have been facing this issue in the past and I think it is very usefull to keep a trace of the discussion, in this forum, for other peoles.

    Obviously, when using the allOf keyword, the SwaggerHub designer must decide which of the available schema must be displayed first.
    Of course, we can naturally expect to see the document preview to follow the same order than the script but, as far as I know, the last schema declaration is always taken and displayed first!!

     

    Anyway, now that this fact is known we can try to find a way to get our expected order.

    First, I propose to extend the usage of allOf in such way:

     


     

     


    Then we can easily play with the wanted order of our visual preview:

     

     


    It's a more elegant way to enhance your approach #2 ðŸ˜‰

    Let us know if you have any other suggestions

    Enjoy!!

     

    • nandan's avatar
      nandan
      New Contributor

      chichepo ,

      thanks!! for the work around approach. can be an alternative solution. For completeness if would be good if we have this capability supported out of the box. thanks!! again, appreciate your help and recommendation.