Comments (5)
It's hard to say since you didn't show your schema.
If /definitions/testDocument
is really a file relative to your schema then you should load your schema using a SchemaLocation
so that it knows the base IRI to resolve it to.
If /definitions/testDocument
is supposed to be in the same schema document, then it should be #/definitions/testDocument
.
from json-schema-validator.
@justin-tay I'm trying to upgrade from 1.0.64 to 1.4.0 and seeing the same issue. My schema is like the follows:
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://json-schema.org/draft/2019-09/schema",
"title": "test schema",
"type": "object",
"properties": {
"fields": {
"type": "object",
"properties": {
"ids": {
"$ref": "#/$defs/fruits"
}
}
}
},
"$defs": {
"fruits": {
"$id": "/fruits/id",
"type": "object",
"properties": {
"berries": {
"type": "array",
"items": {
"$ref": "#/$defs/Berry"
}
}
}
},
"Berry": {
"$id": "/berry-id",
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
}
}
}
The json schema validator complains: com.networknt.schema.InvalidSchemaRefException: : Reference /$defs/Berry cannot be resolved
. How was 1.0.64
able to resolve it?
If I paste the schema to an online json schema validator, I receive errors as well. Was it a bug in 1.0.64
?
from json-schema-validator.
There are plenty of issues in 1.0.64
that were fixed particularly for ref resolution and embedded schema resources.
Putting $id
in a subschema makes it schema resource which makes any $ref
that references the document #
resolve to that schema resource.
In your example, all your $id
entries make no sense and you should just remove all of them. You shouldn't use https://json-schema.org/draft/2019-09/schema
for your $id
as this is for the metaschema. It is intended to use your own identifier. In subschemas the $id
is used for embedded schema resources and it doesn't appear to be your intent as you don't reference them.
from json-schema-validator.
Thanks for the answer @justin-tay. The upper level $id
was just an example. The actual id is like classpath:schemas/test
. I got past that error by not referencing the subschemas under the same $defs
document since that could cause infinite loop and is not allowed based on the documentation.
However, I encountered another error. I have some json schema documents defined under a common
folder so they can be shared by different schemas. I'm seeing this error after upgrade com.networknt.schema.JsonSchemaFactory - Failed to load json schema from classpath:schemas/common/child2.json
. The files would be something like:
main.json
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "classpath:schemas/main",
"title": "main schema",
"type": "object",
"properties": {
"fields": {
"type": "object",
"properties": {
"ids": {
"$ref": "../common/child.json"
}
}
}
}
}
child.json
{
"$id": "/common/child",
"title": "child schema",
"type": "object",
"properties": {
"value": {
"$ref": "./child2.json"
}
}
}
child2.json
{
"$id": "/common/child2",
"title": "child2 schema",
"type": "object",
"properties": {
"value": {
"type": "string",
"$comment": "child value."
}
}
}
Folder structure:
| -- main
| | -- main.json
| -- common
| | -- child.json
| | -- child2.json
Is there something wrong with the way how I load the schemas? I use the following:
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909);
return factory.getSchema(getClass().getResourceAsStream(name));
from json-schema-validator.
Your $id
entries used are very confusing. They should be absolute IRIs. Here your $id
entries look like the retrieval IRI, but aren't as they aren't placed in the correct structure, nor have the correct extension. You would be better off just removing them. The error says it can't find classpath:schemas/common/child2.json
probably because it's not there.
After removing all your $id
entries you can try the following.
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V201909);
JsonSchema schema = factory.getSchema(SchemaLocation.of("classpath:/main/main.json"));
String inputData = "{\r\n"
+ " \"fields\": {\r\n"
+ " \"ids\": {\r\n"
+ " \"value\": {\r\n"
+ " \"value\": 1\r\n"
+ " }\r\n"
+ " }\r\n"
+ " }\r\n"
+ "}";
System.out.println(schema.validate(inputData, InputFormat.JSON, OutputFormat.HIERARCHICAL));
from json-schema-validator.
Related Issues (20)
- Downgrade maven-source-plugin to 3.2.1
- Resolve javadoc warning messages
- `JsonSchema.getSubSchema()` fails with JsonPointer containing a number HOT 2
- Possible performance improvement: JsonNodePath.hashCode() HOT 3
- How to generate the json structure acording to the schema? HOT 2
- oneOf with discriminator does not verify json correctly HOT 4
- The location of the `module-info.class` in the jar file is wrong HOT 1
- anyOf and OneOf unhelpful error messages HOT 2
- Exponential algorithm in BaseJsonValidator.hasAdjacentKeywordInEvaluationPath HOT 13
- Validation error for "id" field in referenced schema HOT 1
- Missing error text details for values of enumeration when enum type is JSON object HOT 3
- is date-time supported in V201909 and latest version of jar HOT 1
- `oneOf` for empty array. HOT 1
- SLF4J 2 dependency, despite being fulfilled by older version HOT 9
- Unevaluated properties and subschemas HOT 4
- Unable to validate all elements of the array using 2020-12 Json schema HOT 4
- Schema validate always print "Failed to apply pattern" when validate fail HOT 1
- Invalid Schema Structure Not Being Enforced HOT 4
- Undertow version containing CVEs HOT 3
- OpenAPI Spec 3.0 validation should not require exclusiveMinimum to be a number HOT 2
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.