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

Feature Proposal: Support arrays of objects to be merged in the "with" property

Ouverte
#14 2 commentaires 7 réactions 0 personnes assignées Voir sur GitHub
feature
Langage dominant
JavaScript
Étoiles
47
Forks
19
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Since the `$merge` operation does not concatenate or intersect arrays, but rather overwrites them wholesale, it is basically nonsensical for the top-level node under the `with` property of the `$merge` schema to be an array. For example, this would not produce a valid schema post merge:
```javascript
//Valid baseSchema
{
"$id": "baseSchema",
"type": "object",
"properties": {
"foo": {
"type": "number"
}
}
}

//Invalid merged schema
{
"$id": "schemaExtended",
"$merge": {
"source": { "$ref": "baseSchema.json#" },
"with": ["foo", "bar"]
}
}
}
```

Because this is the case, would it be possible to have the `with` property support an array, which would then be interpreted as a series of consecutive merges?

```javascript
{
"$id": "baseSchema",
"type": "object",
"properties": {
"foo": {
"type": "number"
}
}
}

//Cumbersome "nested" syntax for handling multiple merges, which is basically impossible to parse
{
"$id": "schemaExtended",
"$merge": {
"source": {
"$merge": {
"source": { "$ref": "baseSchema.json#" },
"with": {
"properties": {
"foo": {
"minimum": 0
},
"bar": {
"type": "string"
}
}
}
}
}
"with": {
"properties": {
"baz": {
"type": "boolean"
}
},
"additionalProperties": false
}
}
}

//Much cleaner syntax which mirrors the way _.extend and Object.assign work
{
"$id": "schemaExtended",
"$merge": {
"source": { "$ref": "baseSchema.json#" },
"with": [{
"properties": {
"foo": {
"minimum": 0
},
"bar": {
"type": "string"
}
}
}, {
"properties": {
"baz": {
"type": "boolean"
}
},
"additionalProperties": false
}]
}
}
```

Is there interest in implementing this? I doubt it would ever break existing functionality, since top-level arrays under `with` already always produce invalid schemas, and I think it would be pretty easy to implement. If this feels like something worth doing, I can submit a quick PR.

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.