cancel
Showing results for 
Search instead for 
Did you mean: 

Swagger (Springfox) only finding Models used in Controller @RequestBody (Spring Boot)

SOLVED
New Contributor

Swagger (Springfox) only finding Models used in Controller @RequestBody (Spring Boot)

Basically, I'm interested whether it's intended that the only models Swagger shows in swagger-ui are models used in RestController methods. It detects both my DTOs that I filled with @RequestBody, but it does not detect the User model, even with the ApiModel annotation. How to I go around this without making a dummy controller method?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Staff

Re: Swagger (Springfox) only finding Models used in Controller @RequestBody (Spring Boot)

yea, seems this is an issue related to springfox instead swagger-codegen or swagger-ui

View solution in original post

3 REPLIES 3
Highlighted
Staff

Re: Swagger (Springfox) only finding Models used in Controller @RequestBody (Spring Boot)

Hi,

 

No sure what you mean but, swagger-ui will show models placed at `components/schema` section inside an OpenAPI definition. Inline schemas/models wont be listed in models sections.

Highlighted
New Contributor

Re: Swagger (Springfox) only finding Models used in Controller @RequestBody (Spring Boot)

Well, what I mean is that I'm trying to use Springfox' implementation in my Spring Boot REST API for documentation and testing in java, and that the only Models autodetected by Swagger are the ones used as parameters in the Controller methods.

For example:

@PostMapping("/signin")
    @ApiOperation
    public String login(
            @ApiParam(value = "The login credentials DTO (username and password)", required = true) 
@RequestBody
@Valid LoginCredentialsDTO loginCredentialsDTO) { return userService.login(loginCredentialsDTO);

It detects the Model "LoginCredentialsDTO" because it was used here in the controller method.

 

Since I only use DTOs in my controller, it's not detecting my main model (User). I don't want to have to make a dummy method just for Swagger to be able to detect all my models.

 

It's possible that I should ask the Springfox community (if there is one) about this instead, my mistake if I asked the wrong people.

Highlighted
Staff

Re: Swagger (Springfox) only finding Models used in Controller @RequestBody (Spring Boot)

yea, seems this is an issue related to springfox instead swagger-codegen or swagger-ui

View solution in original post