Skip to content

springdoc.writer-with-order-by-keys could be more deterministic #1362

Closed
@ianwallen

Description

@ianwallen

Is your feature request related to a problem? Please describe.
The following option is not as deterministic as expected. (Not sure if this is bug or a feature request)
springdoc.writer-with-order-by-keys=true

Reversing function order of the methods can cause different documents to be generated so the results are not really deterministic. The order of the paths seems to remain ordered, but the other attributes inside are not. This makes it difficult to perform a comparison between two open api documents.

Describe the solution you'd like

  • I would like to see all the attributes orders the same way so that it makes a deterministic document that is easy to compare to an older version.

Describe alternatives you've considered

  • Maybe the documentation could be more clear that it is only ordering the "paths" or maybe remove deterministic from the documentation.
    Current documentation states Enable a deterministic/alphabetical ordering.

Additional context

  • To show the problem edit the following unit test.

public class HelloController {
@GetMapping("/testA")
public void testA(String hello) {
}
@GetMapping("/testB")
public void testB(String hello) {
}
}

And reverse the methods so that they look like the following

public class HelloController {

	@GetMapping("/testB")
	public void testB(String hello) {
	}

	@GetMapping("/testA")
	public void testA(String hello) {
	}
}

This will cause the unit test to fail with the following error.

Expected :{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost","description":"Generated server url"}],"paths":{"/testA":{"get":{"tags":["hello-controller"],"operationId":"testA","parameters":[{"name":"hello","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK"}}}},"/testB":{"get":{"tags":["hello-controller"],"operationId":"testB","parameters":[{"name":"hello","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK"}}}}},"components":{}}
Actual   :{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost","description":"Generated server url"}],"paths":{"/testA":{"get":{"operationId":"testA","parameters":[{"in":"query","name":"hello","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK"}},"tags":["hello-controller"]}},"/testB":{"get":{"operationId":"testB","parameters":[{"in":"query","name":"hello","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK"}},"tags":["hello-controller"]}}},"components":{}}

We can see that the Paths are in the correct order but the attributes such as "tags", "operationId" have changed order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions