-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add JSON schema generation. #358
Conversation
Schema generation currently fails (see below)... @domoritz please let me know if you can diagnose or have ideas on how to fix! The Mosaic spec typings make use of intersection types. I don't see those explicitly included as a ts-json-schema-generator feature, so might those be an issue?
|
It looks like there are two unhandled cases. First, The first one took me a bit to find but it's related to the comment on the type we pass to |
Hmm, maybe we can simplify the typings then? I think all we need for the Mosaic JSON spec is an object that has valid CSS property names as keys and their corresponding values. We don't need methods or other DOM bits. If we use something like Alternatively, it looks we can copy that (large) collection of properties from TS libs if needed: https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts ...though it would be nice to not have to maintain our own list! |
I got it working locally but it generates hundreds of thousands of lines for just that type. I had to leave to see the eclipse but will finish up the fix soon and then we can evaluate what makes sense here. |
65b5f5c
to
c899064
Compare
I made some significant updates to the schema generator so it handles functions more gracefully. It now compiles the schema for mosaic. I haven't looked into whether it's correct but at least it compiles. And yes, |
c899064
to
aede4ea
Compare
Thanks @domoritz! I added omitted properties for the CSSStyleDeclaration and that cleans up the result and reduces the size of the output tremendously. For the most part, the generated schema is looking good. Remaining Issues:
|
Preserving string literals would be nice. I filed vega/ts-json-schema-generator#1921. There were some related asks around this earlier. We already seem to handle
|
"lint": "eslint src test", | ||
"schema": "ts-json-schema-generator -f tsconfig.json -p src/spec/Spec.ts -t Spec --no-type-check --no-ref-encode --functions hide > dist/mosaic-schema.json", |
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.
FWIW this fails on a fresh clone of the repo bc the dist/
directory doesn't exist
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! Yeah, this is still WIP, but also schema
is not meant to typically be run in isolation; it's now tied in to both the prebuild and pretest hooks.
I tested with the latest from vega/ts-json-schema-generator#1927 just now. |
Ah, there was a bug that I fixed: vega/ts-json-schema-generator#1929. I'll make a release and update here. |
This PR uses ts-json-schema-generator to automatically generate a JSON schema definition: