ApiResponse.examples not showing in swagger ui
See original GitHub issueVersion: springfox 2.9.2, springboot 2.0.2
What kind of issue is this?: Question.
Lang: Kotlin
Examples from ApiResponse annotations are not propagated to swagger-ui. See following code:
ApiResponse(code = 200, message = "Resource created", response = String::class,
examples = Example(value = [ExampleProperty(value = "Example text")])
)
After spring-boot start swagger-ui present example text of response 200 as “string”. So my question is whether i am missing something or it is bug. Because my expectations were, that example text will be “Example text”. For more detailed info see used config and rest controller.
Thx for answering, V
Used config
@Configuration
@EnableSwagger2
class SwaggerConfig(@Value("\${build.version}") private val buildVersion: String) {
@Bean
fun api(): Docket {
val res404 = ResponseMessageBuilder()
.code(404)
.message("Not found")
.build()
return Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("^/(?!error|probe).*"))
.build()
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, listOf(res404))
.globalResponseMessage(RequestMethod.PUT, listOf(res404))
.globalResponseMessage(RequestMethod.POST, listOf(res404))
.globalResponseMessage(RequestMethod.PATCH, listOf(res404))
.apiInfo(apiInfo)
}
@Bean
fun uiConfig(): UiConfiguration {
return UiConfigurationBuilder.builder()
.deepLinking(true)
.displayOperationId(false)
.defaultModelsExpandDepth(5)
.defaultModelExpandDepth(1)
.defaultModelRendering(ModelRendering.EXAMPLE)
.displayRequestDuration(false)
.docExpansion(DocExpansion.FULL)
.filter(false)
.maxDisplayedTags(null)
.operationsSorter(OperationsSorter.ALPHA)
.showExtensions(false)
.tagsSorter(TagsSorter.ALPHA)
.supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
.validatorUrl(null)
.build()
}
}
RestController:
@RestController
@RequestMapping(
path = ["/path/bla"],
consumes = [MediaType.APPLICATION_JSON_UTF8_VALUE, MediaType.APPLICATION_JSON_VALUE],
produces = [MediaType.APPLICATION_JSON_UTF8_VALUE, MediaType.APPLICATION_JSON_VALUE]
)
class MyController {
@ApiOperation(value = "some opeation")
@ApiResponses(value = [
ApiResponse(code = 200, message = "Resource created", response = String::class,
examples = Example(value = [ExampleProperty(value = "Example text")])
)
])
fun performAction(): String {
....
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:29 (8 by maintainers)
Top Results From Across the Web
Swagger examples are not shown on UI - Stack Overflow
I couldn't find much in swagger2, but upgraded to openapi, where this can be achieved by using @io.swagger.v3.oas.annotations.parameters.
Read more >Describing Responses - Swagger
A response is defined by its HTTP status code and the data returned in the response body and/or headers. Here is a minimal...
Read more >Set List of Objects in Swagger API Response - Baeldung
First, we'll start with some explanations of the OpenAPI Specification and Swagger API Response. Then, we'll implement a simple example using ...
Read more >F.A.Q - Springdoc-openapi
https://github.com/swagger-api/swagger-samples/tree/2.0/java/java-jersey2- ... If you need the definitions to appear globally (within every group), no ...
Read more >Java – Swagger UI not showing example value and model
Java – Swagger UI not showing example value and model. javaopenapispring-bootspringfoxswagger. I was generating Swagger API specification from Spring Boot ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
I am facing the same issue ApiResponse.examples not showing in swagger ui. May i know when this feature will be available.
Same problem here. Springfox 2.9.2, Kotlin 1.2.51, SpringBoot 2.0.3.RELEASE.
examples
parameter ignored in@ApiResponse
.