Skip to content

[JAVA] isJsonMime should support vendor specific JSON MIME type #5172

@davidharrigan

Description

@davidharrigan
Description

We support APIs that return JSON encoded responses with vendor specific mime types. These MIME types look something like:

application/vnd.company+json

Which is a valid MIME-type. A response with the above mime-type as its content-type indicates that the response is JSON encoded. When the swagger-client attempts to deserialize such response, it throws an exception due to a method responsible for determining whether the given MIME is a JSON MIME. The method is isJsonMime and it checks whether the mime type matches the following regex:

(?i)application\\/json(;.*)?

This results in the following error:

Content type "application/vnd.company+json" is not supported for type: class com.somemodel Model

Not tested, but I think the above regex should be updated to something like:

(?i)application\\/((\w\.)*\w\+)?json(;.*)?"

so that MIME types like application/vnd.company+json are recognized as a valid JSON MIME.

I think it would be valid to have some additional tests here
that checks for MIME types such as the one mentioned above.

Swagger-codegen version

v2.2.1

Swagger declaration file content or url

N/A

Command line used for generation
java -jar /opt/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i /mnt/swagger.yaml -l java -o /mnt/clients/java -c /mnt/clients/configs/java.json
Steps to reproduce
  • Generate a client for some API
  • Have the API return a vendor JSON MIME type as the content header
  • use the client to retrieve from the endpoint which produces a vendor JSON MIME type
  • watch it scream
Related issues

This is a simpler fix, but I believe #3870 is related.

Suggest a Fix

Mentioned in the description.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions