jsonschema

JSon schema and Inheritance

半世苍凉 提交于 2019-11-29 09:11: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. OK, well, I am the author of both: the current JSON Schema validation spec; and the Java library which

Using RegEx in JSON Schema

我的未来我决定 提交于 2019-11-29 09:07:21
Trying to write a JSON schema that uses RegEx to validate a value of an item. Have an item named progBinaryName whose value should adhrere to this RegEx string "^[A-Za-z0-9 -_]+_Prog\\.(exe|EXE)$" . Can not find any tutorials or examples that actually explain the use of RegEx in a JSON schema. Any help/info would be GREATLY appreciated! Thanks, D JSON SCHEMA { "name": "string", "properties": { "progName": { "type": "string", "description": "Program Name", "required": true }, "ID": { "type": "string", "description": "Identifier", "required": true }, "progVer": { "type": "string", "description":

Correct JSON Schema for an array of items of different type

跟風遠走 提交于 2019-11-29 09:05:46
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" : { "type" : { "type" : "string", "enum" : ["BUILD", "REASSIGN"] } } }, { "type" : "object", "properties" : {

How do I use the `If` `then` `else` condition in json schema?

筅森魡賤 提交于 2019-11-29 07:12:43
A relatively new addition to JSON Schema (draft-07) adds the if, then and else keywords. I cannot work out how to use these new key words correctly. Here is my JSON Schema so far: { "type": "object", "properties": { "foo": { "type": "string" }, "bar": { "type": "string" } }, "if": { "properties": { "foo": { "enum": [ "bar" ] } } }, "then": { "required": [ "bar" ] } } If the "foo" property equals "bar", Then the "bar" property is required. This works as expected. However, if the "foo" property does not exist or input is empty then I don't want anything. how to acheive this? empty input {}.

Convert JSON to JSON Schema draft 4 compatible with Swagger 2.0

不羁的心 提交于 2019-11-29 05:57:53
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 $refs to other objects definitions thus only has one level whereas the tools I’ve found only produce tree

Understanding the “additionalProperties” keyword in JSON Schema draft version 4

僤鯓⒐⒋嵵緔 提交于 2019-11-29 05:17:04
问题 Link to the specification: http://json-schema.org/latest/json-schema-validation.html#anchor64 Section 5.4.4.2 states: Successful validation of an object instance against these three keywords depends on the value of "additionalProperties": if its value is boolean true or a schema, validation succeeds; ... Section 5.4.4.3 states: If "additionalProperties" is absent, it may be considered present with an empty schema as a value. Ok, so if "additionalProperties" is absent, it counts as being

JSON schema - valid if object does *not* contain a particular property

不羁的心 提交于 2019-11-29 02:43:18
问题 Is it possible to set up a JSON schema that still allows for additionalProperties but does not match if a very particular property name is present? In other words, I need to know if it's possible to have the exact opposite of the required declaration. Schema: { "type": "object", "properties": { "x": { "type": "integer" } }, "required": [ "x" ], "ban": [ "z" ] // possible? } Match: { "x": 123 } Match: { "x": 123, "y": 456 } Do not match: { "x": 123, "y": 456, "z": 789 } 回答1: What you want to

JSON Schema regarding use of $ref

时光怂恿深爱的人放手 提交于 2019-11-29 01:39:03
问题 I understand that $ref takes a URI to a json schema to use but where does $ref : "#" point to? Does it just mean use the current schema for this block level? Or does it mean to use the root level schema defined in the root level id? Thanks EDIT: So if I have: "items": { "anyOf": [ { "$ref": "#" }, { "$ref": "#/definitions/schemaArray" } ], "default": {} } Because it lacks an id field it will attempt to validate the instance items with the root schema first and then if that fails try to

Use JSON.NET to generate JSON schema with extra attributes

↘锁芯ラ 提交于 2019-11-29 00:21:28
问题 I am using JSON.NET to generate JSON Schema from c# object class. But I was unable to add any other json schema attributes e.g. maxLength, pattern(regex to validate email), etc Below is my working code, I can only generate json schema with required attribute. It would be great if anyone can post some code example about how to add those extra attribute for json schema. Thanks, my code example public class Customer { [JsonProperty(Required = Required.Always)] public int CustomerID { get; set; }

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

妖精的绣舞 提交于 2019-11-28 20:29:45
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? 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 . StaxMan If you can get POJOs that match Schema (using xjc for example), you could then use Jackson to produce JSON Schema (see ObjectMapper.generateSchema(...) ). I'd expect you to be able to write an XSLT script that