Skip to content

Handle oneOf during schema generation#22

Merged
adrianhdezm merged 2 commits intomainfrom
codex/generate-zod-schemas-and-typeddict-for-oneof-object
Jun 10, 2025
Merged

Handle oneOf during schema generation#22
adrianhdezm merged 2 commits intomainfrom
codex/generate-zod-schemas-and-typeddict-for-oneof-object

Conversation

@adrianhdezm
Copy link
Copy Markdown
Owner

Summary

  • support oneOf/anyOf when generating Zod schemas
  • support oneOf/anyOf when generating Python TypedDicts
  • test new behaviour for union handling

Testing

  • npm test

https://chatgpt.com/codex/tasks/task_e_6848afbe2c3c832985d921d07e2976ee

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for handling oneOf/anyOf constructs during schema-to-Zod and schema-to-Python-TypedDict generation, accompanied by new tests and a snapshot update.

  • Extend convertSchema (Zod) to emit z.union([...]) for oneOf/anyOf
  • Extend convertToTypedDict (Python) to emit Union[...] for oneOf/anyOf
  • Add unit tests for oneOf with refs in both Zod and TypedDict paths and update snapshot

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/json-schema-to-zod.spec.ts Added test for oneOf with refs
tests/json-schema-to-typed-dict.spec.ts Added test for oneOf with refs
tests/snapshots/json-schema-to-typed-dict.spec.ts.snap Updated snapshot for the new TypedDict union output
src/utils/json-schema-to-zod.ts Implemented oneOf/anyOf handling for Zod schemas
src/utils/json-schema-to-typed-dict.ts Implemented oneOf/anyOf handling for TypedDicts
Comments suppressed due to low confidence (2)

tests/json-schema-to-zod.spec.ts:56

  • [nitpick] Consider adding a corresponding test for anyOf with refs to ensure consistent coverage of both union keywords in Zod generation.
it('handles oneOf with refs', () => {

tests/json-schema-to-typed-dict.spec.ts:105

  • [nitpick] It would be beneficial to add a test case for anyOf with refs so the Python TypedDict generator is equally exercised.
it('handles oneOf with refs', () => {

Comment thread src/utils/json-schema-to-zod.ts
Comment thread src/utils/json-schema-to-typed-dict.ts
@adrianhdezm adrianhdezm merged commit 3043dc6 into main Jun 10, 2025
1 check passed
@adrianhdezm adrianhdezm deleted the codex/generate-zod-schemas-and-typeddict-for-oneof-object branch June 10, 2025 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants