python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.14k stars 333 forks source link

Is there a way to sort in the automated documentation? #604

Open macnewbold opened 4 months ago

macnewbold commented 4 months ago

I'm hoping I'm just missing something, but as our project grows, we're trying to keep the documentation as easy to use as we can. One way we do this is by sorting our ~20 namespaces alphabetically as we load them, so that they come out in the same order they were loaded. While it would be nice if this was automatic, it's workable.

We have an issue though with our 40+ models, whose names alone scroll across several screenfuls in the docs in the browser. They are listed in the order they were added, which means whatever models are used in the early methods of the earliest loaded namespaces show up first. Rather than having models load into the documentation in the order they were used/added as we processed all the methods, we would love to have a way to sort the models alphabetically. Or failing that, listing each model's namespace with it would help it make more sense regarding where to find stuff without resorting to text searches in the browser.

Some other implementations of swagger-related documentation like this seem to support a "sorter" method that can be provided to determine the sort order that is desired in the output.

Thanks to all the contributors and maintainers for the great project!

macnewbold commented 4 months ago

If it helps any, I did find this great article about a way to automatically sort namespaces by subclassing the API:

https://obikastanya.medium.com/flask-restx-plus-sort-namespace-in-swagger-a5e3c8fab08a

If there were something similar to this for both namespaces and models, it would work great I think.

Another option that I'm very open to is having the sorting be a display thing when the docs are generated, and not worrying about any internal sorting in the core. The order really only matters when you display it to a user I think, so a display-level solution would work fine, if it includes the web-based docs and the swagger json output.