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
Reduce redundancy in generated schema #1011
Comments
I would be interested in working on this, but I was first wondering if it should be part of #927. |
Yes, this should be a part of #927. In addition, our |
@mprudhom It would be awesome if you could look into this! In addition to using I suggest that we first look into the ts -> json schema generation (which can use If you want to talk about this in more detail, we could discuss on skype. |
@domoritz Are you sure that |
Sorry, I didn't realize this hasn't been merged yet. There is a branch referenced from YousefED/typescript-json-schema#3. It only needs a few more changes to be ready. |
Relevant #927 |
@mprudhom would you like to work on this? It would be incredibly helpful for us! |
@domoritz I'll take a stab at it. Will it be OK for vega-lite to rely on my own fork of typescript-json-schema? As you mention, it will at least need support for enums. |
Sure! Although @ YousefED has been extremely responsive so I think we will be able to merge quickly. Since we are refactoring some things around the schema in VL right now, the first step would be to finish ref support (YousefED/typescript-json-schema#3) and then make sure that enums work. Also note that TS 1.8 added support for string literals and we might use them some time in the future. I don't think they are treated as enums internally and may produce horrible code with a lot of oneOfs. |
I implemented support for enums in
Then generating the new schema:
Most of the sample specs pass validation:
@domoritz Before I proceed, can you take a look at the TODO list I put in this issue's description and let me know if it sounds good to you? |
Fantastic! The validation errors seem to be mostly because the ts schema is not complete. We use any in a couple of places and the compiler assumes that objects are expected.
Looks like the only difficulty here is that vl shorthand uses the actual array. But to be honest, I think we can just change that code and always output the complete time unit. In fact, I think its necessary now that we have We are planning to extract the shorthand into its own repo anyway. I'll see whether we can speed that up.
What does this mean? We don't use string literals in vl yet but once TS supports microsoft/TypeScript#6554, we might. Check out https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#string-literal-types. Before we change too much in vl, let's try to get YousefED/typescript-json-schema#3 and your changes into the main repo. This means
Should we move these before the changes in vl? Also, just as a side note, we are changing the way default values are used so the instantiate methods or the schema in vega lite are probably not necessary any more. This simplifies our life and makes your contributions to schema generation from interfaces even more important. See #1119 |
OK, I've submitted a PR with CLI support for using refs & root refs at YousefED/typescript-json-schema#15. You can see it in action by grabbing my branch and running:
Is the name-conflict issue an existent problem in the vega-lite schema? I don't notice any cases where it overlapping schema references were being created. |
Not that I know of. |
In that case, I'll defer implementing it in order to keep the PR as simple as possible. Should I submit a vega-lite PR now to use the new schema generation against my branch of typescript-json-schema, or should we wait to see if #1119 gets merged soon? |
Note that one shortcoming of the new schema generation process is that typescript-json-schema doesn't do anything special with class extensions, so Since JSON Schema Draft 4 doesn't have any notion of schema extension, the only way to model the extension is to use an However, I wonder if the |
@domoritz The new schema generation PR is at #1130, and it is passing (aside from an unrelated test failure in "vl.fieldDef.cardinality()"). The example spec are all being validated against the the new schema generation. Let me know if you would like me to proceed with migrating the old schema generation to the new, or if you would like to handle that yourself, as it will touch quite a lot of code. |
I think it's fine to have repetition for now. In the future, the join schema generator could use allOf but for now it's fine to have repetition.
We want the validation to fail rather than silently accept ignored properties.
Amazing! Sorry about the test failure. It's fixed on master now. Give us some time to look at your PR and then we will decide. We want to migrate all defaults to the config in the next 1 to 2 days and avoid merge conflicts but your help is greatly appreciated. Thanks again. |
Awesome work @mprudhom! I made a few changes to your pr and created #1131. Also, I made some changes to the typescript to json schema compiler (YousefED/typescript-json-schema#20). We migrated the defaults into the config (thanks @kanitw) so now we don't need the json schema instantiation any more. What remains now is
I'm also having some issues with the compiler. Can you have a look at these? You can just take the changes from #1131 and create a new PR. Maybe start with one file before you do the complete move.
|
OK, I re-opened my original PR and updated it by migrating most of the schema attributes into comments & annotations on the typescript properties. I haven't eliminated the old schema yet (now renamed to "schemaOLD") because I don't know what you want to do about the current Since #1130 touches quite a lot of files, so I urge priority in reviewing it. P.S. the compiler errors seemed to have something to do with not being able to find the |
Excellent. I merged master and ripped out everything that was left around the old schema. We don't need instantiate any more. Somehow the schema generation is not working with 0.0.5
I think that is the last step left before we can merge all of this (pending review from @kanitw of course). |
See #1131 |
@domoritz Try using the complete path to the 26,27c26
< "schema": "tsc && npm run schema:only",
< "schema:only": "node_modules/typescript-json-schema/bin/typescript-json-schema src/schema/schema.ts Spec > vega-lite-schema.json",
---
> "schema": "typescript-json-schema src/schema/schema.ts Spec > vega-lite-schema.json",
61c60
< "typescript-json-schema": "YousefED/typescript-json-schema",
---
> "typescript-json-schema": "^0.0.5", |
I see the same error on my machine, not just on travis. I also tried changing my package.son to what you wrote above and reinstalled tjs but the error is still the same. It may have to do with the changes in 0.0.5 but I can't tell what the issue is. |
Maybe you see my bug in https://github.com/YousefED/typescript-json-schema/pull/20/files |
I can reproduce it too. Looks like maybe a newline issue with the script in
|
Hmm, I wish it worked.
|
I'm on mac by the way. Not sure whether that's the issue. |
Converting all files does not fix the issue. I also can't get it to work on travis. |
Odd, now I am seeing that error too. If I force the typescript-json-schema dependency to use typescript 1.7.5 instead of 1.8.0 then it works. |
That's annoying because we use ts 1.8 in vega-lite. Could you have a look at this? I submitted a pr to fix the ts version to 1.7 (YousefED/typescript-json-schema#22) for now so at least we can get the pr in and don't risk many merge conflicts. |
I tracked it about as far as I am able and made an issue for it at YousefED/typescript-json-schema#23. In order to move forward for the purposes of getting this PR merged, I recommend using a fork of typescript-json-schema that depends on typescript 1.7.5 instead of 1.8.0 and hope that @YousefED is able to figure out what the underlying problem with 1.8.0 is. |
Yes, I've done that in 4c2d974 |
Some structures in the generated
vega-lite-schema.json
are repeated multiple times. For example, thetimeUnit
enumeration is repeated verbatim 13 times throughout the schema. Detecting this redundancy and emitting repeated structures to a shareddefs
section of the schema would make it much more compact.TODO:
The text was updated successfully, but these errors were encountered: