-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: support JSON Schema as input for a Type #1159
base: main
Are you sure you want to change the base?
Conversation
…pe into json-schema-to-arktype
Type inference removed in 07a5215. Maybe at some point in the future it can be re-added, but agree that for now we should focus on getting a version without inference merged. I still need to address the rest of your comments but I've run out of time for now so will have to wait. Work's been super hectic recently so haven't been able to work on this as much as I would've liked 😅 |
…rom external module YYY but cannot be named' by exporting XXX from YYY
…ion from 0.23.0 to 0.24.0
…il for improved error message upon duplicated 'required' keys
|
||
- No `dependencies` support | ||
- No `if`/`else`/`then` support | ||
- `multipleOf` only supports integers |
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.
@ssalbdivad are you open to lifting ArkType's restriction on divisors being non-integers? Or, if not/as an interim solution, it seems this could be added as a custom narrow
constraint?
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.
You can add whatever arbitrary validation you want in a narrow, but the reason we don't support this is because there isn't a straightforward way to test float divisibility without complex + potentially fallible string math.
@TizzySaurus was actually working on an implementation but it doesn't make sense to add a dependency or implement that much custom logic for such a niche case.
For rational values like 0.1
, you could testing something like (n: number) => (n * 10) % 1 === 0
. Outside that though, things tend to get scary so be careful.
Closes #729.
What
This PR adds
@ark/jsonschema
, which is a library enabling users to convert a valid JSON Schema schema into an ArkType type.API
Below is a basic sample-use of
@ark/jsonschema
:Remaining Work Before Merging
For some reason
parseJsonSchema({type: "array", items: {type: "string"}})
raisesTypeError: this.Schema1Apply is not a function
despite working against an earlier ArkType version (probably a bug in ArkType that I've not yet delved into to properly give details).Similar to above,
const t = parseJsonSchema({oneOf: [{type: "string"}, {type: "number"}]})
raisesTypeError: this.CompositionKeywords1Apply is not a function
:Tests are only partially implemented.
{type: "string", "maxLength": 5}
and{type: "string", "pattern": "es"}
, but not{type: "string", "maxLength": 5, "pattern": "es"}
. Is it worth having tests for the various "permutations"? I think this is perhaps overly excessive?@ark/jsonschema
package:Haven't yet properly filled out
ark/jsonschema/CHANGELOG.md
.Known Limitations (things I didn't implement from JSON Schema spec)
dependencies
keyword on objects.if
/else
/then
.any
/oneOf
/allOf
/not
.multipleOf
on numbers only supports integer divisors, due to ArkType only supporting integer divisors.