Skip to content

Map string schemas with a binary contentMediaType to Blob - #411

Open
ewerton336 wants to merge 2 commits into
cyclosproject:masterfrom
ewerton336:fix/403-content-media-type-blob
Open

ewerton336 wants to merge 2 commits into
cyclosproject:masterfrom
ewerton336:fix/403-content-media-type-blob

Conversation

@ewerton336

Copy link
Copy Markdown

Fixes #403

OpenAPI 3.1 describes raw file content with contentMediaType (e.g. application/octet-stream) instead of format: binary. FastAPI with Pydantic v2 emits upload fields this way, so they were generated as string instead of Blob.

Changes:

  • Added isBinarySchema() in gen-utils.ts. A schema is binary when it has format: binary (unchanged), or a contentMediaType that isn't textual (text/*, or a JSON/XML type such as application/json, application/xml, *+json, *+xml) and no contentEncoding.
  • rawTsType() uses it to generate Blob, and OperationVariant.inferResponseType() uses it so that such responses are requested as blob, same as format: binary today.
  • contentEncoding (e.g. base64) keeps the value as a string, since in OAS 3.1 that means the binary is encoded as text.

Tests: new test/content-media-type.json fixture and spec. They cover model properties (octet-stream, image/png, nullable, base64-encoded, JSON, XML and text content), an application/octet-stream request body, and the response type for binary and base64 responses.

OpenAPI 3.1 describes raw binary content with contentMediaType instead of format: binary. A string schema with a non-textual contentMediaType and no contentEncoding is now generated as Blob, and responses using it are requested as blob.

Fixes cyclosproject#403
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"contentMediaType":"application/octet-stream" is represented as a string, rather than a Blob

1 participant