Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent JSON ordering compared to springdoc-openapi #45

Closed
turnerdaniel opened this issue Apr 6, 2021 · 1 comment
Closed

Inconsistent JSON ordering compared to springdoc-openapi #45

turnerdaniel opened this issue Apr 6, 2021 · 1 comment

Comments

@turnerdaniel
Copy link

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.

@bnasslahsen
Copy link
Contributor

Thank you @turnerdaniel for your proposal.
You could have proposed directly your PR !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants