0

I have a SpringBoot application for which I have created a Swagger implementation. However, the new OpenAPI 3.0 specification brings a default section containing plenty of unnecessary endpoints / metadata. I could not find a solution yet to removing this default section containing all these endpoints that have been unnecessary added by default to my Swagger implementation of my REST API framework. Has anyone been confronted with such issue ?

Where are these endpoints coming from ? How can they be removed ?

Default Section in Swagger printscreen

@RequestMapping("/addresses")
@RestController
@PermitAll
@Tag(name="Addresses",description="Addresses API")
public class AddressRest {

    @Autowired
    private AddressesService addressService;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<AddressDTO> findAll() {
        return this.addressService.findAll();
    }

application.yml file looks as below. I tried to use the paths-to-exclude property but it does not seem to work. What am I missing ?

springdoc:
  swagger-ui:
    path: /swagger-ui.html
    query-config-enabled: true
  api-docs:
    path: /api/openapi.json
    enabled: false
  paths-to-exclude:
    - /api/healthcheck

build.gradle file containing the following dependecies:

implementation 'org.springdoc:springdoc-openapi-ui:1.6.12'
implementation 'io.swagger.core.v3:swagger-jaxrs2:2.2.6'
Helen
  • 87,344
  • 17
  • 243
  • 314

1 Answers1

0

I am not sure if this is still the defacto standart, but you can exclude specific endpoints from the Swagger documentation with the Docket configuration in your OpenApiConfig class (or whichever class you're using to configure Swagger). I found this in an older project of mine (and modified the path for your case):

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(Predicates.not(PathSelectors.regex("/api/.*")))
        .build();
}

This regex with the Predicates.not will exclude all endpoints that match /api/.*.

But I want to emphasize, that this was done with a lot older version and I am not sure if this still works. Let me know in the comments!

lapadets
  • 1,067
  • 10
  • 38
  • The main problem is that the config class described above will not work with the OpenApi 3.0 spec. The Docket class comes from a library not compatible with Swagger 3.0. Thanks for your feedback nonetheless – zweibit01101 Jan 17 '23 at 12:31