-
Notifications
You must be signed in to change notification settings - Fork 155
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
chore: implement JSON Schema to NodeType adapter #1401
Conversation
|
|
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success712 tests passing in 101 suites. Report generated by 🧪jest coverage report action from ab62c1a |
c59c675
to
31d2a6e
Compare
2fe3a1c
to
b72833f
Compare
? itemsType(node[i], joinPointer(nodeAbsoluteRef, i)) | ||
: itemsType; | ||
// we continue resolving unknown types, but stop early on known scalars | ||
if (itemType === undefined && type !== unknownType && type !== SpecExtension) { |
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.
I think this if statement maybe be causing slower benchmark but looks like we need this code
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.
I did not review this file.
@@ -126,7 +127,7 @@ export async function lintConfig(opts: { | |||
rules: { spec: 'error' }, | |||
}); | |||
|
|||
const types = normalizeTypes(ConfigTypes, config); | |||
const types = normalizeTypes(opts.externalConfigTypes || ConfigTypes, config); |
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.
I think we need to move to universal plugins approach so won't need it.
Let's talk offline.
872292a
to
672bc50
Compare
a87cc5f
to
f748ab6
Compare
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.
LGTM
f748ab6
to
ef029ff
Compare
…des; add unit tests
…config schemas according to the latest monorepo changes
update perf benchmark switch to museum for a moment improve walk and resolve for performance cleanup the code change fn syntax make the adapter errors nicer
ef029ff
to
ab62c1a
Compare
|
What/Why/How?
Implemented JSON Schema to NodeType adapter.
This streamlines merging external config schemas while allowing deriving TypeScript types from JSON Schema schemas.
The adapter itself is here. It uses AJV to determine the correct
oneOf
schema if there's nodiscriminator
defined.The adapter is limited to JSON Schemas that are not booleans or arrays themselves, nor types are arrays.
Also, the schemas should not contain
allOf
oranyOf
(we're not using them anyway).The most crucial limitation is that an array's-- Upd: fixed in 2fe3a1citems
could not containoneOf
. I even had to change the adapters schema schema of thedeveloperOnboarding
section. That is becauseNodeType
cannot alter items (like it can do withproperties
oradditionalProperties
).I also fixed a wrong snapshot test, added missing configurable rules subject types, and updated the config schema to the latest version.
Reference
Testing
Performance
Investigated performance losses. It doesn't do that bad on linting. For the current Rebilly API description it doesn't show any significant difference comparing to other versions:
node node_modules/cli-140/bin/cli.js lint api-definitions/openapi/openapi.yaml
node node_modules/cli-150/bin/cli.js lint api-definitions/openapi/openapi.yaml
node node_modules/cli-160/bin/cli.js lint api-definitions/openapi/openapi.yaml
node node_modules/cli-170/bin/cli.js lint api-definitions/openapi/openapi.yaml
node node_modules/cli-180/bin/cli.js lint api-definitions/openapi/openapi.yaml
node node_modules/cli-next/bin/cli.js lint api-definitions/openapi/openapi.yaml
On the other hand, for smaller museum.yaml API description the losses are higher (which most likely means the config itself gets resolved longer):
node node_modules/cli-140/bin/cli.js lint ../resources/museum.yaml
node node_modules/cli-150/bin/cli.js lint ../resources/museum.yaml
node node_modules/cli-160/bin/cli.js lint ../resources/museum.yaml
node node_modules/cli-170/bin/cli.js lint ../resources/museum.yaml
node node_modules/cli-180/bin/cli.js lint ../resources/museum.yaml
node node_modules/cli-next/bin/cli.js lint ../resources/museum.yaml
Screenshots (optional)
Check yourself
Security