openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

Fix #23933: Added @JsonPropertyOrder annotation to Spring Boot generator

Open thesauravpoddar opened this issue 5 months ago • 5 comments

This PR adds the @JsonPropertyOrder annotation to Spring Boot generator to fix the problem that Jackson 3 by default sorts properties alphabetically instead of following the logical order of the generated classes. It ensures that JSON properties are serialized in the logical order defined in the OpenAPI specification, while correctly excluding enum models from the class-level annotation. I addes proper import for @JsonPropertyOrder annotation.

Updated the POJO.mustache for spring boot with @JsonPropertyOrder annotation and updated the AbstractJavaCodegen with adding import statement of @JsonPropertyOrder annotation under method processOpts .

And updated the SpringCodegen class in which i updated the method postProcessModelProperty . Then finally adding test code for this in 'SpringCodegenTest.java' class

cc @Zomzog @martin-mfg @cachescrubber @welshm

PR checklist

  • [x ] Read the contribution guidelines.
  • [ x] Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL) Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • [ x] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Add @JsonPropertyOrder to generated Spring Boot models so JSON follows the OpenAPI field order instead of Jackson 3’s alphabetical sort. Enum models are excluded from the class-level annotation.

  • Bug Fixes

    • Added JsonPropertyOrder import mapping in AbstractJavaCodegen.
    • Updated Spring Boot pojo.mustache to apply @JsonPropertyOrder and emit JSON_PROPERTY_* constants.
    • Updated SpringCodegen to import JsonPropertyOrder for non-enum models only.
    • Added tests in SpringCodegenTest and regenerated Spring sample models.
  • Migration

    • Regenerate Spring Boot code to pick up ordered serialization. No code changes required.

Written for commit 465a7af1400428a6b68b93b951011c34818b4e1b. Summary will update on new commits.

Review in cubic

thesauravpoddar avatar Jun 05 '26 17:06 thesauravpoddar

HI! @Zomzo can you please look at the pull request

thesauravpoddar avatar Jun 11 '26 09:06 thesauravpoddar

thanks for the pr

please resolve the merge conflicts when you've time.

cc @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08)

wing328 avatar Jun 15 '26 01:06 wing328

@cubic-dev-ai ultrareview

thesauravpoddar avatar Jun 15 '26 03:06 thesauravpoddar

@cubic-dev-ai ultrareview

@thesauravpoddar Ultrareview is only available on the Pro plan. Upgrade here to get access.

cubic-dev-ai[bot] avatar Jun 15 '26 03:06 cubic-dev-ai[bot]

Can You please look at this PR whenever you get time.

cc @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08)

thesauravpoddar avatar Jun 23 '26 11:06 thesauravpoddar

Hey can you please look at this

thesauravpoddar avatar Jun 26 '26 17:06 thesauravpoddar

@wing328 can you please look at this

thesauravpoddar avatar Jun 26 '26 17:06 thesauravpoddar