SmallRye OpenAPI generates incorrect content type when using Spring Web annotations
See original GitHub issueBug description
quarkus-smallrye-openapi
extension does not generate correct content type based on Spring Web annotation provided by quarkus-spring-web
extension when generating OpenAPI schema (calling /q/openapi
endpoint).
Instead of picking up the content type specified by Spring annotation
@...Mapping(produces = <desired-content-type>)
it generates response content type application/json
.
The content type of the application endpoint response itself is correct and unaffected by this bug.
Expected output
openapi: 3.0.3
info:
title: Generated API
version: "1.0"
paths:
/greeting:
get:
responses:
"200":
description: OK
content:
text/plain:
schema:
type: string
Actual output
openapi: 3.0.3
info:
title: Generated API
version: "1.0"
paths:
/greeting:
get:
responses:
"200":
description: OK
content:
application/json:
schema:
type: string
To Reproduce
smallrye-openapi-spring-web-reproducer.zip
Steps to reproduce the behavior:
- Use both extensions together:
- quarkus-smallrye-openapi
- quarkus-spring-web
- Define endpoint using Spring annotations and specify response content type, e.g.
@RestController
@RequestMapping("/greeting")
public class GreetingController {
@GetMapping(produces = MediaType.TEXT_PLAIN_VALUE)
public String hello() {
return "Hello Spring";
}
}
- Call OpenAPI endpoint
/q/openapi
.
Environment (please complete the following information):
java -version
:
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
- GraalVM version: 20.3.1
- Quarkus version: 1.12.0.Final
- Build tool: Apache Maven 3.6.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (17 by maintainers)
Top Results From Across the Web
Using OpenAPI and Swagger UI - Quarkus
In this guide, we create a straightforward REST application to demonstrate how fast you can expose your API specification and benefit from a...
Read more >RHBA-2021:2549 - Bug Fix Advisory - Red Hat Customer Portal
... with latest version of RH SSO 7.4; QUARKUS-849 - SmallRye OpenAPI generates incorrect content type when using Spring Web annotations ...
Read more >Spring Boot: Wrong content-type when using @GetMapping ...
I'd guess that otherwise Spring is just using the first one in your produces list. (Which you can test by reordering it.).
Read more >Documenting RESTful APIs using MicroProfile OpenAPI
You can generate an OpenAPI document in various ways. First, because all Jakarta Restful Web Services annotations are processed by default, you can...
Read more >Media Types - Swagger
If you use OpenAPI 2.0, see the OpenAPI 2.0 guide. Media Types. Media type is a format of a request or response body...
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 Free
Top 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
The aforementioned test scenario is passing now on master. 😃
This is now fix in SmallRye. Once we have done a release and pull the new version into Quarkus this should be resolved.