Fix/clone spec through json - #172
Merged
Merged
Conversation
cloneSpec went through gob, which omits a struct field holding the zero value for its type and flattens a pointer to what it points at. An optional number that was present and zero therefore came back nil: "minimum": 0, "maximum": 0, "multipleOf": 0, "maxLength": 0, "maxItems": 0 and "maxProperties": 0 were all dropped from the copy, at any depth and with no error. OrigSpec returns that copy, and ResetDefinitions writes it back over the live definitions. go-swagger marshals OrigSpec into SwaggerJSON, which it embeds in every generated server and loads again at runtime, so those constraints were missing from the specification a generated server serves. The clone now goes through jsonutils.FromDynamicJSON, as validate's own clone already does. It is cheaper too: measured in go-openapi/spec, round-tripping clickmeter.json costs 38.8ms, 11.8MB and 150k allocations through JSON against 46.6ms, 25.6MB and 222k through gob. The gob.Register calls in the package init go with it. spec registers the same two types in its own init, and spec is imported here, so a caller who encodes these types with gob still finds them registered. 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>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #172 +/- ##
==========================================
+ Coverage 83.82% 89.56% +5.73%
==========================================
Files 5 5
Lines 303 297 -6
==========================================
+ Hits 254 266 +12
+ Misses 31 30 -1
+ Partials 18 1 -17 ☔ 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