-1

I am using swagger 2.9.2 version and i want to display endpoints like Get, Post, Put, Patch, Delete. I referred this post Swagger API Operations Ordering which is must similar to my requirement and it working in ascending order but I want to display endpoint as mentioned above order.

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors
                        .basePackage("com.xxx.xxx.controller"))
                .paths(PathSelectors.any()).build()
                .useDefaultResponseMessages(false)
                .apiInfo(metaData());
    }   
    private ApiInfo metaData() {
        return new ApiInfoBuilder()
                .title("test data")
                .description("test data")
                .version("1.0.0")
                .build();
    }   
    @Bean
    UiConfiguration uiConfig() {
        return UiConfigurationBuilder
                .builder()
                .operationsSorter(OperationsSorter.METHOD)
                .build();
    }
}
Nizamuddin
  • 149
  • 1
  • 2
  • 16

1 Answers1

0

What should work is something like this:

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            ...
            .build()
            .operationOrdering(new Ordering<Operation>() {
                @Override
                public int compare(final Operation left, final Operation right) {
                    // Here you have all the information about the operations, 
                    // such as left.getMethod(), right.getMethod()
                    // and you may implement the sorting on your own.
                    // Return +1, 0 or -1 based on the expected order.
                }
            });
}

However, based on the link you provided https://stackoverflow.com/a/52760718/2886891 there might still be a bug:

However, this does not work because of a bug in Springfox which seems to be still active (Operation ordering is not working).

Honza Zidek
  • 9,204
  • 4
  • 72
  • 118
  • Honza Zidek Thanks for reply, I tried given example but it is not working with me. – Nizamuddin Jan 07 '19 at 15:31
  • Create a MCVE (https://stackoverflow.com/help/mcve) and if you are sure it is still an error, post it at https://github.com/springfox/springfox/issues. – Honza Zidek Jan 07 '19 at 15:40