ajv-validator / ajv-validator/ajv-merge-patch

Nested merge and patch

Ouverte
#21 4 commentaires 1 réaction 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
47
Forks
19
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Hi,

I'm not sure if this is an issue with my understand of the spec or not. I understand merge a lot better than patch and so I'd like to use it where possible and then patch things I can't fix with merge. However, I'm having difficulty applying a patch to a schema who's source I apply a merge:

deliver.json
```json
{
"type": "object",
"definitions": {
"settings": {
"type": "object",
"properties": {
"country": {
"type": "array",
"items": { "type": "string" }
},
"client": {
"type": "array",
"items": {
"type": "string",
"enum": ["mobile", "desktop"]
}
}
},
"additionalProperties": false
}
},
"properties": {
"include": { "$ref": "#/definitions/settings" },
"exclude": { "$ref": "#/definitions/settings" },
"templateParameters": {
"type": "object",
"required": [],
"patternProperties": {
".*": { "type": "string" }
}
},
"expire": { "type": "string", "format": "date" }
},
"required": [],
"additionalProperties": false
}
```

and my new schema:

x.json
```json
{
"$patch": {
"source" : {
"$merge": {
"source": { "$ref": "deliver.json" },
"with": {
"properties": {
"templateParameters": {
"properties": {
"link": { "type": "string" }
},
"required": ["link"]
}
},
"required": ["templateParameters"]
}
}
},
"with": [{
"op": "replace",
"path": "/properties/include/properties/client/items",
"value": { "type": "string", "enum": [ "alpha", "bravo" ] }
}]
}
}
```

I get the error message:

```javascript
{ [OPERATION_PATH_UNRESOLVABLE: Cannot perform the operation at a path that does not exist]
message: 'Cannot perform the operation at a path that does not exist',
name: 'OPERATION_PATH_UNRESOLVABLE',
index: 0,
operation:
{ op: 'replace',
path: '/properties/include/properties/client/items',
value: { type: 'string', enum: [Array] } },
tree: { '$merge': { source: [Object], with: [Object] } } }
```

Is this expected? I'm not sure if this kind of thing is allowed under the specification but if it were then I think the order the transformations are applied would need to be altered.

Thanks

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.