Replies: 2 comments
-
Just acknowledging that I see this :) -- it'll probably take me a few days at very least to look at it more carefully. I will say straight off the bat that I know that one thing downstream folks, probably like ASDF very specifically, want/need is an API for doing stateful things during validation. This is very "unlike" what JSON Schema "official" specifications do certainly historically (though that's changed more recently, which I personally find quite unfortunate :/ but alas...), but which is why such a thing is not as easy as it could be -- providing some official public APIs for doing such a thing is something I definitely want to do at some point but it's careful work to not break other existing code I think. Anyways, yeah, I need to get a few more things in progress for the upcoming release (like #1061) but I'll try to give you some advice here sometime soon. |
Beta Was this translation helpful? Give feedback.
-
So I've had a quick look at this (been more than a few days, but alas). That's quite an odd instance :). Your instance is infinite, so I'd definitely expect you to have to go out of your way to support it. Such a thing is certainly beyond any behavior of JSON Schema the specification, JSON has no such thing as infinite data, so the spec doesn't really say anything about what the behavior should be there, and therefore of course as you notice, the I can certainly understand if you extend the spec's behavior to such data, that you'd want the result you're aiming for. It's sort of more an induction-y kind of thing than breaking reference cycles, as even though I haven't thought too hard, my suspicion is you could have some set of mutually referential data with some more complex relationship in your schema and it will not be completely obvious to prove that just because you've validated the first time through each one that that means recursively the schema is valid. But I'm choosing not to think too hard :), I don't know precisely what you're trying to make work in general -- Anyways if it's just infinitely nested exact copies of data, the basic strategy of caching which instances are valid under a schema probably is good enough, yeah -- I'm also not really thinking hard about which validators you need to override / extend, but that API is of course public, so find which ones you need to override and define them similar to how you have that (n.b. if in X JSON Schema versions the spec adds a crazy (And n.b. 2, as a Python programmer I would never really call But yeah that seems the safest today I think, if you really mean to support such a thing. |
Beta Was this translation helpful? Give feedback.
-
As you may know, over in asdf we have a history of taking outrageous liberties with jsonschema's implementation details. Thanks to some new ideas from @braingram and the changes coming in 4.18, we're going to be able to eliminate most of that and use public interfaces instead.
One remaining problem we need to solve is how to break reference cycles during validation. For example, validating this document leads to RecursionError:
My best idea so far is to replace the validator methods with our own doctored up versions. We might replace the "properties" method with something like this:
(and store that
seen
variable somewhere we can reliably clear it after each validation)Is that a reasonable strategy? In doing so are we using anything that should not be considered a public API?
Beta Was this translation helpful? Give feedback.
All reactions