3

I am trying to setup swagger for an existing Spring Boot API project. I have discovered that I have two endpoints that cause the http://url/swagger-ui.html file to not render. If I comment out these two endpoints then it does render correctly.

When the two endpoints exist, the http://url/v2/api-docs json file does render successfully. I can take the json from api-docs and paste it into https://editor.swagger.io/ and the html page renders correctly on that site.

The two endpoints that are causing the issue are on root path, and have only a path parameter in the url. They are each in a controller that has @RequestMapping("/") and they are annotated;

@PutMapping(value = "{vaultTitleId}", produces = MediaType.APPLICATION_JSON_VALUE)

@DeleteMapping(value = "{vaultTitleId}")

These two endpoints work correctly, they just are causing some issue with Swagger rendering the HTML. If I remove them, the HTML displays. I have tried moving them into a controller by themselves and seeing if I could prevent swagger from accessing them in the Swagger configuration. But, it seems they only have to exist somewhere where spring boot sees them to prevent the html from displaying.

Any advice is appreciated. I would like to use Swagger, but I am giving up on it for now, and looking at alternative tools.

Gradle

compile("io.springfox:springfox-swagger2:2.9.2")
compile("io.springfox:springfox-swagger-ui:2.9.2")

Swagger Config

@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors
            .basePackage("com.nextgearcapital.mt.controller"))
            .paths(PathSelectors.any())
            .build();
}
}

1 Answer 1

3

I discovered a work around. This was suggested in another forum.

https://github.com/springfox/springfox/issues/631

The problem is you're endpoints are consuming the endpoint mappings, you can create a regular expression that resolves it?

@DeleteMapping(value = "{vaultTitleId:^((?!swagger-ui.html).)*$}") Seems al lil clunky but not sure what the right answer is.

Using a request mapping with a regex to define the path parameter did allow the swagger-ui to display. It is not obvious to me why this works. I would call it more of a work around than an actual solution. But, this is what I am going to be using.

    @DeleteMapping(value = "{vaultTitleId:^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$}", produces = MediaType.APPLICATION_JSON_VALUE)
Sign up to request clarification or add additional context in comments.

1 Comment

github.com/springfox/springfox/issues/631 for anyone who wanted to simply click a link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.