Summary
When an OpenAPI 3.1 spec describes a multipart file upload using contentMediaType (the OpenAPI 3.1 pattern), @openapi-codegen/typescript generates string instead of Blob (or Blob | File). This breaks TypeScript consumers that pass File objects to generated mutation hooks.
format: binary is handled correctly and maps to Blob.
Environment
@openapi-codegen/cli: 3.1.0
@openapi-codegen/typescript: 11.1.0
- OpenAPI source: FastAPI app (
app.openapi()), OpenAPI 3.1
- FastAPI: ≥ 0.129 (uses
contentMediaType for UploadFile instead of format: binary)
Reproduction
OpenAPI schema (multipart upload):
{
"components": {
"schemas": {
"Body_upload_proposal_document": {
"type": "object",
"required": ["document", "opportunity_id"],
"properties": {
"document": {
"type": "string",
"contentMediaType": "application/octet-stream",
"description": "Proposal document file"
},
"opportunity_id": {
"type": "string"
}
}
}
}
}
}
Generated today:
export type BodyUploadProposalDocument = {
document: string; // ❌
opportunity_id: string;
};
Expected:
export type BodyUploadProposalDocument = {
document: Blob | File; // or Blob
opportunity_id: string;
};
Consumer code that fails typecheck:
await uploadMutation.mutateAsync({
body: {
document: file, // File — TS2322: Type 'File' is not assignable to type 'string'
opportunity_id: opportunityId,
},
});
Context
Suggested fix
In schema type generation, when a property has:
type: string (or no explicit type), and
contentMediaType matching a file-like MIME type (application/octet-stream, image/*, etc.),
treat it the same as format: binary and emit Blob or Blob | File.
Summary
When an OpenAPI 3.1 spec describes a multipart file upload using
contentMediaType(the OpenAPI 3.1 pattern),@openapi-codegen/typescriptgeneratesstringinstead ofBlob(orBlob | File). This breaks TypeScript consumers that passFileobjects to generated mutation hooks.format: binaryis handled correctly and maps toBlob.Environment
@openapi-codegen/cli: 3.1.0@openapi-codegen/typescript: 11.1.0app.openapi()), OpenAPI 3.1contentMediaTypeforUploadFileinstead offormat: binary)Reproduction
OpenAPI schema (multipart upload):
{ "components": { "schemas": { "Body_upload_proposal_document": { "type": "object", "required": ["document", "opportunity_id"], "properties": { "document": { "type": "string", "contentMediaType": "application/octet-stream", "description": "Proposal document file" }, "opportunity_id": { "type": "string" } } } } } }Generated today:
Expected:
Consumer code that fails typecheck:
Context
contentMediaTypeon schema properties for binary/multipart fields (migration guide).Suggested fix
In schema type generation, when a property has:
type: string(or no explicit type), andcontentMediaTypematching a file-like MIME type (application/octet-stream,image/*, etc.),treat it the same as
format: binaryand emitBloborBlob | File.