Repository navigation
Conversation
OpenAPI format byte is base64-encoded text, which JSON carries as a string; raw bytes are format binary. Mapping byte to Blob broke values such as ASP.NET byte[] concurrency tokens, which could not be sent back in a request without a cast. The binary-produces response alias built its Blob type from a synthetic format byte schema, so it now uses format binary and sets the alias content to Blob directly, keeping binary downloads typed as Blob. Fixes acacode#1841
🦋 Changeset detectedLatest commit: 49a8fee The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This is breaking change. And if developer occurs with same problem then it's just changes using codegen config All my cases with byte requires Blob |
|
Thanks, the primitiveTypeConstructs override works for us, so we'll use that and drop our version pin. For the record, I'd still question the default. In OpenAPI, format: byte means base64-encoded text inside JSON. For example, a C# byte[] such as a row version is serialised as "AAAAAAAAB9E=". Raw bytes are format: binary, which is already mapped to File. In a JSON body the runtime value is always a string, never a Blob, so the generated type doesn't match what axios/fetch actually return. If your cases need Blob, it may be worth checking whether those specs mark binary payloads as byte when they should use binary. A middle ground could be to keep string for application/json and use Blob only for multipart or octet-stream content. Either way, since this changed the generated output in a minor release (13.4.0), a "breaking" note in the changelog, with the override snippet, would save others the debugging time. |
Fixes #1841
Problem
Since 13.5.0 (1ed598b),
type: string, format: byteis generated asBlob.In OpenAPI,
bytemeans base64-encoded characters, and raw bytes areformat: binary(OpenAPI 3.0 Data Types).In a JSON body these values are plain strings. For example, ASP.NET serialises
byte[]properties such as concurrency tokens (rowVersion) as base64 strings. WithBlob, the generated type no longer matches the runtime value, so a value read from one response can't be sent back in the next request without a cast.Solution
src/configuration.ts:bytemaps tostringagain, as in 13.4.x and earlier.src/schema-routes/schema-routes.ts: the binary-produces response alias (c4b02db) got itsBlobtype from a synthetic{ type: "string", format: "byte" }schema, so changing themapping alone would have turned those aliases into
string. It now usesformat: "binary"and sets the alias content to
Blobdirectly. Binary downloads are still typed asBlob.Only their JSDoc changes, from
@format byteto@format binary, which describes themmore accurately.
Verification
tests/spec/issue-1841: a JSON body withrowVersion: format bytegenerates
rowVersion: string, andformat: binarystill generatesFile. It failswithout this change.
binary-produces,binary-produces-base-pathandbinary-produces-base-path-with-extracts.format: byteproperties change fromBlobtostring,GetXxxExportDataaliases stayBlob, and route return types are unchanged.Summary by cubic
Fixes #1841. Since 13.5.0,
format: bytewas generated asBlob, but per the OpenAPI spec it is base64-encoded text carried as a JSON string; raw bytes areformat: binary. Properties like ASP.NETbyte[]concurrency tokens are now generated asstringagain, matching the runtime value so they can be sent back in a request without a cast.GetXxxExportData) stay typed asBlob, now built from aformat: binaryschema with the alias content set directly; their JSDoc changes from@format byteto@format binary.format: byte→stringandformat: binary→File, and updates affected snapshots.Written for commit 49a8fee. Summary will update on new commits.