Swagger-ui: How to Sort Paths in UI

Created on 27 Apr 2017  ·  13Comments  ·  Source: swagger-api/swagger-ui

When reporting an issue, please provide the following details:

  • swagger-ui version 3.0.7

In the past I was able to configure alphabetical sorting in SwaggerUI config:

        apisSorter: "alpha",
        operationsSorter: "alpha",

I don't see those options any longer. Is there a way to configure SwaggerUIBundle to sort the paths?

P2 lock-bot feature 3.x

Most helpful comment

These options were added this week and should be available in master. Will be released tomorrow.🤞

All 13 comments

These options were added this week and should be available in master. Will be released tomorrow.🤞

I checked the source code. I see the operationsSorter option is implemented, but it doesn't look like apisSorter is implemented yet. It's storing the operations in an unordered Map, then iterates over the map, producing an alphabetical ordering.

Sorry for the delayed updated, and unfortunately, it's not good news. I've just added https://github.com/swagger-api/swagger-ui/issues/2799#issuecomment-305033731, which applies here as well. If anyone wants to take a shot at it, we'd be happy to review the PR.

@webron does the bad news mean that even if we define the tags in the tags array, that there is no current way to guarantee that the endpoints will display in order?

@Way2nnadi Unfortunately, that's correct.

Update: tagsSorter (fka apisSorter) was implemented in #3303, but operationsSorter is still not implemented.

@Way2nnadi, to your point, tags should be displayed in the order they're defined, thanks to https://github.com/swagger-api/swagger-ui/pull/3324.

@shockey psst..... https://github.com/swagger-api/swagger-ui/blob/master/src/core/utils.js#L578... but don't tell anyone ;)

🤦‍♂️ operationsSorter is implemented as well.

Buy a feature, get one I forgot about for free!

Closing, since everything requested is implemented 😄

Is it possible to do custom sorting in swagger yaml spec with operationsSorter ?

Yes, you can pass a sorting function to it. It's in the README.

@webron thanks for the answer.
I saw about the function but I'm confused as to how to do it within the swagger spec ? Where would that function be defined (and not in this project scope but would swagger codegen also take the order in consideration)

Thanks

The order can't be defined in the spec, this is a swagger-ui functionality. You'd need to pass it as part of its configuration. This does not impact the codegen.

Was this page helpful?
0 / 5 - 0 ratings