fix(zod): apply propertyNames to string schemas in JSON Schema gen#217
fix(zod): apply propertyNames to string schemas in JSON Schema gen#217
propertyNames to string schemas in JSON Schema gen#217Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis pull request adds a new test case covering record schemas with date-formatted keys and refines the conversion logic in the ZodToJsonSchemaConverter. The test case in the edgeCases array ensures proper handling of keys when using Changes
Sequence Diagram(s)sequenceDiagram
participant TestSuite as Test Suite
participant Converter as ZodToJsonSchemaConverter
participant Schema as ZodRecord Key Schema
TestSuite->>Converter: Invoke conversion for record schema
Converter->>Schema: Convert key schema using convert()
Schema-->>Converter: Return key JSON (keyJson)
Converter->>Converter: Evaluate keyJson structure to determine type
Converter-->>TestSuite: Return converted schema
Possibly related PRs
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS Optional dependencies cannot be installed without production dependencies ✨ Finishing Touches
🪧 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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
More templates
@orpc/client
@orpc/contract
@orpc/openapi-client
@orpc/react-query
@orpc/openapi
@orpc/server
@orpc/shared
@orpc/standard-server
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/zod/src/converter.ts (1)
416-418: Improved key type handling for ZodRecordThe change improves the way record key types are processed by directly converting and examining the structure rather than relying on type name checks. This correctly handles string key types with additional constraints (like date formatting).
Consider adding a comment explaining the intention behind this check:
const [__, keyJson] = this.convert(schema_._def.keyType, options, lazyDepth, false, false) +// Apply propertyNames constraint if the key schema is anything more complex than a basic string type if (Object.entries(keyJson).some(([k, v]) => k !== 'type' || v !== 'string')) { json.propertyNames = keyJson }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/zod/src/converter.test.ts(1 hunks)packages/zod/src/converter.ts(1 hunks)
🔇 Additional comments (1)
packages/zod/src/converter.test.ts (1)
408-412: Good test case addition for date-formatted string keysThis test case correctly ensures that record schemas with date-formatted string keys have the appropriate
propertyNamesconstraint in the generated JSON Schema.
Summary by CodeRabbit