-
-
Notifications
You must be signed in to change notification settings - Fork 127
fix(openapi): use ZModel AST array flag for TypeDef[] @json fields #2314
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
fix(openapi): use ZModel AST array flag for TypeDef[] @json fields #2314
Conversation
When a model field uses `TypeDef[] @json` directly (e.g., `title TranslatedField[] @json`),
the OpenAPI generator was not generating the correct array schema. Instead of:
```json
"title": { "type": "array", "items": { "$ref": "#/components/schemas/TranslatedField" } }
```
It was generating:
```json
"title": { "$ref": "#/components/schemas/TranslatedField" }
```
The bug was that `def.isList` comes from Prisma's DMMF, but Prisma treats all `@json`
fields as plain `Json` type and doesn't know about the `[]` array notation in ZModel.
The array information is only available in the ZModel AST via `field.type.array`.
This fix uses `field.type.array` from the ZModel AST instead of `def.isList` from DMMF
when generating OpenAPI schemas for TypeDef-referenced Json fields.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
📝 WalkthroughWalkthroughModified array detection for Json fields referencing TypeDefs in OpenAPI RPC generation. Changed from using Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)packages/plugins/openapi/tests/openapi-rpc.test.ts (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ymc9
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you for making the fix @olup
Summary
TypeDef[] @jsonfields directly on model fieldsfield.type.arrayfrom ZModel AST instead ofdef.isListfrom DMMFProblem
When a model field uses
TypeDef[] @jsondirectly:The OpenAPI generator was producing:
Instead of the correct:
Root Cause
The code was using
def.isListfrom Prisma's DMMF, but Prisma treats all@jsonfields as plainJsontype and doesn't preserve the[]array notation from ZModel. The array information is only available in the ZModel AST viafield.type.array.Test plan
array of TypeDef with enum directly on model field🤖 Generated with Claude Code