-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
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-dataschemas - Identify when input useszfd.formData()or containszfd.file()fields. -
Auto-set content-type - When file fields are detected, automatically use
multipart/form-datainstead ofapplication/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:
- zipBackward Compatibility
- Non-file schemas continue to use
application/json - No breaking changes to the API
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels