question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SmallRye OpenAPI generates incorrect content type when using Spring Web annotations

See original GitHub issue

Bug 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:

  1. Use both extensions together:
    • quarkus-smallrye-openapi
    • quarkus-spring-web
  2. 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";
    }
}
  1. 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:closed
  • Created 3 years ago
  • Comments:18 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
jsmrckacommented, Mar 7, 2021

The aforementioned test scenario is passing now on master. 😃

1reaction
phillip-krugercommented, Mar 4, 2021

This is now fix in SmallRye. Once we have done a release and pull the new version into Quarkus this should be resolved.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found