-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Deterministic and alphabetical orderding of JSON and YAML output #3613
Conversation
please build |
I've also been looking into deterministic serialization of the OpenAPI spec and I believe the above changes might not be enough. Individual classes (such as My current workaround is to acquire Swagger's object mapper and set property ordering for these specific classes:
|
@swarth100 That also seems like a good (additional) solution. Could you make a test case with a specification which fails on non-determinism for this PR? |
modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java
Outdated
Show resolved
Hide resolved
Hello, I am looking forward to see an updated on this. This feature will really help us because we need a test where the current OpenApi file is compared to a reference file to see if there are any differences (this way we avoid unwanted mistakes in the API) |
included and replaced by #3740, see PR comment for details and usage scenarios |
References:
Problem
When using the Swagger library to generate OpenAPI specifications from source code, the output should be fully deterministic. Running the tool on the same source code should always give the same result. This is not the case at the moment.
Because the output is non-deterministic, the contents will change after running the tool again. This causes problems when the output is committed to a version control system such as Git. Even when not changing the input, a huge diff may be generated because the content of the file has changed.
This PR
This PR contains two parts:
Map
s, specifically unorderedMap
s. This causes problems because the insertion order is ususally the iteration order. This problem has been solved by having the Object mapper (Jackson) sort the output properties.