1
votes

I have question about duplicating keys in schemas. This is example:

main.schema.json

{
    "$schema": "http://json-schema.org/draft-04/schema#", 

    "definitions": {
        "main.schema": {
            "properties": {
                "value": {
                    "description": "Status", 
                    "type": "boolean"
                }
            }, 
            "type": "object"
        }
    }, 
    "allOf": [
    {
        "$ref": "baseResource.json#/definitions/baseResource"
    }, 
    {
        "$ref": "#/definitions/main.schema"
    }
    ],
    "id": "main.schema.json#", 
    "required": [
        "value"
    ], 
    "title": "Title", 
    "type": "object"
}

baseResource.json

{
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "allOf": [
        {
            "$ref": "#/definitions/baseResource"
        }
    ], 
    "definitions": {
        "baseResource": {
            "properties": {
                "id": {
                    "description": "SomeDesc", 
                    "type": "string"
                }, 
                "value": {
                    "type": [
                        "string", 
                        "boolean"
                    ]
                }
            }, 
            "type": "object"
        }
    }, 
    "id": "baseResource.json#", 
    "required": [
        "id"
    ], 
    "title": "Base Resource", 
    "type": "object"
}

And what type of value is proper to this? Should value be only boolean (according to main schema) or can be boolean or string (reference to base Resource where that is correct). I'm using JSON validator that don't allow value to be anything else than boolean, I've searched a lot in JSON specyfication but there is no information about it.

1

1 Answers

1
votes

In this case, value must be a boolean.

The allOf statement means the JSON data must be valid against all of the listed schemas.

  • baseResouce requires value to be a string or a boolean
  • main.schema requires value to be a boolean

The only way for a JSON object to be valid against both of these schemas is if it is a boolean.