Fix/flatten spec bugs - #238
Merged
Merged
Conversation
A keyword the Swagger 2.0 model does not map - propertyNames, contains,
if/then/else, $defs - lands in spec.Schema.ExtraProps as raw JSON, and
analyzeSchema never looked there. Flatten imported the subtree holding such
a $ref and left the pointer untouched, so "#/definitions/leaf" ended up
naming a definition of the root document: nothing at all when the root had
no definition of that name, and an unrelated schema when it had one. The
second case validates, wrongly, and reports no error.
analyzeSchema now walks ExtraProps and records what it finds in
referenceAnalysis.unmappedRefs, keyed by the node holding the $ref
("#/definitions/deep/if/anyOf/0"). The index is deliberately kept out of
allRefs and schemas: AllRefs, AllReferences and AllDefinitionReferences
address schemas through the model, and a key naming a raw JSON node is of no
use to them or to what go-swagger builds on them. Their contents are
unchanged.
Flatten consults the new index where it has to: normalizeRef strips the
absolute base from those $ref too, importExternalReferences indexes them
alongside the mapped ones so the target is imported and named through
uniqifyName, importNewRef rebases them onto the document they came from, and
removeUnusedSinglePass counts them as a use - without that last one, the
definition just imported would be pruned again.
replace.UpdateRef gains two cases for raw JSON nodes. No spec-side change is
needed: jsonpointer hands back a copy of the any that holds the map, and a
copied map shares its storage, so writing to it reaches the document.
A document where a mapped $ref happens to pull the same target in was
already flattened correctly, by coincidence. Its output is unchanged.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi
force-pushed
the
fix/flatten-spec-bugs
branch
from
August 24, 2026 18:17
f149442 to
b7a8777
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #238 +/- ##
===========================================
+ Coverage 50.57% 94.24% +43.67%
===========================================
Files 17 29 +12
Lines 1750 3404 +1654
===========================================
+ Hits 885 3208 +2323
+ Misses 865 192 -673
- Partials 0 4 +4 ☔ View full report in Codecov by Harness. |
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.
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist