json-schema-validator

What is the difference between “anyof” and “oneof” in z schema?

有些话、适合烂在心里 提交于 2019-12-05 10:23:15
Its looking like both works fine with my input validation code. Then what is the exact difference? Schema with oneof [{ "id": "MyAction", "oneOf": [{ "$ref": "A1" }, { "$ref": "A2" }] }, { "id": "A1", "properties": { "class1": { "type": "string"}, "class2": { "type": "string"} } }, { "id": "A2", "properties": { "class2": { "type": "string"}, "class3": { "type": "string"} } } ] Schema with anyof [{ "id": "MyAction", "anyOf": [{ "$ref": "A1" }, { "$ref": "A2" }] }, { "id": "A1", "properties": { "class1": { "type": "string"}, "class2": { "type": "string"} } }, { "id": "A2", "properties": {

Enforce object non emptyness using json schema

六眼飞鱼酱① 提交于 2019-12-05 05:21:14
We can enforce empty attribute of type object as follows: { "description": "voice mail record", "type": "object", "additionalProperties": false, "properties": {} } as explained here . Now I want to validate attribute which is of object type, dont have any predefined properties can have properties of type string or numeric should not be empty Enforcing non-emptyness (point 4) is what I am unable to guess. This is somewhat opposite of enforcing emptyness as in above example. My current json schema excerpt looks like this: "attribute": { "type": "object", "additionalProperties": { "type": [

Is it possible in json schema to define a constraint between two properties

此生再无相见时 提交于 2019-12-04 11:35:39
I have two fields in my schema - one is a required property called "name" and the other is optional (used to define a sorting property) called "nameSort" and I want to express If the "nameSort" field is defined, the "name" field should also be defined as the same value. Is it possible to express such an "inter-element" constraint with JSON schema? My cursory read of JSON Schema here http://json-schema.org/latest/json-schema-validation.html says no. You can express one property must be defined when another is present, e.g.: { "type": "object", "dependencies": { "nameSort": ["name"] } } However,

REST Assured with JSON schema validation not working

你。 提交于 2019-12-04 07:24:14
I'm working with Spring Boot and REST Assured to test REST APIs. I was trying the example with JSON schema validation but it throws this error: java.lang.IllegalArgumentException: Schema to use cannot be null According to documentation, the schema should be located in the classpath . My example schema is located there. Here is my project structure and example schema location: Here is my code. Without schema validation it works fine. given(). contentType("application/json"). when(). get("http://myExample/users"). then(). assertThat().body(matchesJsonSchemaInClasspath("example_schema.json"));

Json schema validation in Spring REST APIs

筅森魡賤 提交于 2019-12-04 03:05:23
I’m building a REST API using Spring Boot and [jackson-module-jsonSchema] ( https://github.com/FasterXML/jackson-module-jsonSchema ) for JSON schema generation. I’m looking the best way to validate the request JSON payload arriving to my APIs endpoints (Spring controllers) against the defined JSON schema defined for the exposed resource, validation includes check required fields , format , min and max values, etc.. everything we can validate against the schema. Seems jackson json schema module is useful for schema generation but not for validation, am I right? Any suggestion on how to achieve

JSON Schema definition for array of objects

99封情书 提交于 2019-12-03 11:03:47
问题 I've seen this other question but it's not quite the same, and I feel like my issue is simpler, but just isn't working. My data would look like this: [ { "loc": "a value 1", "toll" : null, "message" : "message is sometimes null"}, { "loc": "a value 2", "toll" : "toll is sometimes null", "message" : null} ] I'm wanting to use AJV for JSON validation in a Node.js project and I've tried several schemas to try to describe my data, but I always get this as the error: [ { keyword: 'type', dataPath:

How to define JSON Schema for Map<String, Integer>?

自闭症网瘾萝莉.ら 提交于 2019-12-01 15:41:24
I have a json : { "itemType": {"food":22,"electrical":2}, "itemCount":{"NA":211} } Here the itemType and itemCount will be common but not the values inside them (food, NA, electrical) which will be keep changing but the will be in the format : Map How do I define Json Schema for such generic structure ? I tried : "itemCount":{ "type": "object" "additionalProperties": {"string", "integer"} } You can: { "type": "object", "properties": { "itemType": {"$ref": "#/definitions/mapInt"}, "itemCount": {"$ref": "#/definitions/mapInt"} }, "definitions": { "mapInt": { "type": "object",

'$id' property usage in JSON Schema

做~自己de王妃 提交于 2019-11-28 07:49:27
问题 I'm using JSON Schema for validating data. I think that I may have a mistake on my schema by using the reserved keywords $id. The intention of this field was to designate what the REMOTE ID of the property on another platform was. So it was the "origin ID". Can you please advise what $id is and if I have made a critical mistake and this value needs changing. Because in the documentation I have found this definition: If present, the value for this keyword MUST be a string, and MUST represent a

Read file from resources folder in Spring Boot

…衆ロ難τιáo~ 提交于 2019-11-27 19:59:54
I'm using Spring Boot and json-schema-validator . I'm trying to read a file called jsonschema.json from the resources folder. I've tried a few different ways but I can't get it to work. This is my code. ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("jsonschema.json").getFile()); JsonNode mySchema = JsonLoader.fromFile(file); This is the location of the file. And here I can see the file in the classes folder. But when I run the code I get the following error. jsonSchemaValidator error: java.io.FileNotFoundException: /home/user/Dev/Java/Java

Read file from resources folder in Spring Boot

余生长醉 提交于 2019-11-26 15:59:38
问题 I'm using Spring Boot and json-schema-validator . I'm trying to read a file called jsonschema.json from the resources folder. I've tried a few different ways but I can't get it to work. This is my code. ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("jsonschema.json").getFile()); JsonNode mySchema = JsonLoader.fromFile(file); This is the location of the file. And here I can see the file in the classes folder. But when I run the code I get