-
Notifications
You must be signed in to change notification settings - Fork 395
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
enhancement bcherny#543 - Prefix items support #574
base: master
Are you sure you want to change the base?
enhancement bcherny#543 - Prefix items support #574
Conversation
added `--usePrefixItems` cli argument. When passed, JSON schemata containing `prefixItems` tuple validation key will parsed correctly.
Function isArrayType() should return true when `prefixItems` is present, even without `items` key
Added `usePrefixItems` option, which defaults to false
Created new test case
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.
Thanks for the contribution!
A few small nits. Please also add an e2e test, similar to https://github.com/bcherny/json-schema-to-typescript/blob/master/test/e2e/options.unreachableDefinitions.ts.
At some point we should explicitly add a --jsonSchemaVersion
flag, but this is a good stop-gap for now.
Thanks!
rules.forEach(rule => traverse(rootSchema, (schema, key) => rule(schema, filename, options, key, dereferencedPaths))) | ||
return rootSchema as NormalizedJSONSchema | ||
} | ||
/* eslint-disable prettier/prettier */ |
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.
Please don't disable Prettier.
|
||
rules.set('Rename `prefixItems` to `items` and `items` to `additionallItems`', (schema, _, options) => { | ||
if (isArrayType(schema) && options.usePrefixItems) { | ||
// @ts-expect-error this is a simple renaming procedure, there is in no need to change the `schema.items` type to allow for boolean values |
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.
Please don't expect an error. Instead, make the types safer or use a type assertion (a as A
).
schema.items = schema.prefixItems | ||
delete schema.prefixItems | ||
} | ||
return |
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.
Nit: Remove this
@TheoAnastasiadis Any chance you are still able to work on this? I would find this really helpful for my project. Thanks! |
Forgot about this completely. Will hopefully be free this weekend and I'll make the requested changes 🤞🤞 |
Added optional
--usePrefixItems
flag that defaults to false.When passed JSON schemas containing
prefixItems
anditems
keys are normalized asitems
andadditionalItems
, as per JSON Schema Draft 2020-12.The draft also contains changes to the
$recursiveRef
and$recursiveAnchor
keywords, which this PR does not deal with.✔Tests added