-
Notifications
You must be signed in to change notification settings - Fork 89
add support for or/and key-groups in s/keys #279
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
Conversation
|
Hello? Is there no interest in this? |
|
I am truly sorry I didn't notice this PR earlier. I'll have a look at it now! |
|
Trying to make this mergeable, the first thing I notice is that it breaks pretty much every json-schema test. This is because things like turn into I feel like with a small adjustment of the logic, it would be possible to still generate This would make it easier to see what this change actually changes. Additionally, Do you feel like taking this PR forwards after all this time? |
|
Hi, I 'll try to revisit this over the weekend, taking your feedback into account 👍 btw, what is the semantic or functional difference between the following?
VS
|
|
Both comments addressed, and conflict/test resolved 👍 |
|
As far as I understand the json-schema spec, However, tools that interpret json-schema (like swagger ui) might have different handling for these. I see the CI pipeline is broken in this project at least for CLJS, I'll try fixing it. One more thing: would you mind adding a new test for this new behaviour? |
|
CI is now fixed in #292 . If you push new commits they should get a working CI run. |
ok, I'll push a dummy commit to get the passing tests
I was going to do that, but (to my surprise) such a test already exists! See the relevant test file I had to update... |
|
CI still requires approval, however all tests pass locally (via |
opqdonut
left a comment
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.
Looks good! This is definitely mergeable. Thanks! Consider my suggestion.
| :allOf [{:required ["spec-tools.json-schema-test/a"]} | ||
| {:anyOf [{:required ["spec-tools.json-schema-test/b"]} | ||
| {:allOf [{:required ["spec-tools.json-schema-test/c"]} | ||
| {:required ["spec-tools.json-schema-test/d"]}]}]} |
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.
If you pushed the (every? :required ...) check into parse-required1, it would also combine these two :required, making the output schema simpler.
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'm afraid it's not enough to just 'push' it into parse-required1 - I have to duplicate it in order to get the outcome you're describing (see last commit). Think of it this way: The one in accept-spec 'clojure.spec.alpha/keys is needed in order to keep the simple (no key groups) case as-is. The one in parse-required1 is needed to simplify a particular use-case after finding a key-group.
If you don't mind that sort of duplication, feel free to merge 👍
|
Oh no, I just realised that while these are the same: These aren't: ... and I think your last commit (that I asked for) also does the anyOf transformation. So probably best to merge without the check in Optimizing the allOf-anyOf tree to be smaller but semantically equivalent is a complex task, and I don't think we really need that in spec->json_schema. At least we should wait until some user bumps into a problem caused by big allOf-anyOf trees. |
You are indeed right - i should have thought that through a bit more too... The good news that we're now an
That was pretty much my thought when you first asked for this 'optimisation'...with that said, at this point (and after having fixed the bug I introduced yesterday) I kind of see the point of it all. In any case, if you want me to revert, I will. |
|
Thanks, that's great! I intend to merge this tomorrow. I'll add some test cases to make sure I really understand all the repercussions of this, and also have a crack at simplifying the output even more. I have some vague ideas about it, so I don't feel like dumping them on you. I'll also add some reitit-side test cases so that I can close the original metosin/reitit#619 . Thanks again for your contribution. |
|
released in 0.10.8 🎉 |
Tried to do the absolute minimum changes - hence I didn't touch
parse-keyswhich would be the ideal place to do it in...By the way this whole thing started here