Comments (7)
Thanks for the report. I'll have to check what changed. Refs are hard.
from json-everything.
I think this is the cause
I remember I needed to make that change in the $dynamicRef
and $recursiveRef
keywords, but I may have been overzealous in changing $ref
as well.
Also, your test case may be a good candidate for the JSON Schema Test Suite. I run against that suite every build, and it passed, so this case isn't there already.
from json-everything.
Interesting. I'll take a look into adding it to that test suite!
Regarding the place that you mentioned, I remember already snagging once on the fact that CurrentUri
sometimes actually contains the "parent directory" of the uri referring to the current schema. I think it was possible to get diagnostics where some uris were incorrect because of this. I'd wanted to write a minimal test-case but never got around to it.
My point is, it could be that the change you made there actually uncovered an underlaying problem. The last time I looked at it I tried to find a simple solution that will make sure that CurrentUri
always contains the uri of the current schema, but didn't manage it. As you said, $ref
-s are hard :)
from json-everything.
Yep, that's what did it. The idea with the change was that I wanted to first check if the current URI was resolveable, and take the schema root if not. It looks like you've found a case where that check throws an exception for some reason. This is important if the URI completely changes while navigating the schema.
For example:
// schema
{
"$id": "https://mydomain.com/outer",
"properties": {
"foo": {
"$id": "https://mydomain.com/foo",
"properties": {
"inner1": {
"$anchor": "bar",
"type": "string"
},
"inner2": {
"$ref": "#bar"
}
}
},
"bar": {
"$anchor": "bar",
"type": "integer"
}
}
}
// passes
{
"foo": {
"inner2": "value"
}
}
// fails
{
"foo": {
"inner2": 42
}
}
The first instance passes because the URI changes when navigating to the $ref
from outer
to foo
, which means that we need to resolve foo#bar
. The subschema at /properties/bar
has a URI of outer#bar
.
I think I just need to figure out why the exception is thrown rather than changing the $ref
resolution.
from json-everything.
The exception is thrown from your test code when trying to resolve the URI. If you use the code that you commented out (the TryGetValue()
line), then it works just fine. 😑
from json-everything.
The reason for the call, however... I'm not sure. My example still works without the change, as does the test suite.
I'll revert this change and republish.
from json-everything.
Sorry, I should have written this more clearly. Of course the exception is from my code, and one could argue that a good Fetch
should return null and not throw exceptions when e.g. a file is missing. OTOH, if I know what schemas would need to be fetched, and that the files are all there, then I shouldn't expect it to be called with a "strange" uri.
I left the exception-throwing version to highlight this; i.e., the bug is IMO that this uri was ever fetched. If you use the version which silencesthis exception in the test, it will not catch this bug.
Put otherwise: in the test which you added, I would have used the following Fetch
:
uri =>
{
map.TryGetValue(uri, out var ret).AssertTrue();
return ret;
}
since the only uris passed to this fetch should be in that dictionary. This would then indeed fail the test gracefully and not with an error (and also be more readable).
from json-everything.
Related Issues (20)
- How to get list of JSON Pointers that have the format keyword of date-time value from a JSON Schema HOT 4
- Support xml comments on generated schema HOT 13
- Deconstruct JsonLogic for conversion into another format HOT 8
- Support Case Insensitive Match on Property Names HOT 2
- Support custom keywords in schema generation HOT 6
- Evaluate JsonRequired Attribute HOT 5
- Model with Nullable value type is invalid HOT 1
- Model is not valid when has integer value as string HOT 1
- that the custom metastructure could not be parsed HOT 4
- How to extend SchemaGenerator for DateTime HOT 7
- JsonSchema.NET DataValidation HOT 10
- Custom `IAttributeHandler` never called HOT 5
- Anchors naming of 2020 still following 2019 rules HOT 5
- Generating a Custom JSON Schema HOT 1
- ArgumentOutOfRangeException thrown when calling JsonSchema's Evaluate methods from multiple threads. HOT 3
- 2020-12 output incorrectly places annotations
- Nullable decimal type removes multipleOf HOT 1
- Boolean applicator keywords must be non-empty HOT 1
- Issues with rendering on docs site HOT 1
- Verified error reporting type HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-everything.