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.

More then one content type of response

See original GitHub issue
Q A
Bug or feature request? Bug
Which Swagger-Core version? 2.0.0-rc1
Which Java version? Java-8
Which JAX-RS framework & version? Jackson 2.9.1, Jersey 2.25.1

Hi,

I have an endpoint like above and I want to have more than one content type of response. As I see in the openAPI specification it is possible but using annotation I can’n generate it.

@POST
    @Operation(summary = "Create multilevel query execution", responses = {
            @ApiResponse(responseCode = "200",
                    content = @Content(mediaType = "application/multiLevel+json", 
                            schema = @Schema(implementation = MultiLevelResult.class))),
            @ApiResponse(responseCode = "200",
                    content = @Content(mediaType = "application/flat+json",
                            schema = @Schema(implementation = FlatResult.class))),
            @ApiResponse(responseCode = "500", description = "An unexpected error has occurred. Error code is unexpected.error")})
    @Consumes({"application/execution.multiLevelQuery+json"})
    @Produces({"application/flat+json", "application/multiLevel+json"})

As result of the generation, I get only one content type.

"paths" : {
    "/queryExecutions" : {
      "post" : {
        "summary" : "Create multilevel query execution",
        "operationId" : "executeQuery",
        "parameters" : [ {
          "schema" : {
            "$ref" : "#/components/schemas/ClientMultiLevelQueryExecution"
          }
        } ],
        "responses" : {
          "200" : {
            "content" : {
              "application/flatData+json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/ClientFlatQueryResultData"
                }
              }
            }
          },
          "500" : {
            "description" : "An unexpected error has occurred. Error code is unexpected.error"
          }
        }
      }
    }
  }

Does it not implemented yet?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:8
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
jameslaneconklingcommented, Jul 25, 2019

Is there at least a suggested path forward while this is not supported? For cases where there are multiple resources (e.g. getAsJSON and getAsCSV), I had thought it would work to decorate one with multiple @Content annotations for each mime type, and leave the other unannotated. However, it looks like the order in which each resource is parsed is non-deterministic, so if the annotated resource is evaluated second, the correct docs are produced, but if the unannotated resource is evaluated second, it overwrites the annotated resource and the docs are lost.

I’m fishing around for the least hacky way to solve this, given that there doesn’t seem much interest in supporting the use case. Is there a way to ignore a resource method? The only way I can think of doing this is to put annotated resources in a different package from unannotated ones.

4reactions
flo-ryancommented, Mar 29, 2019

Any update on this? It seems that API accept header versioning is not possible with Swagger at the moment?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does the HTTP Protocol support multiple content types in ...
No. As pointed out in the accepted answer, the header value itself does not allow for multiple values, and ...
Read more >
Content-Type - HTTP - MDN Web Docs - Mozilla
In responses, a Content-Type header provides the client with the actual content type of the returned content.
Read more >
REST API: Setting of multiple content types in request header ...
I have updated the REST API for multiple content-type is set in header and then return appropriate result in response.
Read more >
Multiple content types specified - PortSwigger
If a response specifies multiple incompatible content types, then the browser will usually analyze the response and attempt to determine the actual MIME ......
Read more >
Single vs Multiple Content Types (Website Examples)
Irrespective of the type of content type (“Webpage” or “Content Block”) you are creating, you should mark it as either Single or Multiple....
Read more >

github_iconTop Related Medium Post

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