Skip to content

Objects properties order is not preserved with springdoc.api-docs.resolve-schema-properties = true #1274

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

Closed
jawpio opened this issue Sep 22, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@jawpio
Copy link

jawpio commented Sep 22, 2021

For some projects the object properties order is not preservered in the schema.

I checked the sample-springdoc-openapi-person-service if I change the Person properties order it's reflected in the swagger specification.

I created a minimalistic project which shows that the properties order is not preserved https://github.com/jawpio/springdoc-property-ordering-test.

In above project you can see that the SampleResponseClass looks as follows:

public class SampleResponseClass {

	private String id;

	private String name;

	private String lastName;

	private boolean aValue;

but it's generated as:

      "SampleResponseClass": {
        "type": "object",
        "properties": {
          "lastName": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "isaValue": {
            "type": "boolean"
          }
        }
      }

I tired to find what's causing that issue, but I was unable to find the reason yet.

@jawpio jawpio changed the title Question: Preserve properties order Objects properties order is not preserved Sep 24, 2021
@jawpio
Copy link
Author

jawpio commented Sep 27, 2021

I found the what's causing above problem, setting the property:
springdoc.api-docs.resolve-schema-properties = true

has that side effect.

@bnasslahsen
Copy link
Collaborator

@jawpio,

There is no such expected order.
If you want a deterministic/alphabetical order, use springdoc.writer-with-order-by-keys= true as described in the documentation.

@jawpio
Copy link
Author

jawpio commented Oct 5, 2021

Thanks @bnasslahsen for answer, but I think the issue should be still opened.

The springdoc.writer-with-order-by-keys=true setting orders properties alphabetically which is not something we want to achieve, we'd like to keep/preserve properties order from the java model.

Please note that, with default springdoc/swagger configuration properties order is(and should be) preserved! Check all examples etc.!

The problem starts when you set the springdoc.api-docs.resolve-schema-properties to true, than the properties order is not preserved. Due to the fact it's the springdoc.api-docs.* configuration which is causing the issue I think the problem is somewhere in springdoc.

IMO properties order is important aspect in documentation description, you don't want to put items which are less relevant on the top of the object description.
Other thing is that when you describe the XML responses, quite often you'd like to keep XSD schema compatibility for legacy projects, and please note that <xsd:sequence> from XSD schema enforces the properties order.

@bnasslahsen
Copy link
Collaborator

@jawpio,

Make sure you Provide a Minimal, Reproducible Example - with HelloController that reproduces the problem which proves your affirmation.

This ticket can be reopened, if the relevant information are provided.

@jawpio
Copy link
Author

jawpio commented Oct 5, 2021

@bnasslahsen Thanks for quick answer!

Please check this project https://github.com/jawpio/springdoc-property-ordering-test I think it's as minimalistic as possible, and please check the ReadMe to reproduce the issue.

@bnasslahsen bnasslahsen reopened this Oct 5, 2021
@bnasslahsen bnasslahsen changed the title Objects properties order is not preserved Objects properties order is not preserved with springdoc.api-docs.resolve-schema-properties = true Oct 8, 2021
@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
mpleine pushed a commit to mpleine/springdoc-openapi that referenced this issue May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants