(global) Response mappings

Global response mapping will replace the result type of the endpoint in the api description based on its content type to the given java type.

It is defined like below, and it should be added to the map/responses section in the mapping.yaml which is a list of global response mappings.

A single global response mapping can have the following properties:

 - content: {content type}  =>  {target type}
   generics:
     - {a generic type}
     - {another generic type}
  • content is required.

    • {content type} is the name of the content type of the endpoint response that should be replaced by {target type}.

    • {target type} is the fully qualified class name of the java type that should be used for all endpoint content types {content type}.

  • generics defines the list of types that should be used as generic type parameters to the java type given by {target type}.

Since the processor will simply match the content type string take care that all responses of this content type should really use the same type!

This is probably only useful for a vendor content types. Globally mapping the content type for example of application/json does not look like a good idea.

Example

Given the following (global) response mapping

map:

  # list of global response mappings, mapped by content type
  responses:
    - content: application/vnd.something => io.openapiprocessor.Something

and an openapi.yaml with multiple endpoints returning their result as content type application/vnd.something

openapi: 3.0.2
info:
  title: global response content type mapping example
  version: 1.0.0

paths:
  /do-something:
    get:
      responses:
        '200':
          description: response
          content:
            application/vnd.something:
              schema:
                type: string

  /do-something-else:
    get:
      responses:
        '200':
          description: response
          content:
            application/vnd.something:
              schema:
                type: string

the processor will use io.openapiprocessor.Something as java type for all responses with the content type application/vnd.something.