jsonschema

JSON Schema: How to check that an array contains at least one object with a property with a given value?

夙愿已清 提交于 2019-12-19 03:20:11
问题 How can I check in the following json that at least one element in the array names has a property nickName with the value Ginny ? { "names": [ { "firstName": "Hermione", "lastName": "Granger" }, { "firstName": "Harry", "lastName": "Potter" }, { "firstName": "Ron", "lastName": "Weasley" }, { "firstName": "Ginevra", "lastName": "Weasley", "nickName": "Ginny" } ] } Currently I'm using the draft-06 version (FAQ here). This is my NOT WORKING schema: { "$schema": "http://json-schema.org/draft-06

Convert JSON to JSON Schema draft 4 compatible with Swagger 2.0

爷,独闯天下 提交于 2019-12-18 19:10:32
问题 I've been given some JSON files generated by a REST API with plenty of properties. I've created a Swagger 2.0 definition for this API and need to give it the corresponding schema for the response. The main problem: this JSON file has loads of properties. It would take so much time and I would make many mistakes if I write the schema manually. And it’s not the only API I need to describe. I know there are some tools to convert JSON to JSON schemas but, if I’m not mistaken, Swagger only has

Does JSON Schema validation in common-js utils support references?

血红的双手。 提交于 2019-12-18 13:22:51
问题 Does JSON Schema validation in common-js utils support references? I can not do this with https://github.com/kriszyp/commonjs-utils/blob/master/json-schema.js I tried following code: { "type" : "object", "required" : true, "properties" : { "id" : { "type" : "number", "required" : true }, "related" : { "type" : "array", "required" : true, "items" : {"$ref": "$#"} } } } I can go ahead and prepare my schema with out references, but it would be nice to know if it is possible. 回答1: I do not know,

Flask: Decorator to verify JSON and JSON Schema

自古美人都是妖i 提交于 2019-12-18 10:26:28
问题 I have a flask application with calls expecting JSON payload. Before each call is processed, I have a 2-step error checking process: Assert that the payload is a valid JSON Assert that the JSON payload complies with a specific schema Which is implemented in the following fashion: @app.route('/activate', methods=['POST']) def activate(): request_id = request.__hash__() # Assert that the payload is a valid JSON try: input = request.json except BadRequest, e: msg = "payload must be a valid json"

Json Schema: Require a property only when a specific property is present in a deep nested object

萝らか妹 提交于 2019-12-18 08:57:38
问题 I need to build a json schema (draft 4) that requires a property based on the presence of a property in another nested object. I already searched and tried a lot of things (anyOf, oneOf, not, dependencies) with no luck. Maybe this is not possible to in json schema? This is my simplified schema: { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "required": ["dog"], "properties": { "dog": { "type": "object", "required": ["bananas"], "properties": { "bananas": { "$ref":

OpenAPI query string parameter with list of objects

不打扰是莪最后的温柔 提交于 2019-12-18 08:14:45
问题 I am trying to document with OpenAPI a query string which look like filtered[0][id]=code&filtered[0][value]=12345 and contains a list of object with properties id and value . My yaml documentation looks like the following parameters: - name: filtered in: query description: filters to be applied explode: true style: deepObject schema: type: array items: properties: id: description: name of the field to be filtered type: string value: description: value of the filter type: object The problem is

How to define choice element in json schema when elements are optional?

我们两清 提交于 2019-12-18 07:46:07
问题 ------------Josn schema----------- { "type": "object", "properties": { "street_address": { "type": "string" }, "city": { "type": "string" }, "state": { "type": "string" } }, "required": [ "street_address" ], "additionalProperties": false } In above schema i want to create a choice between city and state. That is either city or state can come in json. So that below json would be invalid { "street_address": "abc", "city": "anv", "state": "opi" } and below one should be valid one { "street

JSon schema and Inheritance

▼魔方 西西 提交于 2019-12-18 05:36:46
问题 I have searched on json schema with java bindings with inheritance and all searches led me to the usage of "allOf". Using allOf would potentially solve my problem, but I am wondering if there is a construct in json schema that I can use which will generate my java code with real java inheritance "B extends A" - rather than inlining all properties from A inside B ? I am wondering if this is even supported / doable or I am just dreaming. If not supported, I would be curious to know the reason.

Correct JSON Schema for an array of items of different type

久未见 提交于 2019-12-18 05:28:06
问题 I have an unordered array of JSON items. According to the specification http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.5 the json schema below will only validate if the objects in the array appear IN THAT ORDER. I don't want to specify an order, just validate the objects within the array, regardless of order or number of objects. From the spec I can't seem to understand how this is done. "transactions" : { "type" : "array", "items" : [ { "type" : "object", "properties" : {

Is there a tool to generate a JSON schema from an XML schema through Java?

假装没事ソ 提交于 2019-12-17 23:13:07
问题 Is anyone aware of a tool or approach from which we can generate a JSON schema from XML schema or XML schema from JSON schema by Java? 回答1: It isn't very elegant, but jackson can generate json schema from a java class . So you could take your xml schema, generate java classes from it with jaxb annotations, then generate the json schema from that as jackson supports jaxb annotations. 回答2: If you can get POJOs that match Schema (using xjc for example), you could then use Jackson to produce JSON