Skip to content

OpenAPI 3 / 3.1 handling of binary content #550

@PaulStryck

Description

@PaulStryck

Description

OpenAPI 3 has dropped the file type. It looks like this is not reflected here.

When using type: file in a schema:

"content": {
  "application/zip":  {
    "schema": {
      "type": "file"
    }
  }
}

the corresponding typescript type is created as (Blob | File). Which is the expected behaviour for OpenApi v2 but the above is not a valid OpenAPI 3 / 3.1 spec as the type: file is not supported anymore.

In OpenAPI 3:

Content transferred in binary (octet-stream) MAY omit schema

"content": {
  "application/zip":  {}
}

Or use type: string with contentEncoding keyword.

"content": {
  "application/zip":  {
    "schema": {
      "type": "string",
      "contentEncoding": "base64"
    }
  }
}

However, this will generate typescript types of either unknown or string.

OpenAPI specification (optional)

{
  "openapi": "3.1.0",
  "paths": {
    "/foo": {
      "get": {
        "responses": {
          200: {
            "content": {
              "image/png":  {
                "schema": {
                  "type": "string",
                  "contentMediaType": "image/png",
                  "contentEncoding": "base64"
                }
              }
            }
          }
        }
      }
    }
    "/bar": {
      "get": {
        "responses": {
          200: {
            "content": {
              "application/zip":  {}
            }
          }
        }
      }
    }
  }
}

Configuration

No response

System information (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Broken or incorrect behavior.important 📌This issue is important and will be addressed when capacity allows.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions