jsonschema

How to specify a property as null or a reference?

痴心易碎 提交于 2019-12-21 03:14:17
问题 I have a json document in which a part can be either null or a subobject, like this: [{ "owner":null }, { "owner":{ "id":1 } }] The question is if its possible to model this in json schema draft v4 using ref? What I would like is something like this { "type":"object", "properties":{ "owner":{ "type":["null", "object"], "$ref":"#/definitions/id" } }, "definitions":{ "id":{ "type":"object", "properties":{ "id":{ "type":"number" } } } } } 回答1: What you've posted should work, if you remove the

json schema date-time does not check correctly

杀马特。学长 韩版系。学妹 提交于 2019-12-20 11:03:42
问题 I have a JSON and a JSON-schema JSON: { "aaa": "4000-02-01 00:00:00" } JSON-schema: { "$schema": "http://json-schema.org/draft-04/schema", "type": "object", "properties": { "aaa": { "type": "string", "format": "date-time" } }, "required": ["aaa"] } The JSON gets validated by the JSON-schema. However if I change the field aaa to "bla" the schema does not notice that it is not a date-time any longer. Did I miss anything in the schema? 回答1: For Python's jsonschema library, specify the format

How to generate JSON-Schema from Swagger API Declaration

a 夏天 提交于 2019-12-20 08:20:59
问题 I have Swagger API Declaration for services using Swagger v 1.2 My original feeling about Swagger was, that it is very close to JSON Schema (Draft 3 and lately Draft 4) and it shall be relatively easy to generate JSON Schema for request and response objects. However, while part of the Swagger reuses JSON Schema structures, it turned out, it uses only subset of features, and it also introduces it's own inheritance in Models (using subTypes and discriminator ) . Question: Is there any existing

How can i write the json schema if json has multiple data set

余生颓废 提交于 2019-12-20 07:44:16
问题 I am new to this json schema , i am able to write json schema if it has only one data set like below { "employees": [ { "id": 1, "name": "aaa" } } example json-schema for this is { "type" : "object", "required" : ["employees"], "properties" : { "employees" : { "type" : "Array", "items" : [ "properties" : { "id" : {"type" : "integer"}, "name" : {"type" : "string"}, }, "required" : ["id","name"] ] } } } but i got stuck to write json schema in ruby if we have multiple data sets { "employees": [

JSONSchema - Required property dependent on parent property

纵然是瞬间 提交于 2019-12-20 05:47:04
问题 I would like to apply an additional "required" property in an array sub schema based on the presence of a property in the root schema. I have my schema set like this: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required":[ "isParentDependency", "subArray" ], "properties": { "isParentDependency": { "$id": "#/properties/isParentDependency", "type": "boolean" }, "subArray": { "$id": "#/properties/subArray", "type": "array", "items": { "$id": "#/properties

Are JSON schemas necessary for defining the structure of a JSON?

眉间皱痕 提交于 2019-12-20 04:29:07
问题 I am asking this because I see that the current JSON schema draft (http://json-schema.org/) proposes to have the schema of JSON in the following way: for the JSON : { "a":"abc" "b": 123 } the schema proposed in the draft is like { "type":"object" "properties":{ "a": {"type":"string"} "b": {"type":"integer"} } } My question here is does the JSON itself not define its structure? Is a separate schema necessary? The schema proposed by the draft validates the JSON that have the above structure and

Referencing JSON Schema from json similar way XML references XML Schema

 ̄綄美尐妖づ 提交于 2019-12-20 04:13:51
问题 When I have defined XML Schema I can then reference it from XML this way saying that that XML must correspond to the referenced schema. This way I can force validation of such XML and I can also provide valuable hint for the person who is going to edit this file, because XML editors supporting XML Schema will use such reference to generate auto-complete, this way making editing much easier. However I can't see such referencing in JSON Schema documentation. For example: https://json-schema.org

Storing a JSON schema in mongodb with spring

天涯浪子 提交于 2019-12-19 19:44:23
问题 I am new to Spring data and mongodb. I have a JSON object which represents a JSON Schema and I need to store that in mongodb using spring data. But the issue with JSON schema is the structure of JSON Schema is dynamic; for example below are two valid JSON schema with completely different structure. { "type": "object", "properties": { "name": { "type": "string", "minLength": 10 }, "age": { "type": "integer" } }, "required": [ "name", "age" ] } { "type": "array", "items": { "type": "object",

Jackson: generate schemas with references

孤街浪徒 提交于 2019-12-19 17:37:46
问题 When using Jackson's JSON schema module, instead of serializing the complete graph I'd like to stop whenever one of my model classes is encountered, and use the class name to insert a $ref for another schema. Can you guide me to the right place in the jackson-module-jsonSchema source to start tinkering? Here's some code to illustrate the issue: public static class Zoo { public String name; public List<Animal> animals; } public static class Animal { public String species; } public static void

Mutually exclusive property groups

此生再无相见时 提交于 2019-12-19 07:41:35
问题 Suppose I have an object with four possible properties: a, b, c, d. a and b can only appear together (i.e., a appears if and only if b appears). If a and b appear, c cannot appear (that is, a/b and c are mutually exclusive). If a and b do not appear, c may appear (but is not required to). d can appear in any combination with a/b, c, or on its own. No properties other than a, b, c, or d may appear at all. How do I express this as a jsonschema? I suspect I could use some combination of oneOf