-
-
Notifications
You must be signed in to change notification settings - Fork 106
fix(JSON): @default not working for @JSON types & Typed JSON lists generating invalid Zod schemas #2040
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
Conversation
…rating invalid Zod schemas
📝 WalkthroughWalkthroughThe changes update type validation and schema transformation logic. In the attribute validator, a new check ensures that if a Typed JSON field’s parameter is marked as default, its resolved type must be a string. In the transformer, the schema generation now conditionally appends Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Validator
note over Validator: assignableToAttributeParam(...)
Caller->>Validator: Call assignableToAttributeParam(arg, param)
Validator->>Validator: Check if container is Typed JSON field
Validator->>Validator: If parameter is marked as @default, verify resolved type is string
Validator->>Caller: Return validation result
sequenceDiagram
participant Transformer
participant SchemaBuilder
Transformer->>SchemaBuilder: generateObjectSchemaField(field)
SchemaBuilder->>SchemaBuilder: Determine if field is an array (isList)
alt isList true
SchemaBuilder->>SchemaBuilder: Append .array() to lazy-loaded schema string
else isList false
SchemaBuilder->>SchemaBuilder: Use lazy-loaded schema string as is
end
SchemaBuilder->>Transformer: Return constructed alternatives
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (5)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/schema/src/language-server/validator/attribute-application-validator.ts
(2 hunks)packages/schema/src/plugins/zod/transformer.ts
(1 hunks)tests/regression/tests/issue-2039.test.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: build-test (20.x)
- GitHub Check: OSSAR-Scan
🔇 Additional comments (3)
packages/schema/src/language-server/validator/attribute-application-validator.ts (2)
270-275
: Good implementation for the Typed JSON field validation.This addition properly handles the case where a field is Typed JSON with a
@default
parameter, ensuring that the argument must be a string. This is critical because default values for JSON fields need to be serialized as strings that can be parsed back into their object form.
336-337
: Clean code separation with proper spacing.The empty line added here improves readability by separating logical blocks of code.
tests/regression/tests/issue-2039.test.ts (1)
1-42
: Well-structured regression test for issue #2039.This test comprehensively validates both aspects of the fix:
- It verifies that default values are correctly set for both single JSON objects (
foo
) and arrays of JSON objects (fooList
) when creating a new record- It confirms that the generated Zod schemas correctly validate JSON input data
The test case is properly isolated with its own PostgreSQL database and uses realistic JSON values in the default attributes.
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.
Thank you for making the fix @diesal11 ! I've added a minor comments. I'll make the adjustment and release a patch 😄.
Fixes #2039