Repository navigation
support arktype (generalise json-schemable validation libraries) - #59
Merged
Merged
Conversation
but going to hit a problem with `schema.safeParse(...)`
mmkal
force-pushed
the
general-json-schema
branch
from
March 18, 2025 15:34
e49503b to
7c888c8
Compare
commit: |
mmkal
force-pushed
the
general-json-schema
branch
2 times, most recently
from
March 19, 2025 14:32
882f90b to
49aafe7
Compare
mmkal
force-pushed
the
general-json-schema
branch
from
March 19, 2025 14:40
49aafe7 to
46a2e18
Compare
mmkal
force-pushed
the
general-json-schema
branch
from
March 19, 2025 16:09
4cb4964 to
200b62c
Compare
mmkal
marked this pull request as ready for review
March 19, 2025 17:45
Merged
mmkal
added a commit
that referenced
this pull request
Mar 19, 2025
Follow on to #59 - this adds valibot support. Satisfyingly easy now that the only requirement is json schema conversion. Others have done the hard work! Notes: - requires `@valibot/to-json-schema` installed. if not detected valibot schemas will require raw json input (and output helptext explaining how to get richer inputs) - `@valibot/to-json-schema` throws when `v.pipe(...)` usage is detected, so there's a custom preprocessor that takes advantage of how slim and simple valibot schemas are - it just walks the "schema" object and swaps `.pipe` arrays with only the first element and metadata elements. I think this is safe but raised an issue against valibot: open-circle/valibot#1090 --------- Co-authored-by: Misha Kaletsky <[email protected]>
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.
Be less zod-biased, so that arktype (or in theory another validation library implementing
.toJsonSchema()) can be used instead of zod.Mostly out of my own curiosity, and zod will remain the recommended way to use this, but feels sensible to not be too coupled to zod.
Notes:
.toJsonSchema()doesn't always produce a usable json schema, see A few toJsonSchema requests arktypeio/arktype#1379 and arktype.test.tsmycli foo 2.2will parse as"2.2"for an input of typez.union([z.string(), z.number().int()]). But even this is arguably too smart. Maybe an argument of typez.union([z.string(), z.number()])should just always parse as a numberFuture:
.toJsonSchema()to the standard-schema spec? I doubt it would be accpeted, but maybe, if there were some official caveats like it being optional, and it being able to rely on external libs or somethingTRPC_CLI_JSON_INPUTS=true mycli foo --input '{"xx": 1, "yy" 2}'- idea being that if you don't like the way this library has transformed the input type into CLI arguments, you can opt out as an escape hatch