OpenAPI Generator and Custom MIME types

  Kiến thức lập trình

I’ve been down the rabbit hole on this, and extracted the templates for Spring, i.e., open-api-generator author template -g spring and combed though the mustache files.

What I’m trying to do is get OpenAPI to recognize application/vnd.api+json (JSON.api) as a superset of application/json in the generation of examples, instead of getting:

...
if (mediaType.isCompatibleWith(MediaType.valueOf("application/vnd.api+json"))) {
  String exampleString = "Custom MIME type example not yet supported: application/vnd.api+json";
  ApiUtil.setExampleResponse(request, "application/vnd.api+json", exampleString);
...

Where the exampleString is “Custom MIME type example not yet supported: application/vnd.api+json” but the OpenAPI Spec defines a JSON struture:

components:
  responses:
    Echo:
      description: Test operation for pipelines
      content:
        'application/vnd.api+json':
          schema:
            $ref: '#/components/schema/Echo'
          example:
            data:
              type: echo
              id: 17d39399-c08c-499f-9e2c-d8b6e467e6aa
              attributes:
                message: Echo cho ho o

This feels to me something that has been encountered and my Google-fu is failing me. When I use application/json the example is parsed as expected and used in the exampleString. This seems to me something to configure or provide to the templates as a “Hey, when you see application/vnd.api+json parse the example as application/json like you would normally.”

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT