jsonschema

Convert a JSON schema to a python class

流过昼夜 提交于 2019-12-17 22:09:13
问题 Is there a python library for converting a JSON schema to a python class definition, similar to jsonschema2pojo -- https://github.com/joelittlejohn/jsonschema2pojo -- for Java? 回答1: So far the closest thing I've been able to find is warlock, which advertises this workflow: Build your schema >>> schema = { 'name': 'Country', 'properties': { 'name': {'type': 'string'}, 'abbreviation': {'type': 'string'}, }, 'additionalProperties': False, } Create a model >>> import warlock >>> Country = warlock

Validating JSON against Swagger API schema

家住魔仙堡 提交于 2019-12-17 18:14:51
问题 I created an API spec from some JSON files and I am trying to test if the files validate against the API spec. There are some good tools to validate against JSON Schema, but I did not have chance to find a tool to validate against specs created in the Swagger (tool for creating API schema). The only solution I found is generating a client/server in the Swagger-Editor, it is quite cumbersome. Is there already an existing tool to validate JSON against Swagger Schema? 回答1: Arnaud in the comments

How to manage multiple JSON schema files?

这一生的挚爱 提交于 2019-12-17 17:39:29
问题 I'm trying to validate my JSON API using node.js + json-schema.js from commonjs-utils. Just single validation was easy but could not find right way how to manage multiple schema files to enable referencing each other. Suppose that I got two Models & two APIs. // book { "type": "object", "properties": { "title": { "type": "string" }, "author": { "type": "string" } } } // author { "type": "object", "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string" } } } //

How to reference schema of json which is top level array

↘锁芯ラ 提交于 2019-12-17 17:16:29
问题 I have a JSON file which contains a list of items. The only thing stored in this file is the items as a array. e.g: [ {...}, {...}, {...}, ] I want to define a schema file for this. This seems fine as the initial type can be set to array and I can define items as a type. But I want to reference the schema in the item json file. Unfortunately it is not an object so I cannot add the "$schema" key. I could of course make the json a object with only one key that has the array value but this doesn

How to tell JSON schema validator to pick schema from property value?

做~自己de王妃 提交于 2019-12-17 16:35:18
问题 For example a schema for a file system, directory contains a list of files. The schema consists of the specification of file, next a sub type "image" and another one "text". At the bottom there is the main directory schema. Directory has a property content which is an array of items that should be sub types of file. Basically what I am looking for is a way to tell the validator to look up the value of a "$ref" from a property in the json object being validated. Example json: { "name":"A

JSON schema validation with PHP [closed]

天涯浪子 提交于 2019-12-17 16:32:38
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 months ago . Is there any PHP library that validates a JSON object against a JSON Schema? 回答1: About jsonschemaphpv, although it´s not very well maintained, we use it a lot and it works. It´s a port from the js validator. It has a full test suite that runs against the php and the http://code.google.com/p/jsonschema/. And

Generate Json schema from XML schema (XSD) [closed]

风流意气都作罢 提交于 2019-12-17 07:09:23
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Does anybody know how to generate a JSON schema from a existing XML schema (XSD file)? Are there any tools available for this? 回答1: Disclaimer : I am the author of Jsonix, a powerful open-source XML<->JSON JavaScript mapping library. Today I've released the new version of the Jsonix Schema Compiler, with the new

jsonSchema attribute conditionally required

十年热恋 提交于 2019-12-16 22:08:12
问题 In jsonSchema you can indicate whether defined fields are mandatory or not using the "required" attribute: { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "header": { "type": "object", "properties": { "messageName": { "type": "string" }, "messageVersion": { "type": "string" } }, "required": [ "messageName", "messageVersion" ] } }, "required": [ "header" ] } In certain cases, I would like the messageVersion field not to be mandatory. Is there any way

What is the logical relationship between keyword in a json schema?

我的梦境 提交于 2019-12-13 06:52:27
问题 According to the specification (http://json-schema.org/schema) there is no mutual exclusion among schema keywords. For example I could create the following schema: { "properties" : { "foo" : {"type" : "string"} } "items" : [ {"type" : "integer" }, {"type" : "number" } ] } Would this schema validate against both objects and arrays? If so it would imply an "OR" relationship between keyword. But if we consider the following schema: { "anyOf" : [ { "type" : "string",}, { "type" : "integer"} ]

How to remove dependencies of order in Json schema in case of Array of objects

99封情书 提交于 2019-12-13 06:27:50
问题 I have one Json schema template, which contains array of objects. And I need to verify Json input with that template. But I want this should not dependent on order for object in array. And below we have array of 3 different object in template i.e. abs, endpoint and dispatch. I want to remove dependency of order from here. I can provide ant order of items in Json input schema. It should not dependent on template. I am using 'ajv' node js template to validate the Json input with template data.