ajv-validator / ajv-merge-patch

$merge and $patch keywords for Ajv JSON-Schema validator to extend schemas
https://ajv.js.org
MIT License
46 stars 17 forks source link

$ref to definitions inside “source” or “with” parts of $merge is not supported #28

Open gallofeliz opened 5 years ago

gallofeliz commented 5 years ago

Hi,

When the "with" object contains definitions (like '"$ref": "#/definitions/JwtConfig"'), ajv throws an error.

I need to move the "with" "definitions" property to the main object :

            {
                $merge: {
                    source
                    with
                },
                definitions
            }

I think it's an issue :)

Regards

epoberezkin commented 5 years ago

Please add a specific example that you expect to work.

gallofeliz commented 5 years ago

Something like :

var source = {
    type: 'object',
    properties: {
        parking: {
            type: 'object',
            properties: {
                cars: {
                    type: 'array',
                    items: { $ref: '#/definitions/car' }
                }
            }
        }
    },
    definitions: {
        car: {
            type: 'object',
            properties: {
                color: {
                    type: 'string'
                }
            }
        }
    }
}

var with = {
    type: 'object',
    properties: {
        cage: {
            type: 'object',
            properties: {
                birds: {
                    type: 'array',
                    items: { $ref: '#/definitions/bird' }
                }
            }
        }
    },
    definitions: {
        bird: {
            type: 'object',
            properties: {
                color: {
                    type: 'string'
                }
            }
        }
    }
}

var final = {
    $merge: {
        source,
        with
    }
}
epoberezkin commented 5 years ago

yes, definitions have to be outside of the merge (and you can use merge inside definitions

nwinch commented 5 years ago

yes, definitions have to be outside of the merge (and you can use merge inside definitions

Is there an example anywhere of how this looks? I've tried the following (mock example) but it doesn't seem to work. Do I have definitions at the correct level (parallel to $merge) ?

{
  "id": "lixi-internal-request-custom",
  "$merge": {
    "source": { "$ref": "lixi-internal-request" },
    "with": {
      "properties": {}
    }
  },
  "definitions": {
    "ID": {
      "pattern": "^[a-zA-Z0-9_][a-zA-Z0-9-_.]*$"
    }
  }
}
gallofeliz commented 5 years ago

Sorry but this is nothing logic. I did want to merge to entities, if I need to put definitions in another section, I do the merge myself ... And in the last case it's the same, to have définitions of a $ref is understandable as $ref should declare its own definitions.

Sorry but Not Logic.

Le jeu. 14 nov. 2019 03:28, Nathan Winch notifications@github.com a écrit :

yes, definitions have to be outside of the merge (and you can use merge inside definitions

Is there any example anywhere of how this looks? I've tried the following (mock example) but it doesn't seem to work. Do I have definitions at the correct level (parallel to $merge) ?

{ "id": "lixi-internal-request-custom", "$merge": { "source": { "$ref": "lixi-internal-request" }, "with": { "properties": {} } }, "definitions": { "ID": { "pattern": "^[a-zA-Z0-9][a-zA-Z0-9-.]*$" } } }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/epoberezkin/ajv-merge-patch/issues/28?email_source=notifications&email_token=AJU4UFQNKHYOBVQDKA5EAPTQTSZWHA5CNFSM4GOOWL4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEALQHA#issuecomment-553695260, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJU4UFQSW5VW3MO23RN4XNTQTSZWHANCNFSM4GOOWL4A .