Reputation: 1650
I am new to Swagger.io and so also to Spring fox. The problem I am having is, that for some Reason one Object is not correctly referenced to its model.
The error is because it ends up like this in the JSON:
"schema": {
"$ref": "#/definitions/Error-ModelName{namespace='online.staffmanager.backend.auth.model.dto', name='UserChangeSet'}"
}
if I change it to:
"schema": {
"$ref": "#/definitions/UserChangeSet"
}
it does work. And I have no Idea why the anotations are mapping it like this.
My Annotations:
@Operation(
tags = "auth",
summary = "Create a new User Account",
responses = {
@ApiResponse(
responseCode = "200",
content = @Content(schema = @Schema(implementation = TokenInfo.class))),
@ApiResponse(
responseCode = "201",
content = @Content(schema = @Schema(implementation = UserChangeSet.class)))
}
)
SpringFoxConfig:
@Configuration
@EnableSwagger2
@EnableWebMvc
public class SpringFoxConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Note: I am using Springfox 3.0.0. Thanks in advance!
Upvotes: 6
Views: 12486
Reputation: 5460
In my case using Generic types got solution:
@PutMapping(path = "/home")
public ResponseEntity<Void>(....)
TO
@PutMapping(path = "/home")
public ResponseEntity (....)
Upvotes: 0
Reputation: 511
you have to add one more configuration to the Bean.
Here is the configuration need to be added:
.additionalModels(
typeResolver.resolve(TokenInfo.class),
typeResolver.resolve(UserChangeSet.class)
)
This is full code:
@Configuration
@Import(SpringDataRestConfiguration.class)
public class SwaggerUIConfig {
@Bean
public Docket api(TypeResolver typeResolver) {
return new Docket(DocumentationType.SWAGGER_2)
.additionalModels(
typeResolver.resolve(TokenInfo.class),
typeResolver.resolve(UserChangeSet.class)
)
.select()
.apis(RequestHandlerSelectors.basePackage("com.projectname.controllers"))
.paths(PathSelectors.any())
.build()
.useDefaultResponseMessages(false);
}
}
Note: @EnableSwagger2 annotation is recommended to remove in version 3.0. You can refer http://springfox.github.io/springfox/docs/current/#migrating-from-existing-2-x-version
I hope can help you.
Upvotes: 10