Comments (5)
You are indeed doing something wrong, and the question therefore becomes what you want to do.
The problem is that itemsOne
is not a node which pointers are collected for. Do you want the first item of your array to obey a certain schema? Do you want all items to obey a certain schema?
from json-schema-validator.
My guess is that the second option is the good one. In this case this is what you have to do:
{
"items": {
"description": "an item in the array",
"$ref": "reference.json"
}
}
from json-schema-validator.
Ah, you are right. In this case, I want all the items in my list to obey a certain schema.
However, there are some more complex scenarios that would create a more complex array definition. For example of the data.
{
"orderedArray" : [
{
"desc" : "required first element personal data",
"lastname" : "smith",
"firstname" : "joe"
},
{
"desc" : "any number of these",
"phonenumber" : "111-111-1111",
"type" : "cell"
},
{
"desc" : "any number of these",
"phonenumber" : "111-111-1112",
"type" : "work"
},
{
"desc" : "required last element personal data",
"gender" : "M",
}
]
}
Perhaps there is a better way to describe this than using an array, such as pattered properties or additional properties, but I'm not as familiar with these concepts yet.
from json-schema-validator.
Hmmm, you will have difficulties here. Note: properties
and {additional,pattern}Properties
are only there for validating JSON Objects, not arrays.
The main problem you have is that as far as arrays are concerned, schemas for array elements are decided by both the presence or absence of items
and additionalItems
. And you cannot, currently, describe the schema for the last element of an array.
In fact, even though you can add keywords with my implementation, even this will not help: the ArraySchema{Digest,Selector}
classes only account for the aforementioned two keywords.
The closest to what you could do is having a three-element array, where the first has its own schema, the second is an array of any number of "middle items", and the third has its own schema as well. That is, your data would be:
[
"firstItem",
[ "array", "of", "middle", "items" ],
"lastItem"
]
and the maching schema would be (note: individual schemas for items left empty for brevity):
{
"type": "array",
"minItems": 3,
"maxItems": 3,
"items": [
{},
{ "type", "array", "items": { "$ref": "#/definitions/middleItems" } },
{}
],
"definitions": {
"middleItems": {}
}
}
from json-schema-validator.
I believe this is fixed, thanks!
from json-schema-validator.
Related Issues (20)
- Fix new errorprone warnings across java-json-tools
- can't validate a doc against the schema containing "const" HOT 1
- Failed validation for no apparent reason?
- Getting java.util.concurrent.ExecutionException while validating
- Error when validating Json against a schema defining oneOf
- Are we planning on supporting draft-07 HOT 1
- Example code on README.md please plus links to examples in src
- Migrate from joda-time to java 8 time API HOT 2
- Improcess error hanling in getJsonSchema - never squash exceptions
- Android app crashes because schema (v4) cannot be found at runtime HOT 2
- Getting NPE when passing null to validate method.
- Has the functionality of the ResolvingSchemaWalker been replaced in more recent versions?
- Conflicting Transitive Dependency Versions for Guava and Jsr305
- Where is pom.xml ? I want to import this library to my local and customize it
- Not compatible with GraalVM
- NoSuchFieldError on signing
- When JSONObject contains JSONArray, JSONArray's object can not be validated
- draftv4/schema is different between json-schema-validator 2.2.14 and json-schema-core 1.2.14
- release new version HOT 2
- How can we get Error Message with the error path appended?
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.