Skip to content

When merging examples in allOf, merge entries by index, not concat

Snwachukwu requested to merge github/fork/ottomata/examples-merge into master

Created by: ottomata

When merging schemas, we can assume that The examples in each schema can each be merged together, so that the the merged example entries will validate against the final merged schema. By default, json-schema-merge-allof concats arrays to merge them, and JSONSchema examples is an array.

We want each element in each to-be-merged examples to be merged together, not concat-ed.

I.e. we want: merge(schemaA.examples[0], schemaB.examples[0])

NOT the default behavior: schemaA.examples.concat(schemaB.examples)

Before merging, we also reverse the candidate examples. We want to assume that schemas later in the allOf list have more complete and specific examples and want any final conflicting example values to take precedence.

This will make it easier to compose complete examples from included schemas, just like we allow with the schemas themselves.

Bug: T242454

Merge request reports