fix: resolve cross-file discriminator mapping references - #115
Merged
Merged
Conversation
`discriminator.mapping` and `defaultMapping` values are URI references that live outside the JSON Schema vocabulary, so the schema compiler never saw them. Planning resolved them lazily after the compiled graph had been rebased onto portable identifiers, so any relative or cross-file value failed with `invalid_discriminator_mapping` even though the same URI worked in `$ref`. Mapping values were also resolved relative to the union schema rather than the schema that owns the discriminator. The schema engine gains a generic `extra_references` compilation hook: callers name additional reference strings inside schema objects, keyed by a JSON Pointer relative to the schema. They are resolved like `$ref` before rebasing, retrieving target resources when needed, and recorded in the reference table. Failures to retrieve or resolve them are recorded for `reference_failure` instead of aborting compilation; retrieved documents that fail to compile stay fatal. Rebasing carries the bindings and failures across and rewrites the resolved strings. Normalization declares URI-shaped mapping values through the hook (bare schema names are left alone per OAS 3.1.1), and planning reads the recorded binding for the discriminator owner's node, reporting recorded failures as located diagnostics. Fixes #114
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #114.
Problem
Normalization rebases the compiled schema graph onto synthetic portable identifiers.
$reftargets survive because the compiler resolves them before the rebase and records them in its reference table.discriminator.mappinganddefaultMappingvalues are not JSON Schema keywords, so the compiler never saw them; planning resolved them lazily after the rebase, against the synthetic base, so any relative or cross-file value failed withinvalid_discriminator_mapping. Mapping values were also resolved relative to the union schema rather than the schema that owns thediscriminator.Changes
src/schema_engine/compiled.jl: genericextra_referenceshook on the compiler constructors. It is called with each scanned schema object and returns(pointer, reference)pairs, with the pointer relative to that schema object. Pairs are resolved like$ref, retrieving files as needed, and recorded under the pointer key. They are optional: retrieval or resolution failures land in a newreference_failurestable (read throughreference_failure) instead of aborting compilation. A retrieved document that fails to compile stays fatal. The engine stays OpenAPI-agnostic.src/schema_engine/rebase.jl: carries bindings and failures across the rebase and rewrites pointer-keyed reference strings in the rebased documents, so serialized specs use only portable ids.src/normalize.jl: declares URI-shapedmapping/defaultMappingvalues through the hook. Bare names such asCatare left alone, following the OAS 3.1.1 rule that ambiguous values are schema names and./Catforces a URI reference.src/planning.jl:_discriminator_targetreads the recorded binding keyed by the discriminator owner's node, reports recorded failures asinvalid_discriminator_mapping/invalid_discriminator_defaultwith the retrieval message, and falls back to same-document lookup for values the compiler was not asked about.models.md,pipeline.md.Tests
$refand broken retrieved documents remain fatal.schemas/, mapping values mixing whole-file, empty-fragment and pointer-fragment targets; generated client decodes all variants and rejects a mismatched body;allOfinheritance layout plans; a typo'd file yields a diagnostic naming the missing file.Verification
OPENAPI_CORPUS_TESTS=allon Julia 1.12 (Petstore, Discord, Stripe, GitHub): pass.git diff --check: clean.Notes
feline: Cat) behave exactly as before; supporting them is a possible follow-up.