jsonschema

Convert a JSON schema to a python class

*爱你&永不变心* 提交于 2019-11-28 17:16:27
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? synthesizerpatel 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.model_factory(schema) Create an object using your model >>> sweden = Country(name='Sweden

set Jackson ObjectMapper class not to use scientific notation for double

空扰寡人 提交于 2019-11-28 12:14:27
I am using a library com.fasterxml.jackson library for JsonSchema, I am creating creating an IntegerSchema object, when I set range for integer schema using below code: main(){ IntegerSchema intSchema = new IntegerSchema(); // setMaximum accepts Double object intSchema.setMaximum(new Double(102000000)); // setMaximum accepts Double object intSchema.setMinimum(new Double(100)); printJsonSchema(intSchema); } public void printJsonSchema(JsonSchema schema){ ObjectMapper mapper = new ObjectMapper(); try { logger.info(mapper.writeValueAsString(schema)); } catch (JsonProcessingException e) { throw

Express that, for a given property value, a property with the same name should exist using json schema?

我怕爱的太早我们不能终老 提交于 2019-11-28 11:40:58
问题 I'm trying to validate json files which have an element that has a property which contains a value that should exist in another part of the json. I'm using jsonschema Draft 07. This is a simple little example that shows the scenario I'm trying to validate in my data. { "objects": { "object1": { "colorKey": "orange" } }, "colors": { "orange": { "red": "FF", "green": "AF", "blue": "00" } } } How can I validate that the 'value' of colorKey (in this case 'orange') actually exists as a property of

Json Schema example for oneOf objects

我们两清 提交于 2019-11-28 09:36:30
I am trying to figure out how oneOf works by building a schema which validates two different object types. For example a person (firstname, lastname, sport) and vehicles (type, cost). Here are some sample objects: {"firstName":"John", "lastName":"Doe", "sport": "football"} {"vehicle":"car", "price":20000} The question is what have I done wrongly and how can I fix it. Here is the schema: { "description": "schema validating people and vehicles", "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "required": [ "oneOf" ], "properties": { "oneOf": [ { "firstName": {"type":

How to change all keys to lowercase when parsing JSON to a JToken

懵懂的女人 提交于 2019-11-28 07:55:18
问题 I have a string of JSON and the keys have uppercase and lowercase characters: {"employees":[ {"FIrstName":"John", "LASTname":"Doe"}, {"FIRSTNAME":"Anna", "LaSTNaME":"Smith"}, {"firstName":"Peter", "lastName":"Jones"} ]} I want convert it to a JToken object and have all the keys in the JToken be lowercase. So internally in the JToken it should be as follows: {"employees":[ {"firstname":"John", "lastname":"Doe"}, {"firstname":"Anna", "lastname":"Smith"}, {"firstname":"Peter", "lastname":"Jones"

'$id' property usage in JSON Schema

做~自己de王妃 提交于 2019-11-28 07:49:27
问题 I'm using JSON Schema for validating data. I think that I may have a mistake on my schema by using the reserved keywords $id. The intention of this field was to designate what the REMOTE ID of the property on another platform was. So it was the "origin ID". Can you please advise what $id is and if I have made a critical mistake and this value needs changing. Because in the documentation I have found this definition: If present, the value for this keyword MUST be a string, and MUST represent a

oneOf in Swagger schema does not work

天大地大妈咪最大 提交于 2019-11-28 07:12:48
问题 I want to define PaymentMethod as below. Is oneOf supported in swagger.yaml? PaymentMethod: oneOf: - $ref: '#/definitions/NewPaymentMethod' - $ref: '#/definitions/ExistPaymentMethod' The ExistPaymentMethod will have just id, and cardNumber where NewPaymentMethod will have no id , but all other details, e.g. cardNumber , cardholderName , cardholderAddress etc. 回答1: oneOf is supported in OpenAPI version 3 ( openapi: 3.0.0 ), but not in Swagger version 2 ( swagger: '2.0' ). PaymentMethod: oneOf:

JSON Schema - specify field is required based on value of another field

独自空忆成欢 提交于 2019-11-28 06:45:18
Wondering if this is possible with schema draft 03. I've gotten dependencies working elsewhere, I think there is possibly just some creative use of them required in order to use them for specifying the required property of some field. My current best attempt (which doesn't work) should give you some idea of what I'm after. I want a value required by default, and optional when another field has a particular value. { "description" : "An address...", "type" : "object", "properties" : { "postcode": { "type" : "string", // postcode should be required by default "required" : true, // postcode

Validating JSON against Swagger API schema

倖福魔咒の 提交于 2019-11-28 06:44:24
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? Arnaud in the comments is correct that there are two separate questions here. Do you want to validate that your spec is a valid

JSON Schema for tree structure

匆匆过客 提交于 2019-11-28 05:22:36
问题 I have to build tree like structure of Json data.Each node has an id (an integer, required), a label (a string, optional), and an array of child nodes (optional). Can you help me how to write JSON schema for this Json data. I need to set Id as required in child node as well. { "Id": 1, "Label": "A", "Child": [ { "Id": 2, "Label": "B", "Child": [ { "Id": 5, "Label": "E" }, { "Id": 6, "Label": "E" }, { "Id": 7, "Label": "E" } ] }, { "Id": 3, "Label": "C" }, { "Id": 4, "Label": "D", "Child": [ {