-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Schema validation with dynamic keys #2516
Comments
not sure if this is simple tbh. personally I consider the need to validate keys rare and due to badly designed APIs. also am more worried about issues like this: #2515 - because that is core to karate the last line is honestly a bit hard to read and understand. so I'm concerned about that. you are welcome to try a PR |
Thanks @ptrthomas Agreed about the last line being a bit hard to read.
Not sure it would be more understandable, though. And definitely very complicated to implement. The other interesting thing in your comment is issue #2515. There's a risk, albeit small IMO, that this new marker would introduce a similar regression. Also, how would it integrate with contains [only [deep]]? Something to thing about ... Anyway, I'm hoping to raise a PR for feedback in the coming days, with the initial suggestion. |
(on hold while looking at #2515 and learning more about shortcuts and whether they could help here. It seems that every month i learn a new amazing feature in Karate!) |
There are a few posts in StackOverflow asking how to use Karate's schema validation against data with dynamic keys.
This one is a pretty good example:
Peter's suggestion works:
but the mor.e properties there are in the json, especially nested ones as in the example above, the more complicated it is to implement. Isn't Karate all about simplicity ;)
What the user was trying to achieve:
'data: {#string: {name: #string, city_code: #string, airports: {#string: {name: #string}}}'
is a step in the right direction, IMHO.
Looking at the code, it does not seem too complicated to implement.
However, Karate currently does not support fuzzy logic on keys, only on values.
Any reason for that? Any objections to add it?
Also, I think
airports: {#string: {name: #string}}
is a bit misleading. It seems to imply a key of type string having an object with a propertyname
of type string, when in fact, we want to match a set of keys, each having an object with a propertyname
.Therefore, we could introduce a new #dict marker (as in Python's dictionary) that would be used as follows:
data: {#dict: {name: #string, city_code: #string, airports: {#dict: {name: #string}}}
@ptrthomas What do you think?
The text was updated successfully, but these errors were encountered: