jsonschema

How to define UUID property in JSON Schema and Open API (OAS)

北城余情 提交于 2019-12-06 20:38:58
问题 When using JSON Schema and Open API specification (OAS) to document a REST API, how do I define the UUID property? 回答1: There's no built-in type for UUID, but the OpenAPI Specification suggests using type: string format: uuid From the Data Types section (emphasis mine): Primitives have an optional modifier property: format . OAS uses several known formats to define in fine detail the data type being used. However, to support documentation needs, the format property is an open string-valued

JSON Schema with dynamic key field in MongoDB

北城以北 提交于 2019-12-06 17:55:17
问题 Want to have a i18n support for objects stored in mongodb collection currently our schema is like: { _id: "id" name: "name" localization: [{ lan: "en-US", name: "name_in_english" }, { lan: "zh-TW", name: "name_in_traditional_chinese" }] } but my thought is that field "lan" is unique, can I just use this field as a key, so the structure would be { _id: "id" name: "name" localization: { "en-US": "name_in_english", "zh-TW": "name_in_traditional_chinese" } } which would be neater and easier to

how write json schema to show a property based on another property value using json-editor?

自古美人都是妖i 提交于 2019-12-06 17:47:27
I'm using Json-editor for creating a page to edit a json schema. I would like to set a property to be visible only if another property is set as true , for instance: property has_pets will rule the visibility of a pets array. I was not able to find anything, only enforcing the validation field. How can I write a schema definition to does not show a property based on another property value? 来源: https://stackoverflow.com/questions/51884859/how-write-json-schema-to-show-a-property-based-on-another-property-value-using-j

Using jsonschema to validate that a key has a unique value within an array of objects?

♀尐吖头ヾ 提交于 2019-12-06 11:26:32
How do I validate JSON, with jsonschema, that within an array of objects, a specific key in each object must be unique? For example, validating the uniqueness of each Name k-v pair should fail: "test_array": [ { "Name": "name1", "Description": "unique_desc_1" }, { "Name": "name1", "Description": "unique_desc_2" } ] Using uniqueItems on test_array won't work because of the unique Description keys. I found the alternative method of using a schema that allows arbitrary properties. The only caveat is that JSON allows duplicate object keys, but duplicates will override their previous instances. The

Generate XSD programmatically in java

拟墨画扇 提交于 2019-12-06 08:40:52
Is there any API to generate XSD programmatically in java. I need to generate XSD from Json-Schema ,I will read Json Schema and based on the elements i encounter during parsing need to create appropriate XSD elements. So if there is any API that can XSD elements it would help me in development process. I've used API's such as XSOM and Xerces XML Schema to parse XSD's, but their API's don't offer methods to programmatically generate XSD's. (I suppose you could try to access their internal implementations to somehow generate an XSD, but that would be at your own risk and probably ill-advised.)

How to reference external files with JSON.net?

泄露秘密 提交于 2019-12-06 07:17:31
Here is the error I am getting when JSON.net is trying to read my JSON schema ( return JsonSchema.Read(new JsonTextReader(reader)); ): 2014-07-15 15:33:42.7011 [Fatal] Newtonsoft.Json.JsonException: Could not resolve schema reference 'data-result.json'. at Newtonsoft.Json.Schema.JsonSchemaBuilder.ResolveReferences(JsonSchema schema) in c:\Development\Releases\Json\Work ing\Newtonsoft.Json\Src\Newtonsoft.Json\Schema\JsonSchemaBuilder.cs:line 139 at Newtonsoft.Json.Schema.JsonSchemaBuilder.ResolveReferences(JsonSchema schema) in c:\Development\Releases\Json\Work ing\Newtonsoft.Json\Src

How do you reference other property values in JSON schema?

末鹿安然 提交于 2019-12-06 05:37:07
问题 I have a JSON schema with 2 properties, minimumTolerance and maximumTolerance. I need to make sure that the value of maximumTolerance is not smaller than minimumTolerance & vice versa. Is this possible in JSON schema? Here is an example of what I'd like to be able to do: { "$schema": "http://json-schema.org/draft-06/schema#", "title": "MinMax", "description": "Minum & Maximum", "type": "object", "properties": { "minimumTolerance":{ "type": "number" "maximum":{ "$ref":"maximumTolerance" } }

Generating JsonSchema from pojo: how do I add “description” automatically?

末鹿安然 提交于 2019-12-06 03:42:44
问题 I am trying to automatically generate JsonSchema from pojos in my project: The code looks like this: ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(clazz, visitor); JsonSchema jsonSchema = visitor.finalSchema(); String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema); When clazz is defined like this: public class ZKBean { public String anExample; public int anInt; } I end

How to make json-schema to allow one but not another field?

我们两清 提交于 2019-12-06 03:02:47
问题 Is it possible to make jsonschema to have only one of two fields. For example, image if I want to have a JSON with ether start_dt or end_dt but not both of them at the same time. like this: OK { "name": "foo", "start_dt": "2012-10-10" } OK { "name": "foo", "end_dt": "2012-10-10" } NOT OK { "name": "foo", "start_dt": "2012-10-10" "end_dt": "2013-11-11" } What should I add to the schema: { "title": "Request Schema", "type": "object", "properties": { "name": { "type": "string" }, "start_dt": {

Validating json payload against swagger file - json-schema-validator

烈酒焚心 提交于 2019-12-06 02:07:18
I am trying to validate a json payload against a swagger file that contains the service agreement. I am using the json-schema-validator(2.1.7) library to achieve this, but at the moment it's not validating against the specified patterns or min/max length. Java Code: public void validateJsonData(final String jsonData) throws IOException, ProcessingException { ClassLoader classLoader = getClass().getClassLoader(); File jsonSchemaFile = new File (classLoader.getResource("coachingStatusUpdate.json").getFile()); String jsonSchema = new String(Files.readAllBytes(jsonSchemaFile.toPath())); final