jsonschema

AJV always returns true

徘徊边缘 提交于 2021-01-29 18:00:21
问题 Why does the validate function always return true even if the object is wrong? const Ajv = require('ajv') const ajv = new Ajv() const schema = { query: { type: 'object', required: ['locale'], properties: { locale: { type: 'string', minLength: 1, }, }, }, } const test = { a: 1, } const validate = ajv.compile(schema) const valid = validate(test) console.log(valid) // TRUE What is wrong with my code? It is a basic example. 回答1: An empty schema is either {} or an object which none of its keys

How to display default value in JSON Schema using Jackson

北战南征 提交于 2021-01-29 06:26:18
问题 I am using Jackson to create json schema. I want to display property with their default value in json schema. I tried @JsonProperty annotation with default attribute but still default value is not being display on the json schema. I am using following code to generate Json Schema: ObjectMapper mapper = new ObjectMapper(); JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper); JsonSchema schema = null; try { schema = schemaGen.generateSchema(RootTemplate.class); System.out.println

react-jsonschema-form How to use it via cdn?

余生长醉 提交于 2021-01-28 21:15:10
问题 I am trying to use this library "react-jsonschema-form" to create forms using react and jsonschema. I am trying to use it in my project as described in the example from the website by including the .js file via cdn. It is not working. The exported component "Form" is undefined. I had a look at this similar question Using React component from js source maps but I could not understand the solution offered. I am supposed to alias the default export of JSONSchemaForm. But what is JSONSchemaForm?

json schema object property constraints

北战南征 提交于 2021-01-28 19:53:43
问题 In my schema I have an array of phone objects. Each object has a "status" property, which can be one of three values: "Primary", "Active" and "Not-in-use". I want to set the following constraint: If the number of phone objects > 0 then exactly one must have status="Primary" Is this possible with json schema? If so, how? 回答1: This schema is pretty close to what you want. The only restriction is that the "Primary" phone number needs to be the first item in the array. You might be able to get

MongoError: Document failed validation - How to insert both float and int into the same field - which is marked as double?

寵の児 提交于 2021-01-28 14:45:44
问题 I'm having problems with inserting into mongoDB because good objects don't pass the mongoDB validator . To make it worse, the error is a generic: Document failed validation which in a big multi-nested object can make things confusing regarding where exactly this validation fails. myValidatorIs = { validator: { $jsonSchema : { bsonType: "object" , required: [ "price" ] , properties: { price: { bsonType: "double" // price needs to be a double, tried with decimal also. , description: "must be a

MongoError: Document failed validation - How to insert both float and int into the same field - which is marked as double?

江枫思渺然 提交于 2021-01-28 14:45:33
问题 I'm having problems with inserting into mongoDB because good objects don't pass the mongoDB validator . To make it worse, the error is a generic: Document failed validation which in a big multi-nested object can make things confusing regarding where exactly this validation fails. myValidatorIs = { validator: { $jsonSchema : { bsonType: "object" , required: [ "price" ] , properties: { price: { bsonType: "double" // price needs to be a double, tried with decimal also. , description: "must be a

Is it valid json (schema) to say that an element can be a single item or an array

浪尽此生 提交于 2021-01-28 06:22:01
问题 Is it possible to specify that a particular json value can be either a single element or an array? E.g. Can both of following json documents be valid according to a given single json schema. "person": { "name": "john", "friends": "jack" } "person": { "name": "john", "friends": ["jack", "jill"] } It's certainly possible (I believe) if you ignore the concept of schema, and simply when you are parsing using a parser such as rapidjson, to simply check if the element is an array or not before

Two way binding dependences based on enum value in json schema

可紊 提交于 2021-01-28 02:21:41
问题 I have a senior were I have to validate the schema for below json data. { 'userId': 123, 'userType': CUSTOMER } Information about JSON: Were userId is an integer and the userType is enum ['Customer','Admin','Guest'] So the issue is that I want to validate the JSON data from the JSON schema based on : If userId is present then userType is required. If userType ['Customer','Admin'] is present but userId is not then it should not validate the JSON data. But if the userType is ['Guest'] then

Apply required field to referenced JSON data schema

无人久伴 提交于 2021-01-28 00:54:20
问题 I have the following use-case I try to solve with JSON schemas. I have a generic JSON data schema for, for example, a user. Here is an example of the user.schema.json file. { "type": "object", "definitions": {}, "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "name": { "type": "string", "minLength": 1 }, "email": { "type": "string", "minLength": 1 }, "locale": { "type": "string", "minLength": 1 }, "active": { "type": "boolean", "default": true }, "password": { "type":

How do JSON schema's anyOf type translate to typescript?

廉价感情. 提交于 2021-01-21 09:58:09
问题 Let's say we have a schema like this (I borrowed the OpenAPI 3.0 format but I think the intention is clear): { "components": { "schemas": { "HasName": { "type": "object", "properties": { "name": { "type": "string" } } }, "HasEmail": { "type": "object", "properties": { "email": { "type": "string" } } }, "OneOfSample": { "oneOf": [ { "$ref": "#/components/schemas/HasName" }, { "$ref": "#/components/schemas/HasEmail" } ] }, "AllOfSample": { "allOf": [ { "$ref": "#/components/schemas/HasName" },