Closed vmelamed closed 1 week ago
Hey there. I'm the maintainer of JsonSchema.Net. I'm happy to have a look if you'd like to refile this issue over in the json-everything repository.
This repository is for the specification itself and not the right place for implementation-specific questions.
I have discovered the problem, and it's probably specific to my implementation.
The short answer is that you have your $defs
kinda messed up. It needs to be a flat dictionary, not a nested folder lookup.
What's happening is that it's reading /$defs/components
as a schema, which means all of the keys under it are treated as unknown keywords. As a result, it doesn't try to deserialize them... until they're referenced. And it deserializes them each time they're referenced (probably something I can try to fix up).
So every time you reference something like #/$defs/components/tokens/identifier
, this happens:
DefsKeyword
components
subschemaUnrecognizedKeyword
with a "tokens" name, which contains its value as a JsonNode
/identifier
), which returns another JsonNode
JsonSchema
SchemaRegistry
only tracks named subschemas, ones that contain $id
, $anchor
, or $dynamicAnchor
(or $recursiveAnchor
for 2019-09). It doesn't track pointer-identified subschemas. So when you point into an unknown keyword, it has to go through a lot of deserialization. When you then do that recursively... you saw what happened.
The solution is to flatten your $defs
and don't point $ref
to locations where subschemas aren't expected. Fix that up and it'll easily validate the instances. (I tried it.)
(Just out of curiosity, why are you serializing Linq expressions? And then, why do you need to validate them?)
Moved the issue to json-everything (sorry!) I'll add answers to your other questions there.
No worries. I was curious and impatient 😆
Hello,
In the last 2-3 months I've been building a schema that became quite large - almost 2000 lines with some minification. The schema is quite recursive - naturally - it defines JSON structure for the serialization of LINQ expressions (AST). Yesterday I added the last 4 types (literally at the bottom of the file) and all my tests crashed with stack overflow (if it helps, I am pasting the stack below). Then I tried other schema validators online and replaced
JsonSchema
with Newtonsoft'sJSchema
- they all work. If you have advice on how to fix it (unless it is a bug) I'll appreciate it very much, as I already committed toSystem.Text.Json
(hence ergoJson.Schema
) and adding Newtonsoft to the mix ... smells bad. You can find plenty of valid JSON documents in my test folders. If you need more information about the project, etc., please don't hesitate to contact me here or directly.Thank you very much for the good work and previous support with other issues. Val