Closed
Description
Using an annotation such as:
@ApiOperation(
value = "Operation",
notes = "Notes",
position = 2
)
and a custom ordering such as:
docket.apiDescriptionOrdering(new Ordering<ApiDescription>() {
@Override
public int compare(ApiDescription left, ApiDescription right) {
int leftPos = left.getOperations().size() == 1 ? left.getOperations().get(0).getPosition() : 0;
int rightPos = right.getOperations().size() == 1 ? right.getOperations().get(0).getPosition() : 0;
int position = Integer.compare(leftPos, rightPos);
if(position == 0) {
position = left.getPath().compareTo(right.getPath());
}
return position;
}
});
The scanner framework seems to read the documentation and sort it properly. When the data is extracted to the Swagger object at Swagger2Controller.java:74, the ordering seems to be lost.
Activity
dilipkrish commentedon May 8, 2015
Unfortunately that is because of the data structure that swagger-core uses. There is now way for us to fix that. You might want to try and open an issue in swagger-core
chadjaros commentedon May 8, 2015
A LinkedHashMap preserves insertion order when iterated. If you insert things in sorted order, they will stay that way when retrieved via iteration.
It looks like the offending code is here. It's certainly something that could be fixed by subclassing the Swagger object and getting rid of the extra sort.
I've opened this issue at swagger-core.
dilipkrish commentedon May 8, 2015
Thanks for digging deeper! :) Im closing this issue for now
chadjaros commentedon May 8, 2015
This means you will not address it at this time?
dilipkrish commentedon May 8, 2015
There is nothing for us to address here 😕
chadjaros commentedon May 8, 2015
If Docket#apiDescriptionOrdering and Docket#apiListingReferenceOrdering are non-functional, you may want to indicate that by either adding a javadoc comment (if you expect the issue to eventually be corrected) or deprecating them (if this is not a feature you will support).
dilipkrish commentedon May 8, 2015
Just to be clear, we have an internal model that totally works as expected and functional. The api descriptions and api operations will be sorted as expected from
springfox
's standpoint. We're only using the swagger models as DTOs to handle the serialization of our internal service models. Once the DTO's are fixed to preserve the ordering this problem will go away.We can certainly add a note to describe the problem and the cause to the
Readme
. Other than waiting for swagger core to fix this, there is nothing to do here other than that I'm afraid.Added a note in javadocs as to why sorting of api descriptions and li…
yiranlihao commentedon Jun 29, 2017
bro,why it does not work in version 2.7.0--the newest version?
yiranlihao commentedon Jun 29, 2017
anybody can check it for me?
dilipkrish commentedon Jul 4, 2017
The swagger-models do not display sorted versions. thats the problem.
abelsromero commentedon Jul 20, 2017
@yiranlihao not working, getPosition() just returns 0.
abelsromero commentedon Jul 20, 2017
Does this affect
apiListingReferenceOrdering
. Because I just implemented a custom method insideapiListingReferenceOrdering
and it gets invoked, but the results of the comparator seem to be ignored.15 remaining items