Repository navigation
Map string schemas with a binary contentMediaType to Blob - #411
Open
ewerton336 wants to merge 2 commits into
Open
ewerton336 wants to merge 2 commits into
ewerton336 wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #403
OpenAPI 3.1 describes raw file content with
contentMediaType(e.g.application/octet-stream) instead offormat: binary. FastAPI with Pydantic v2 emits upload fields this way, so they were generated asstringinstead ofBlob.Changes:
isBinarySchema()ingen-utils.ts. A schema is binary when it hasformat: binary(unchanged), or acontentMediaTypethat isn't textual (text/*, or a JSON/XML type such asapplication/json,application/xml,*+json,*+xml) and nocontentEncoding.rawTsType()uses it to generateBlob, andOperationVariant.inferResponseType()uses it so that such responses are requested asblob, same asformat: binarytoday.contentEncoding(e.g.base64) keeps the value as astring, since in OAS 3.1 that means the binary is encoded as text.Tests: new
test/content-media-type.jsonfixture and spec. They cover model properties (octet-stream, image/png, nullable, base64-encoded, JSON, XML and text content), anapplication/octet-streamrequest body, and the response type for binary and base64 responses.