jsonschema

JSON Schema conditional required if and only if a specific key exists in nested object

Deadly 提交于 2020-01-17 01:00:12
问题 My question for jsonschema is twofold: Given { "foo": {"ar": {"a": "r"}}, "bar": "" } How do I check if the key "ar" exists inside of "foo"? And only if "ar" exists inside of "foo", how do I make it so that "bar" must exists inside the given json? I have tried looking other SO answers or jsonschema docs, but they only seem to check if the key has a specific value rather than if the key just exists regardless of its value. And the jsonschema for nested objects only seem to check for the

Add description to json schema subtypes

▼魔方 西西 提交于 2020-01-15 10:38:30
问题 I am generating json schema from my java classes with jackson, and I add the description field to all my properties like this : @NotNull @JsonProperty (required = true) @JsonPropertyDescription ("My description to add in schema") private double value; This work fine, and the field description is set into the json schema. Now I have json subtypes described as below : @JsonTypeInfo (use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") @JsonSubTypes ({

How to materialize attrs data class from JSON schema defined by JSL document

好久不见. 提交于 2020-01-15 09:31:48
问题 Assuming you using Python JSL library for defining JSON schema of your data and you using attrs library for quick definition of your DTO. How can you easily validate data structure against its JSON schema definition (as jsl.Document class) and reify it into attrs instance conforming to its JSL definition without extra boilerplate? Because creating JSL documents and duplicate their definitions just to have a corresponding attrs DTO doesn’t feel to be the right way. 回答1: Define a function to

How to materialize attrs data class from JSON schema defined by JSL document

心不动则不痛 提交于 2020-01-15 09:30:12
问题 Assuming you using Python JSL library for defining JSON schema of your data and you using attrs library for quick definition of your DTO. How can you easily validate data structure against its JSON schema definition (as jsl.Document class) and reify it into attrs instance conforming to its JSL definition without extra boilerplate? Because creating JSL documents and duplicate their definitions just to have a corresponding attrs DTO doesn’t feel to be the right way. 回答1: Define a function to

How to set up local file references in python-jsonschema document?

99封情书 提交于 2020-01-15 07:28:20
问题 I have a set of jsonschema compliant documents. Some documents contain references to other documents (via the $ref attribute). I do not wish to host these documents such that they are accessible at an HTTP URI. As such, all references are relative. All documents live in a local folder structure. How can I make python-jsonschema understand to properly use my local file system to load referenced documents? For instance, if I have a document with filename defs.json containing some definitions.

Get the property for each jsonschema errror

喜夏-厌秋 提交于 2020-01-15 06:49:11
问题 I am trying to determine which property caused the error. It seems for each type of error the way to get the property is different. from jsonschema import Draft4Validator request_json = { 'num_pages': 'invalid', 'duration': 'invalid', 'dne': 'invalid' } schema = { "patch": { "type": "object", "properties": { "name": {"type": "string"}, "location": {}, "description": {}, "objectives": {}, "num_pages": {"type": "integer"}, "duration": {"type": "integer"} }, "required": ["name"],

Can JSON integer attributes be referenced?

ぐ巨炮叔叔 提交于 2020-01-11 13:15:09
问题 I have the following JSON schema that I want to validate and Python unittest. { "properties": { "traffic_parameters" { "capacity": { "oneOf": [ { "max_percentage": { "type": "integer", "minimum" : 1, "maximum" : 150 }, "min_percentage": { "type": "integer", "minimum" : 1, "maximum" : { "$ref": "#/properties/traffic_parameters/capacity/oneOf/max_percentage/minimum" } } }, { "percentage_range": { "type": "array", "minItems": 1, "maxItems": 10, "items": { "type": "integer" } } } ] } } } } Using

Need help :Json Schema Design

馋奶兔 提交于 2020-01-06 18:03:49
问题 I am designing the the json scheme. and I am facing some issues while designing the schema. Here is the problem. I have an array of group objects. and I want this array should contain unique group objects. I want to make them unique based on object id ( ex group.id) The groups array is not unique if (groups[0].id == groups[1].id) , I want to make unique only based on group id, Below is my Json structure. "groups": { "type": "array", "items": {"$ref": "#/group"}, "uniqueItems":true }, "group":

How to allow one property only if other is not present and allow any of other propeties in json schema

烈酒焚心 提交于 2020-01-05 13:09:46
问题 I have six properties: name, age, phone, deletePhone, address, deleteAddress. I want to create schema that allows anyOf above properties but phone should not be present with deletePhone and address should not be present with deleteAddress(and vice versa). I have tried this schema: { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "number" }, "phone": { "type": "number" }, "deletePhone": { "type": "boolean" }, "address": { "type": "string" }, "deleteAddress": {

validate array json contains several unordered objects using json schema

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-05 07:15:09
问题 Problem I want to use json schema draft 7 to validate that an array contains several unordered objects. For example, the array should contains student A, B, regardless of their orders. [{"name": "A"}, {"name": "B"}] //valid [{"name": "B"}, {"name": "A"}] //valid [{"name": "A"}, {"name": "C"}, {"name": "B"}] //extra students also valid [] or [{"name": "A"}] or [{"name": "B"}] //invalid Current Attempt json schema contains keyword doesn't support a list json schema Tuple validation keyword must