Skip to content

Inconsistent JSON ordering compared to springdoc-openapi #45

Closed
@turnerdaniel

Description

@turnerdaniel

Description

The order of JSON items within the openapi.json file created by this plugin are not consistent with the output of the /v3/api-docs endpoint. I would expect that the order of the JSON files produced by this plugin and springdoc-openapi-webmvc-core remain the same (even if pretty printed). This results in differences in presentation/implementation when using certain clients (e.g Swagger UI).

I realise that JSON is designed to be unordered. However, the fact that io.swagger.v3.oas.models.OpenAPI objects and the gson library purposely used by this plugin both retain item order makes me believe this is an oversight.

Screenshots

JSON from plugin used in Swagger UI:

JSON from jar used in Swagger UI:

To Reproduce

  1. Add this gradle plugin to a springboot project
  2. Execute the generateOpenApiDocs task
  3. Execute the bootRun task
  4. Compare the JSON of the /v3/api-docs endpoint to the openapi.json file

Example

I've provided a very quick demo that shows this in action (json-demo.zip). This project contains a test which outputs the Open API JSON file generated by the springdoc-openapi-core jar to the build directory for comparison with the JSON file produced by the plugin.

Next Steps

I'm happy to create a PR for this if it's something you agree needs fixing.

It only requires a very minor fix which involves swapping response.jsonObject.toString to response.text at OpenApiGeneratorTask.kt#L87. This is because the jsonObject field intentionally does not preserve field order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions