Replies: 1 comment 2 replies
-
Feel free to create a PR and change this. In the meantime you can use our new |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'd like to propose an enhancement to
@valibot/to-json-schema
that would improve compatibility with various JSON Schema parsers by explicitly including emptyproperties: {}
andrequired: []
fields in generated schemas, even when they would be empty.Background
I'm a big fan of valibot and use it extensively across multiple packages in our monorepo.
When integrating with tools like LangChain (which officially supports Zod), I could switch to Zod, but I really want to keep using valibot because:
However, I discovered that some JSON Schema parsers have stricter expectations about object schema structure than what the specification requires. This led me to manually define schemas instead of using the convenient
toJsonSchema
function - but I'd love to keep using valibot everywhere!Current Behavior
When converting a valibot schema with record types:
The generated JSON Schema looks like:
Proposed Enhancement
I propose that
toJsonSchema
should generate:Technical Context
According to the JSON Schema draft-07 specification:
However, in practice, some parsers expect these fields to be explicitly present.
Questions for Discussion
I'd love to hear the community's thoughts on this proposal!
Beta Was this translation helpful? Give feedback.
All reactions