Comments (6)
Hi, @jrhok.
This is actually really interesting question. It seems like the library indeed have a problem when the root $id
is not an absolute uri. I tried to load your schemes and the uri for foo.json
was resolved as /myproject/enums/myproject/enums/foo
that is definitely incorrect. I will create an issue to resolve this. I will try to fix it as soon as I can. Thank you for bringing this to my attention!
In the mean time, I could suggest use something like this instead (until I fix this)
foo.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://myproject/enums/foo",
"type": "integer",
"enum": [
0,
1,
2
]
}
request.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://myproject/data/request",
"type": "object",
"properties": {
"foo": {
"type": "array",
"items": {
"$ref": "/enums/foo"
}
},
"foobar": {
"$ref": "/enums/foo"
}
}
}
from json-schema-validator.
Thank you for your quick feedbacks !
We came up with the same workaround, thanks !
from json-schema-validator.
Hi, @jrhok. I will merge the fix today - I hope you can use the snapshot version until the release is published.
Small note about the references:
In your example:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "myproject/data/request",
"type": "object",
"properties": {
"foo": {
"type": "array",
"items": {
"$ref": "enums/foo"
}
},
"foobar": {
"$ref": "/myproject/enums/foo"
}
}
}
you tried to use the relative reference enums/foo
. You want it to be resolved into myproject/enums/foo
however, this will not happen. This will be resolved into myproject/data/enums/foo
.
This happens because when you use the reference that does not start with /
the resolution logic is the following:
- Find the closest
$id
to the place where you use the reference; - Drop the last part segment;
- Append the value from
$ref
to the URI we have on step 2.
So, the only option here would be to use the absolute reference in the main JSON schema.
from json-schema-validator.
Fixed in release 0.0.11
from json-schema-validator.
I have merged changes. Once snapshot (and later release) is published I will leave a comment here. Kindly, reopen the issue if you still have the same problem after updating to the newer version
from json-schema-validator.
Snapshot has been published
from json-schema-validator.
Related Issues (20)
- Add issue templates
- Each assertion should be loaded independently instead of grouping in one factory
- Automate version increment on release publication
- Add support for Draft 2019-09 (Draft 8)
- Add PR validation for lables
- Support remote schema loading
- Register custom Keywords HOT 4
- Add benchmarks for schema loading and validation execution
- Add support for Draft 2020-12
- Migrate to Kotlin 1.9
- Update workflows
- Support vocabulary customization through custom meta schema
- Too much validation errors HOT 3
- Correct circled references detection logic
- Add format keyword support
- Enhancement: support for dev containers
- Bug: multipleOf round error HOT 4
- Validation issue HOT 3
- Enhancement: Support $defs subschemas in Json HOT 3
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-schema-validator.