Problem
Currently, tRPC procedures that accept file uploads via zod-form-data cannot be included in the generated OpenAPI specification. The library only supports application/json and application/x-www-form-urlencoded content types.
This forces endpoints like file upload to be disabled from the public API (enabled: false), limiting API capabilities.
Proposed Solution
Add automatic detection and proper schema generation for multipart/form-data:
-
Detect zod-form-data schemas - Identify when input uses zfd.formData() or contains zfd.file() fields.
-
Auto-set content-type - When file fields are detected, automatically use multipart/form-data instead of application/json.
-
Generate binary schema - File fields should generate:
{ "type": "string", "format": "binary" }
Example
// Schema using zod-form-data
const uploadSchema = zfd.formData({
applicationId: z.string().optional(),
zip: zfd.file(),
});
// tRPC procedure
uploadFile: protectedProcedure
.meta({ openapi: { method: 'POST', path: '/upload' } })
.input(uploadSchema)
.mutation(...)
Generated OpenAPI:
/upload:
post:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
applicationId:
type: string
zip:
type: string
format: binary
required:
- zip
Backward Compatibility
- Non-file schemas continue to use
application/json
- No breaking changes to the API