question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sorting/Ordering on method (POST, GET, UPDATE, DELETE)

See original GitHub issue

Describe the bug I want to sort the endpoints/Method by methods. While having groups and tags.

Steps to reproduce I used Endpoints with tags. I have grouped API endpoints like these:

@Bean
    public GroupedOpenApi internalApi() {
        return GroupedOpenApi.builder()
                .setGroup("internal")
                .packagesToScan(CatalogController.class.getPackageName())
                .build();
    }

And I used the OpenApiCustomiser like this:

@Bean
    public OpenApiCustomiser sort() {
        //WE DON'T UNDERSTAND WHERE 'openApi' IS COMMNG FROM - not debugable....
        return openApi -> openApi.setPaths(
                (Paths) openApi.getPaths().entrySet()
                        .stream()
                        .sorted(Comparator.comparingInt(pathItem -> {
                            if (pathItem.getValue().getGet() != null) {
                                return 1;
                            }
                            return 0;
                        }))
                        .collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (x, y) -> y, LinkedHashMap::new))
        );
    }

Expected behavior Sorting should be debugable and working.

Additional context Would be nice to add these sorting like by Tag/Method,… to the already existing properties next to alphabetic sorting. Also would be great to solve ordering with an annotation…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
bnasslahsencommented, Dec 15, 2020

@YunaBraska,

Have you looked at the documentation?

You can use the swagger-ui properties, without having to override the standard way of sorting (operationsSorter and tagsSorter).

For example:

springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tagsSorter=alpha

Additionnaly, your sample code is not complete, as your GroupedOpenApi doesn’t not reference your OpenApiCustomiser. You should use OpenApiCustomiser, only if you really have some custom ways that are not handled in the standard swagger-ui properties.

You should have something like on your GroupedOpenApi:

@Bean
    public GroupedOpenApi internalApi() {
        return GroupedOpenApi.builder()
                .setGroup("internal")
                .packagesToScan(CatalogController.class.getPackageName())
                .addOpenApiCustomiser(sort())
                .build();
    }

0reactions
milindraocommented, Aug 20, 2020

I’m running into the same problem (v1.4.3). This is making documenting the differences after a change very hard.

I made no changes to the configuration. Just to the code and this was always in the application.properties file springdoc.swagger-ui.operationsSorter=method

The order of the endpoints used to be GET, PATCH, POST. For some reason now, it’s POST, GET, PATCH.

In addition to the endpoints itself, even some (though not all) attribute order has changed. Not sure what I need to do to fix that. springdoc.swagger-ui.tagsSorter=alpha?

I don’t know if this worked by fluke previously. Since I only changed the model classes, I don’t see how what could have triggered this change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using HTTP Methods for RESTful Services - REST API Tutorial
Click on a tab for more information about the desired HTTP method. POST; GET; PUT; PATCH; DELETE. The POST verb is most-often utilized...
Read more >
Does order matter in REST api express, ie. get -> post -> put
No. Order matters only when two routes would handle both the same path and the same method. So, since app.post() and app.
Read more >
REST API Design: Filtering, Sorting, and Pagination - Moesif
Advanced REST API design guidelines for API filtering, sorting, and pagination.
Read more >
Most Common HTTP Request Methods — POST, GET, PUT ...
POST, GET, PUT, PATCH, and DELETE are the most-commonly-used HTTP verbs. ... In sort, the POST method is used to insert new items...
Read more >
HTTP methods - Omnisend API
GET – request used to retrieve data. Never used to delete, update or insert data. · POST – request used to insert data....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found