ePages-de / restdocs-api-spec

Adds API specification support to Spring REST Docs
MIT License
375 stars 100 forks source link

Fields order in OpenAPI Specification #198

Open aliaksei-taliuk opened 2 years ago

aliaksei-taliuk commented 2 years ago

Hi!

I have the next documentation section in my test:

...
.responseFields(
                                fieldWithPath("albums").description("Result list of requested albums"),
                                fieldWithPath("albums[].id").description("Album id, f.e. 59727856"),
                                fieldWithPath("albums[].barcodeId").description("Album's barcode id (EAN-13 or UPC-A)").optional(),
                                ...
                        )
...

while OpenAPI Spec has the next relevant section:

...
components:
  schemas:
    albums629762604:
      type: object
      properties:
        albums:
          type: array
          description: Result list of requested albums
          items:
            type: object
            properties:
              copyright:
                type: string
                description: Album's copyright information
              releaseDate:
                type: string
                description: Album's release date (ISO-8601)
              numberOfVolumes:
                type: number
                description: Number of volumes
             ...
...

which doesn't match the order in my test.

I do understand that from the structural point of view this is not a problem at all, but it is important when you trying to generate some static web pages based on Open API Spec. And there you may see fields in some non-logical order.

I do appreciate any feedback and your thoughts in this regard!

Thanks in advance!

ozscheyge commented 2 years ago

Hey @aliaksei-taliuk ,

yes, afaik the supported spec formats don't require any property order nor imply semantics with the ordering.

Spring Restdocs values the order in which fields are documented for the generated HTML docs, so maybe we should do the same. The current "shuffleing" probably stems from use of HashMaps/HashSets (over insertion-order-stable LinkedHashMaps, LinkedHashSets) or the Kotlin equivalents.

aliaksei-taliuk commented 2 years ago

Thanks for the reply! This enhancement would be much appreciated!

mgkim-woowahan commented 8 months ago

I am also experiencing the same issue and I don't understand how to solve it. The latest version is 1.9.0.

The yaml is not created in the order of FieldDescriptor entered in requestFields of the test code.

I am not using Map or Set. What should I do?

I also attach the code and result screen.

< Test Code > image

< Result > image