Skip to content

Fix/clone spec through json - #172

Merged
fredbi merged 2 commits into
go-openapi:masterfrom
fredbi:fix/clone-spec-through-json
Aug 25, 2026
Merged

fredbi merged 2 commits into
go-openapi:masterfrom
fredbi:fix/clone-spec-through-json

Conversation

@fredbi

@fredbi fredbi commented Aug 25, 2026

Copy link
Copy Markdown
Member

Change type

Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update

Short description

Fixes

Full description

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

fredbi and others added 2 commits August 25, 2026 20:23
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

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.56%. Comparing base (65cb02c) to head (862dc2b).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@fredbi
fredbi merged commit 6d3a812 into go-openapi:master Aug 25, 2026
22 checks passed
@fredbi
fredbi deleted the fix/clone-spec-through-json branch August 25, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant