Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

$ref doesn't work in document root schema #185

@dashameter

Description

@dashameter

Creating a document using JSON:

{
    "note": {
        "$ref": "#/definitions/msg"
    },
    "definitions": {
        "msg": {
            "required": [
                "timestamp"
            ],
            "properties": {
                "timestamp": {
                    "type": "number"
                },
                "description": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        }
    }
}

and setting definitions via

        const definitions = json.definitions;
        delete json.definitions;
        const contract = await platform.contracts.create(json, identity);
        contract.setDefinitions(definitions);
        await platform.dpp.dataContract.validate(contract);

dpp.dataContract.validate(contract) throws


TypeError: Cannot set property '$id' of undefined
    at enrichDataContractWithBaseSchema.js:43
    at Array.forEach (<anonymous>)
    at enrichDataContractWithBaseSchema.js:42
    at Array.forEach (<anonymous>)
    at i (enrichDataContractWithBaseSchema.js:28)
    at c.g [as validateDataContract] (validateDataContractFactory.js:59)

contract.JSON() as output by browser debug console (since node version is broken):

contract: DataContract
definitions:
msg:
additionalProperties: false
properties:
description: {type: "string"}
timestamp: {type: "number"}
required: Array(1)
0: "timestamp"
length: 1
documents:
note:
$ref: "#/definitions/msg"
entropy: "yd8ob63kZQ2c2aKsBgAcsik9SvC6xpLzoZ"
id: "2DEBGqaZDhxA8JSmdvsGUzucW7GLUzDtJKRzkN3teJZy"
ownerId: "32EfBxtPmTDSmdohuRFJ6EUTm92WPgyVojFrxyW9rKbi"
schema: "https://schema.dash.org/dpp-0-4-0/meta/data-contract"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions