jsonschema

Generate JSON Schema for ASP.Net Web API

陌路散爱 提交于 2019-12-03 12:07:35
I'm looking to generate JSON Schema for a WebAPI, including documentation from the XML comments. Its primarily so that I can then import that into our API docs (using apiary.io) I've managed to get a workaround solution by adding swagger (and swashbuckle) and then using the raw link on each service - but ideally I'd like something a bit cleaner, that works across all apis (this has to be done per service / controller), and didnt have so many dependencies. Before I go and look at how swagger is doing this and seeing if it can be extracted, would be good to know if there are existing ways to do

JSON Schema definition for array of objects

99封情书 提交于 2019-12-03 11:03:47
问题 I've seen this other question but it's not quite the same, and I feel like my issue is simpler, but just isn't working. My data would look like this: [ { "loc": "a value 1", "toll" : null, "message" : "message is sometimes null"}, { "loc": "a value 2", "toll" : "toll is sometimes null", "message" : null} ] I'm wanting to use AJV for JSON validation in a Node.js project and I've tried several schemas to try to describe my data, but I always get this as the error: [ { keyword: 'type', dataPath:

How to represent sum/union types in in json schema

喜欢而已 提交于 2019-12-03 10:58:51
I am trying to document an existing use of JSON using json-schema. The system permits the following two possabilities for one of the object attributes. Either { "tracking_number" : 123 } Or { "tracking_number" : [ 123, 124, 125 ] } How can I express this using json schema? Use anyOf to assert that the property must conform to one or another schema. { "type": "object", "properties": { "tracking_number": { "anyOf": [ { "$ref": "#/definitions/tracking_number" }, { "type": "array", "items": { "$ref": "#/definitions/tracking_number" } ] }, "definitions": { "tracking_number": { "type": "integer" } }

Generate Avro Schema from certain Java Object

戏子无情 提交于 2019-12-03 10:56:28
问题 Apache Avro provides a compact, fast, binary data format, rich data structure for serialization. However, it requires user to define a schema (in JSON) for object which need to be serialized. In some case, this can not be possible (e.g: the class of that Java object has some members whose types are external java classes in external libraries). Hence, I wonder there is a tool can get the information from object's .class file and generate the Avro schema for that object (like Gson use object's

How to specify a property as null or a reference?

心已入冬 提交于 2019-12-03 09:38:42
I have a json document in which a part can be either null or a subobject, like this: [{ "owner":null }, { "owner":{ "id":1 } }] The question is if its possible to model this in json schema draft v4 using ref? What I would like is something like this { "type":"object", "properties":{ "owner":{ "type":["null", "object"], "$ref":"#/definitions/id" } }, "definitions":{ "id":{ "type":"object", "properties":{ "id":{ "type":"number" } } } } } What you've posted should work, if you remove the "type":"object" from the definition. However, a neater, more explicit way to specify alternatives is to use

How to write a JSON schema for array of objects?

我的未来我决定 提交于 2019-12-03 08:32:14
问题 My JSON string would be formatted as: { "count":3, "data":[ { "a":{"ax":1} }, { "b":{"bx":2} }, { "c":{"cx":4} } ] } The data array contains many a and b and c . And no other kinds of objects. If count==0 , data should be an empty array [] . I'm using https://github.com/hoxworth/json-schema to validate such JSON objects in Ruby. require 'rubygems' require 'json-schema' p JSON::Validator.fully_validate('schema.json',"test.json") The schema.json is: { "type":"object", "$schema": "http://json

Generating JSON schema from C# class

独自空忆成欢 提交于 2019-12-03 06:38:57
问题 Is there any way to programmatically generate a JSON schema from a C# class? Something which we can do manually using http://www.jsonschema.net/ 回答1: Another option which supports generating JSON Schema v4 is NJsonSchema: var schema = JsonSchema4.FromType<Person>(); var schemaJson = schema.ToJson(); The library can be installed via NuGet. Update for NJsonSchema v9.4.3+: using NJsonSchema; var schema = await JsonSchema4.FromTypeAsync<Person>(); var schemaJson = schema.ToJson(); 回答2: For those

Should a RESTful API have a schema?

我只是一个虾纸丫 提交于 2019-12-03 06:38:34
问题 I was told recently that a proper RESTful API should define a schema for the resources representations it accepts and returns. For example XSD for XML and JSON Schema for JSON. However in all the books and articles on REST I went through this has never seem not only prominent, but even mentioned. Could someone provide some authoritative resources, to clarify if we should be providing schema when developing RESTful APIs? 回答1: You have to define and communicate the request and response

Generate JSON schema from java class

ぐ巨炮叔叔 提交于 2019-12-03 04:14:37
I have a POJO class public class Stock{ int id; String name; Date date; } Are there any annotations or development framework/api that can convert POJO to JSON schema like below {"id": { "type" : "int" }, "name":{ "type" : "string" } "date":{ "type" : "Date" } } and also i can expand the schema to add information like "Required" : "Yes", description for each field, etc., by specifying some annotations or configurations on POJO and can generate JSON Schema like below. {"id": { "type" : "int", "Required" : "Yes", "format" : "id must not be greater than 99999", "description" : "id of the stock" },

Only allow properties that are declared in JSON schema

自作多情 提交于 2019-12-03 04:09:19
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": { "type":"string", "minimum": 3 }, "title": { "type":"string", "minimum": 5 }, "description": { "type"