json-editor
json-editor copied to clipboard
Required for boolean forces a true value or validation fails
This is my schema below
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"model": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"plural": {
"type": "string"
},
"fields": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"boolean",
"date-iso8601",
"date-time-iso8601",
"decimal",
"double",
"integer",
"long",
"object",
"string",
"unit",
"uuid"
]
},
"description": {
"type": "string"
},
"required": {
"type": "boolean"
},
"default": {
"type": "string"
},
"minimum": {
"type": "integer"
},
"maximum": {
"type": "integer"
},
"deprecation": {
"$ref": "#/definitions/deprecation"
}
},
"required": [
"name",
"type",
"required"
]
},
"minItems": 1,
"uniqueItems": true
}
}
},
"deprecation": {
"type": "object",
"properties": {
"description": {
"type": "string"
}
}
},
"enum": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"plural": {
"type": "string"
},
"description": {
"type": "string"
},
"values": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"deprecation": {
"$ref": "#/definitions/deprecation"
}
},
"required": [
"name"
]
},
"minItems": 1,
"uniqueItems": true
},
"deprecation": {
"$ref": "#/definitions/deprecation"
}
},
"required": [
"name",
"values"
]
},
"union": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"plural": {
"type": "string"
},
"discriminator": {
"type": "string"
},
"description": {
"type": "string"
},
"types": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": "string"
},
"description": {
"type": "string"
},
"deprecation": {
"$ref": "#/definitions/deprecation"
},
"required": [
"type"
]
},
"minItems": 2,
"uniqueItems": true
}
},
"required": [
"name",
"types"
]
},
"response": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"description": {
"type": "string"
},
"deprecation": {
"$ref": "#/definitions/deprecation"
}
},
"required": [
"type"
]
},
"resource": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"description": {
"type": "string"
},
"operations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"method": {
"type": "string",
"enum": [
"GET",
"POST",
"PUT",
"DELETE"
]
},
"path": {
"type": "string"
},
"description": {
"type": "string"
},
"body": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"description": {
"type": "string"
},
"deprecation": {
"$ref": "#/definitions/resourceItem"
}
},
"required": [
"type"
]
},
"parameters": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"location": {
"type": "string"
},
"description": {
"type": "string"
},
"deprecation": {
"$ref": "#/definitions/deprecation"
},
"required": {
"type": "boolean"
},
"default": {
"type": "string"
},
"example": {
"type": "string"
},
"minimum": {
"type": "integer"
},
"maximum": {
"type": "integer"
}
}
},
"required": [
"name",
"type",
"required"
],
"minItems": 1
},
"responses": {
"type": "object",
"patternProperties": {
"[0-9]{3}": {
"$ref": "#/definitions/response"
}
}
}
},
"required": [
"method"
],
"minItems": 1
}
},
"deprecation": {
"$ref": "#/definitions/deprecation"
}
},
"required": [
"operations"
]
}
},
"type": "object",
"properties": {
"name": {
"type": "string"
},
"apidoc": {
"type": "object",
"properties": {
"version": {
"type": "string"
}
}
},
"info": {
"type": "object",
"properties": {
"contact": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"url": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"license": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"url": {
"type": "string"
},
"required": [
"name"
]
}
}
}
},
"namespace": {
"type": "string"
},
"base_url": {
"type": "string"
},
"description": {
"type": "string"
},
"imports": {
"type": "array",
"items": {
"type": "object",
"properties": {
"uri": {
"type": "string"
}
}
}
},
"headers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"required": {
"type": "boolean"
},
"default": {
"type": "string"
},
"description": {
"type": "string"
},
"deprecation": {
"$ref": "#/definitions/deprecation"
}
},
"required": [
"name",
"type",
"required"
]
}
},
"enums": {
"type": "object",
"patternProperties": {
"[A-Za-z]": {
"$ref": "#/definitions/enum"
}
}
},
"models": {
"type": "object",
"patternProperties": {
"[A-Za-z]": {
"$ref": "#/definitions/model"
}
}
},
"unions": {
"type": "object",
"patternProperties": {
"[A-Za-z]": {
"$ref": "#/definitions/union"
}
}
},
"resources": {
"type": "object",
"patternProperties": {
"[A-Za-z]": {
"$ref": "#/definitions/resource"
}
}
}
},
"required": [
"name"
]
}
When I create an item under models
there is a required field called... required
. The value is a boolean, if I set it to false, the validation fails. It passes if I set it to true.
I've a running example here: https://nemo83.github.io/apidoc-editor/
Is this an issue?
I am also facing this issue.
hey, to fix issue:
find if(!result[i]) delete result[i];
and replace with if(typeof result[i] === 'undefined' || result[i] === '' || (result[i] !== null && Object.keys(result[i]).length == 0 && result[i].constructor == Object)) delete result[i];