stoicflame / enunciate-openapi

OpenAPI3 module for Enunciate
Apache License 2.0
10 stars 10 forks source link

@Consumes and @Produces do not support multiple media type entries #30

Closed bkratz closed 4 years ago

bkratz commented 4 years ago

Given following Resource code with @Produces having multiple media type entries:

@ResourceGroup("Resource group text")
@Path("/path/{pathArg}")
public class DataResource {
    @GET
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @StatusCodes({
            @ResponseCode(code = 200, condition = "OK", type=@TypeHint(DataDTO.class)),
            @ResponseCode(code = 400, condition = "Bad request")
    })
    public Response get(@PathParam("pathArg") String pathArg) {
        return Response.ok(new DataDTO()).build();
    }
}

the generated openapi.yaml is expected to be:

openapi: 3.0.0
...
      responses:
        "200":
          description: "OK"
          content:
            "application/json":
              schema:
                $ref: "#/components/schemas/json_DataDTO"
            "application/xml":
              schema:
                $ref: "#/components/schemas/xml_ns0_dataDTO"
        "400":
          description: "Bad request"

components:
...

but is currently:

openapi: 3.0.0
...
      responses:
        "200":
          description: "OK"
          content:
            "application/json":
              schema:
                $ref: "#/components/schemas/json_DataDTO"
        "400":
          description: "Bad request"

components:
...

The same issue applies to @Consumes containing multiple media type entries.

I have already analysed the problem. It seems that the generator selects the "best" high quality media type and ignores the others. This does not conform with the idea of openAPI because openAPI does not have the concept of weighing media types.

I will prepare a PR for this issue.

jskov-jyskebank-dk commented 4 years ago

Nice!

bkratz commented 4 years ago

Would be cool, if you could accept this PR #31 and release a new version of this module. Thx.

jskov-jyskebank-dk commented 4 years ago

https://github.com/Jyskebank/enunciate-openapi/releases/tag/1.1.5 And https://repo1.maven.org/maven2/dk/jyskebank/tooling/enunciate/enunciate-openapi/1.1.5/

Maven Central index is not updated yet, but you should be able to pull the artifacts.