Prerequisites
Fastify version
5.5.0
Plugin version
No response
Node.js version
22
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
15
Description
When using @fastify/swagger with fastify-type-provider-zod, Zod schemas that include .transform() methods result in incorrect OpenAPI specifications. The transformed fields in response schemas are rendered as empty objects {} instead of maintaining their proper type information, while request schemas work correctly.
Expected Behavior
Both request and response schemas should maintain type information for transformed fields:
"stringWithTransform": {
"type": "string"
}
Actual Behavior
- ✅ Request body schema: Correctly shows
"type": "string"
- ❌ Response schema: Shows empty object
{}
{
"paths": {
"/": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"stringWithTransform": {
"type": "string" // ✅ Correct
}
}
}
}
}
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"properties": {
"stringWithTransform": {} // ❌ Bug: Missing type
}
}
}
}
}
}
}
}
}
}
Environment
- Node version: 22
@fastify/swagger: 9.5.1
fastify: 5.5.0
fastify-type-provider-zod: 6.0.0
zod: 4.1.5
Link to code that reproduces the bug
https://github.com/aon/fastify-swagger-zod-transform-bug
Additional context
I've reported this issue as well in turkerdev/fastify-type-provider-zod#208
Prerequisites
Fastify version
5.5.0
Plugin version
No response
Node.js version
22
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
15
Description
When using
@fastify/swaggerwithfastify-type-provider-zod, Zod schemas that include.transform()methods result in incorrect OpenAPI specifications. The transformed fields in response schemas are rendered as empty objects{}instead of maintaining their proper type information, while request schemas work correctly.Expected Behavior
Both request and response schemas should maintain type information for transformed fields:
Actual Behavior
"type": "string"{}{ "paths": { "/": { "post": { "requestBody": { "content": { "application/json": { "schema": { "properties": { "stringWithTransform": { "type": "string" // ✅ Correct } } } } } }, "responses": { "200": { "content": { "application/json": { "schema": { "properties": { "stringWithTransform": {} // ❌ Bug: Missing type } } } } } } } } } }Environment
@fastify/swagger: 9.5.1fastify: 5.5.0fastify-type-provider-zod: 6.0.0zod: 4.1.5Link to code that reproduces the bug
https://github.com/aon/fastify-swagger-zod-transform-bug
Additional context
I've reported this issue as well in turkerdev/fastify-type-provider-zod#208