ajaishankar / openapi-typescript-fetch

A typed fetch client for openapi-typescript
MIT License
233 stars 54 forks source link

Fix OpResponseTypes to support negotiated content types #34

Closed rolandzwaga closed 2 years ago

rolandzwaga commented 2 years ago

OpenAPI spec supports content negotiation, in my use case we use this to support API versioning.

So, our spec results in a generated schema type such as this:

    "200-items": {
      content: {
        "application/items.v1+json": {
          items?: components["schemas"]["items"][];
        };
      };
    };

In the current typings for openapi-typescript-fetch a hard-coded 'application/json' string is used to infer the response types. Which breaks in the case of our schema...

This PR adds a templated literal to accommodate for situations where something other than 'application/json' is used, while remaining backwards compatible.