-
Notifications
You must be signed in to change notification settings - Fork 405
docs: update zod docs on openai patterns #643
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughReplaces a simple z.toJSONSchema mapper in documentation with a custom mapper that calls z.toJSONSchema(schema, { io, unrepresentable, override }). The override forces Zod date types to map to an OpenAPI string with date-time format, affecting OpenAPI schema generation behavior for dates (and potentially others via override). Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Dev as Developer
participant Mapper as Custom Mapper
participant Zod as z.toJSONSchema(...)
participant OAS as OpenAPI Schema
Dev->>Mapper: Generate schema from Zod
Mapper->>Zod: toJSONSchema(schema, { io, unrepresentable, override })
alt override: ZodDate detected
Zod-->>Mapper: type: date
Mapper-->>OAS: { type: "string", format: "date-time" }
else other types
Zod-->>Mapper: default JSON Schema
Mapper-->>OAS: default mapping
end
Note over OAS: Resulting OpenAPI schema reflects explicit date-time for dates
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests
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 |
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
🧹 Nitpick comments (1)
docs/patterns/openapi.md (1)
186-186
: Improve the comment clarity.The comment "Zod Mapping Invalid types, dates & more" could be more descriptive. Consider clarifying what "invalid types" means in this context and what "more" refers to.
Suggested improvement:
-// Zod Mapping Invalid types, dates & more +// Custom Zod mapping for handling dates and unrepresentable types
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
docs/patterns/openapi.md
(1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
docs/patterns/openapi.md
188-188: Hard tabs
Column: 1
(MD010, no-hard-tabs)
🔇 Additional comments (1)
docs/patterns/openapi.md (1)
189-198
: Use spaces for indentation and clarify the example heading
- The use of
ctx.zodSchema._zod.def
is correct per Zod v4 JSON Schema docs; no change needed there.- Replace the hard tabs with spaces for consistent indentation.
- Update the heading/comment to specifically describe handling of date schemas rather than “dates & more.”
Likely an incorrect or invalid review comment.
mapJsonSchema: { | ||
zod: (schema: z.ZodType) => z.toJSONSchema(schema, { | ||
io: 'output', | ||
unrepresentable: 'any', | ||
override: (ctx) => { | ||
const def = ctx.zodSchema._zod.def | ||
if (def.type === 'date') { | ||
ctx.jsonSchema.type = 'string' | ||
ctx.jsonSchema.format = 'date-time' | ||
} | ||
}, | ||
}) | ||
}, |
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.
Fix indentation to use spaces instead of hard tabs.
The code block contains hard tabs which are flagged by markdownlint. For consistency with the rest of the documentation, use spaces for indentation.
Based on static analysis hints.
Apply consistent spacing throughout the code block (the exact diff would depend on viewing the raw file, but ensure all lines use spaces, not tabs).
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)
188-188: Hard tabs
Column: 1
(MD010, no-hard-tabs)
🤖 Prompt for AI Agents
In docs/patterns/openapi.md around lines 188 to 200, the code block uses hard
tab characters for indentation which violates markdownlint and repository style;
replace all hard tabs with spaces to match the project's indentation convention
(use the same number of spaces per indent level used elsewhere in the file,
e.g., 2 or 4 spaces), ensuring every line in the shown block and any nested
lines use spaces only and no \t characters.
Summary by CodeRabbit