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

refs #3613 - Configurable and deterministic order of JSON and YAML output #3740

Merged
merged 3 commits into from
Dec 3, 2020

Conversation

frantuma
Copy link
Member

@frantuma frantuma commented Dec 3, 2020

Includes and replaces #3613, provides a solution for related issues, including:

The solution covers two areas:

  1. deterministic input (reflection): methods and fields are sorted consistently, thanks @hiddewie!

  2. sorted serialization.

This is achieved in two possible ways:

A. specifying the newly introduced configuration option (and maven/gradle parameter) sortOutput, which applies an opinionated sorting , using Jackson ORDER_MAP_ENTRIES_BY_KEYS and SORT_PROPERTIES_ALPHABETICALLY along with defined order for serialization of OpenAPI root and Schema instances

B. fully customizing the ObjectMapper used in serialization of output, using the existing mechanism of the ObjectMapperProcessor which is now defining 2 more methods processOutputJsonObjectMapper and processOutputYamlObjectMapper to customize the "output mapper" (which is different from the one used while resolving, customizable with the existing method processJsonObjectMapper).

Please see tests for an example of usage.

As quick background, many alternatives have been proposed to obtain a deterministic output, including but not limited to usage of sorted Maps and Sets at the POJO level, hard-coding Jackson sort features, providing specific serializers etc. but all options would have affected the deserialization->serialization roundtrip not allowing to maintain the original order. Additionally the order of output fields is and should be opinionated, as the semantic meaning stays the same.

Related tickets will be closed referencing this PR, any further issues in this area should be reported in a new or not closed ticket.

@hiddewie
Copy link
Contributor

hiddewie commented Dec 4, 2020

Thank you @frantuma

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

Successfully merging this pull request may close these issues.

2 participants