jsonschema

How to make json-schema to allow one but not another field?

家住魔仙堡 提交于 2019-12-04 08:42:00
Is it possible to make jsonschema to have only one of two fields. For example, image if I want to have a JSON with ether start_dt or end_dt but not both of them at the same time. like this: OK { "name": "foo", "start_dt": "2012-10-10" } OK { "name": "foo", "end_dt": "2012-10-10" } NOT OK { "name": "foo", "start_dt": "2012-10-10" "end_dt": "2013-11-11" } What should I add to the schema: { "title": "Request Schema", "type": "object", "properties": { "name": { "type": "string" }, "start_dt": { "type": "string", "format": "date" }, "end_dt": { "type": "string", "format": "date" } } } You can

JSON Schema conditional: require and not require

爷,独闯天下 提交于 2019-12-04 07:28:39
I'm trying to implement this condition: if a particular property exists, then another property is required; but if it does not exist, another one is not required. Also, in JSON schemas, can we use not in dependencies? Here is a sample schema var schema = { "properties": { "smaller": { "type": "number" }, "larger": { "type": "number" }, "medium":{'type':'string'}, "bulky":{'type':'string'} }, require:['smaller','larger'], additionalProperties:false }; If "medium" is present, then "bulky" is required. Otherwise, "bulky" is not required. Here "not required" means that if "medium" doesn't exist,

Is there a way to use Swagger just for validation without using the whole framework?

十年热恋 提交于 2019-12-04 05:06:51
问题 Suppose I have an existing Java service implementing a JSON HTTP API, and I want to add a Swagger schema and automatically validate requests and responses against it without retooling the service to use the Swagger framework / code generation. Is there anything providing a Java API that I can tie into and pass info about the requests / responses to validate? (Just using a JSON schema validator would mean manually implementing a lot of the additional features in Swagger.) 回答1: I don't think

Recursive JSON Schema

試著忘記壹切 提交于 2019-12-04 04:06:57
问题 I'm trying to create proper JSON Schema for menu with sub-menus. So I should define an array from item which should contain three items. 1 Display name, 2 URL and Children (which should be an array of object with the same structure) At this time I've got this: { "type": "array", "additionalProperties": false, // have no idea what is this for :) "items": { "type": "object", "additionalProperties": false, // have no idea what is this for :) "description": "MenuLink", "id": "menuLink",

How to define a JSON schema that requires at least one of many properties

会有一股神秘感。 提交于 2019-12-04 02:42:58
问题 I would like to know if I can define a JSON schema (draft 4) that requires at least one of many properties possible for an object. I already know of allOf , anyOf and oneOf but just can't figure out how to use them in the way I want. Here are some example JSON to illustrate : // Test Data 1 - Should pass { "email": "hello@example.com", "name": "John Doe" } // Test Data 2 - Should pass { "id": 1, "name": "Jane Doe" } // Test Data 3 - Should pass { "id": 1, "email": "hello@example.com", "name":

Denormalizing data structures for private data access in Firebase?

浪尽此生 提交于 2019-12-04 02:15:38
问题 I would like to create data that scales (to track private data of a user). The Firebase documentation recommends to nest the child objects under the parent like this: { "users": { "google:1234567890": { "displayName" : "Username A", "provider" : "google", "provider_id" : "1234567890", "todos": { "rec_id1": "Walk the dog", "rec_id2": "Buy milk", "rec_id3": "Win a gold medal in the Olympics", ... } }, ... } } (Where rec_id is a unique key generated by Firebase.push().) But as mentioned in

specify a value can be a string or null with json schema

℡╲_俬逩灬. 提交于 2019-12-03 23:27:36
Hopefully this isn't obvious to others because I find the docs at http://json-schema.org/ to be lacking in finer details. I'm getting a block of json with some properties that can be null or a string. How do you specify, in a json schema (to be parsed by json.NET's JsonSchema.Parse method), that a value can be of type null or type string? Is there something simple I'm missing like supplying an array for the type? For example; "member_region": { "type": [ "string", null ] } // this throws an exception Also, does anyone have a better source for json schema details then the json-schema.org? Where

JSON schema to enforce array contents

血红的双手。 提交于 2019-12-03 23:25:50
Hi all and thanks in advance. I am attempting to create a JSON schema to enforce an array to contain one A and B object and N C objects, where A and B are C objects and N is an integer inclusively between 0 and infinity. Therefor : [A, B] [A, B, C1] [A, B, C1, .., CN] Are all valid , though : [A] [A, C1] [A, C1, .., CN] Are not valid . To make clear, A and B must be present. C objects are optional, though you may have as many as you would like. C object schemas : { "$schema": "http://json-schema.org/draft-04/schema#", "title": "C Object", "type": "object", "required": ["id", "name"],

Conditional Json Schema validation based on property value

我的未来我决定 提交于 2019-12-03 20:42:53
I have the input json like below, { "results": [ { "name": "A", "testA": "testAValue" } ] } the condition is, if value of 'name' is 'A', then 'testA' should be the required field and if value of 'name' is 'B', then 'testB' should be the required field. This is the Json Schema I tried and its not working as expected, { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "required": [ "results" ], "properties": { "results": { "type": "array", "oneOf": [ { "$ref": "#/definitions/person" }, { "$ref": "#/definitions/company" } ] } }, "definitions": { "person": { "type": "object"

Only allow properties that are declared in JSON schema

空扰寡人 提交于 2019-12-03 14:17:47
问题 I am using json-schema and wanting to only allow properties that are declared in this file to pass validation. For instance if a user passes a "name" property in their json object it will fail this schema because "name" is not listed here as a property. Is there some function similar to "required" that will only allow the listed properties to pass? { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Accounting Resource - Add Item", "type": "object", "properties": { "itemNumber":