More then one content type of response
See original GitHub issueQ | 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:
- Created 6 years ago
- Reactions:8
- Comments:9 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
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
Is there at least a suggested path forward while this is not supported? For cases where there are multiple resources (e.g.
getAsJSON
andgetAsCSV
), 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.
Any update on this? It seems that API accept header versioning is not possible with Swagger at the moment?