-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schemas from subpackages break without calls to .openapi()
#158
Comments
.openapi()
broken in v5.3.0
.openapi()
broken in v5.3.0
.openapi()
broken in v5.3.0
.openapi()
.openapi()
.openapi()
@mikestopcontinues thank you for reporting. Would you be able to provide a full example of something that breaks it. Since I tried to create this script: export const registry = new OpenAPIRegistry();
const Key = z.object({ name: z.string() });
const KeyPost = Key.pick({ name: true }).openapi('KeyPost');
const KeyPatch = Key.pick({ name: true }).openapi('KeyPatch');
registry.registerPath({
path: '/key',
method: 'post',
responses: {
200: {
description: 'Sample response',
content: {
'application/json': {
schema: KeyPost,
},
},
},
},
});
registry.registerPath({
path: '/key/{keyId}',
method: 'patch',
responses: {
200: {
description: 'Sample response',
content: {
'application/json': {
schema: KeyPatch,
},
},
},
},
}); and it did generate a correct result: "paths": {
"/key": {
"post": {
"responses": {
"200": {
"description": "Sample response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/KeyPost"
}
}
}
}
}
}
},
"/key/{keyId}": {
"patch": {
"responses": {
"200": {
"description": "Sample response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/KeyPatch"
}
}
}
}
}
}
}
} The above seems correct. So please elaborate on your issue with a reproducible example |
Hi @AGalabov, I updated the original post just now. I was not correct in my initial diagnosis. The issue is with pulling the schemas from other packages in a monorepo. I'm actively trying to narrow down the issue now. |
@mikestopcontinues would you be able to share how the actual |
@AGalabov Here's a reproduction. The bug occurs as I find in my actual monorepo. A key source of confusion for me is that this exact code was working perfectly yesterday, under heavy development. I watched my types, my docs, and my client SDK update with changes, without problem. Some combination of updating dependencies and clearly temp data broke things. But the fact that this repro also errors suggests there's a real bug here. Anything else I can provide? |
@mikestopcontinues thank you! I did pull your code and added a few In general this particular schema should have There are two things that I can say:
|
@AGalabov Thanks a million. I'd been working in watch mode yesterday (no minification), and today I was trying to do a production build. As far as I'm concerned, my issue is resolved. I do see the value of better type discovery. Does Thanks again! |
As for:
Yes the So considering you're "resolved" I'll leave this issue open until I get to check the alternative approach. If it doesn't work for whatever reason I'll have to close the issue with a comment. Thank you for the collaboration as well! |
…-breaks-type-checks use _def.typeName for type checking zod schemas
@mikestopcontinues I think this should be working now for you with v5.3.1 |
Awesome, thanks! |
At the moment, I maintain one package with all of my application types, which I then import and wrap with
.openapi()
calls for use withzod-to-openapi
. However, this behavior completely stopped working recently. I thought it was caused by updating to5.3.0
, but testing ruled that out.Here's an example of code that no longer works:
And the error:
I can swallow some of the errors with a merge:
However, then I get the error for deeper properties that are reused:
I wish I had a better sense of how things stopped working, but I tried both rolling back my package updates as well as rolling back to previously working commits and clearing all caches and temp data. Neither brings back the prior behavior. I know it was working, because I was actively working with the code yesterday.
On the other hand, I experienced similar errors when I first started working with
zod-to-openapi
, so I suspect that there's likely something deeper going on.The text was updated successfully, but these errors were encountered: