OpenAPITools / OpenAPITools/openapi-generator

[REQ] [Java] Preserve the order of model properties by generating @ApiModelProperty.position value

Open
#6,005 2 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

For Java-based generators, @ApiModelProperty has a position property that can be used for implementors to sort model properties, like what has been done in Springfox Swagger2.

Without the position property value generated for the Java accessor method, the only reliable way to ensure the property order constant from run to run is to sort the properties by its name due to the limitation of Class.getDeclaredMethods(). And this behavior may results inconsistent to the OAI definition.

Describe the solution you'd like

Add config option like preserveModelPropertiesOrder to all generators which generating Swagger Annotation. For best compatibility, the default of this property should be false.

However, there exist sortModelPropertiesByRequiredFlag option may inference with this proposed option.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Java-based generators that produce Swagger annotations and the existing sortModelPropertiesByRequiredFlag option. Compare the requested preserveModelPropertiesOrder behavior with the Springfox example and determine how the two options should interact. Done means the option is consistently supported by the relevant generators and generated model properties receive the expected positions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.