Implement schema patching (RFC 7386) #573
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements Schema patching
This PR introduces schema patching, allowing fine-grained modifications to JSON schemas
via a new
patchSchemaWith
key underonyxia-api
, similar to overwriting.Schema resolution now supports JSON Merge Patch (RFC 7386)
in addition to the existing
overwriteSchemaWith
and$ref
substitution mechanisms.Motivation
The existing overwriting mechanism completely replaces the JSON structure, which has several drawbacks:
By introducing a targeted JSON patching mechanism, users can specify only the values that need updating,
improving both readability and maintainability.
Corner cases
$ref
,rewriteSchemaWith
,patchSchemaWith
) are present,only the first available, in that order, is applied.
rewriteSchemaWith
nested within a patched object is processed first, followed by patching on the resolved JSONpatchSchemaWith
entries are applied from the innermost to the outermost level."key": null
(only valid in patches, not in schema files)Does not fail if the
"key"
is missing from the patched objectImplementation Notes
deepCopy()
by reconstructing a freshJsonNode
rewriteSchemaWith
,patchSchemaWith
) are removed from the final resolved schemaExample
The
input.json
schema below is resolved asoutput.json
whenthe
ingress.json
,enabled.json
,hostname.json
, andignored.json
filescan be retrieved from the
JsonSchemaRegistryService
.input.json
ingress.json
enabled.json
hostname.json
ignored.json
"I replace stuff with this string if I'm used anywhere"
output.json