fix(agent): skeletonFromJsonSchema handles nullable type-union shape - #634
Open
ygd58 wants to merge 1 commit into
Open
fix(agent): skeletonFromJsonSchema handles nullable type-union shape#634ygd58 wants to merge 1 commit into
ygd58 wants to merge 1 commit into
Conversation
Fixes sapiom#614 exampleFromJsonSchema (via its internal skeletonFromJsonSchema helper) returned null for any field whose JSON Schema type is an array containing "null" (e.g. { type: ["string", "null"] }), instead of a type-appropriate placeholder. The switch(schema.type) statement never matched an array, so it always fell through to the null default. The type field can validly be an array of alternatives per the JSON Schema spec, and some Zod versions (and non-Zod JSON Schema producers) represent a nullable field this way rather than as anyOf. exampleFromJsonSchema is a public entry point for schemas generated by whatever tooling the caller uses (per its own doc comment), so this shape must be handled regardless of which zod version/tool produced it - not just the anyOf branch already handled above. Fix: normalize an array type to its non-null member before the switch. Tests: this repo's bundled zod version actually produces anyOf for .nullable() (not a type array), so the zod-based tests pass via the pre-existing anyOf handling and mainly guard against regressions there. The raw type-array tests (constructing { type: [...] } directly) exercise the actual fix and fail without it - verified by temporarily reverting the fix and confirming that test failed, then restoring it. Changeset added (patch, @sapiom/agent).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #614
exampleFromJsonSchema(via its internalskeletonFromJsonSchemahelper) returnednullfor any field whose JSON Schematypeis an array containing"null"(e.g.{ type: ["string", "null"] }), instead of a type-appropriate placeholder. Theswitch(schema.type)statement never matched an array, so it always fell through to thenulldefault.The
typefield can validly be an array of alternatives per the JSON Schema spec, and some Zod versions (and non-Zod JSON Schema producers) represent a nullable field this way rather than asanyOf.exampleFromJsonSchemais a public entry point for schemas generated by whatever tooling the caller uses (per its own doc comment), so this shape must be handled regardless of which zod version/tool produced it - not just theanyOfbranch already handled above.Fix: normalize an array
typeto its non-null member before the switch.Tests: this repo's bundled zod version actually produces
anyOffor.nullable()(not a type array), so the zod-based tests pass via the pre-existinganyOfhandling and mainly guard against regressions there. The raw type-array tests (constructing{ type: [...] }directly) exercise the actual fix and fail without it - verified by temporarily reverting the fix and confirming that test failed, then restoring it.Changeset: added (
@sapiom/agent, patch).Verified locally:
vitest run src/introspection.test.ts(5/5 passing),eslintclean.