Backwards compatibility flag for alias handling#3239
Backwards compatibility flag for alias handling#3239fredbi merged 3 commits intogo-swagger:masterfrom
Conversation
Signed-off-by: cce <51567+cce@users.noreply.github.com>
5c1a77b to
9817f93
Compare
fredbi
left a comment
There was a problem hiding this comment.
OK I understand the requirement. This is a good thing.
Could you please update the CLI doc which is published: docs/generate-spec/_index.md ?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3239 +/- ##
==========================================
+ Coverage 80.73% 80.95% +0.22%
==========================================
Files 64 64
Lines 13823 13869 +46
==========================================
+ Hits 11160 11228 +68
+ Misses 2075 2049 -26
- Partials 588 592 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
NOTE: RefAliases does not control whether aliases a recognized at all, but whether aliases are expanded or define their own model and referred to by $ref. |
fredbi
left a comment
There was a problem hiding this comment.
Another point: since you've changed the behavior for parameters and responses too, could you please add a test case that reasonably covers that part of the patch?
Signed-off-by: cce <51567+cce@users.noreply.github.com>
d1b52fa to
dde3ce6
Compare
|
Thanks, I think I've addressed your feedback with some more test fixtures and updated the docs. Also, thanks for developing and maintaining this tool! |
fredbi
left a comment
There was a problem hiding this comment.
Looks great. Thank you for this contribution.
Summary
Adds a new
--transparent-aliasesflag toswagger generate specthat makes type aliases completely transparent during spec generation. When enabled, aliases never create their own definitions in the swagger spec - references point directly to the underlying type instead.This provides a backwards compatibility option for projects that depend on stable swagger specs and were affected by the alias handling changes in #3227.
Motivation
PR #3227 improved Go 1.24 compatibility and added proper support for type aliases by creating swagger definitions for them. While this is the correct default behavior (aliases are distinct types in the API surface), it changed the generated swagger specs for existing codebases, which be disruptive.
Solution
The
--transparent-aliasesflag restores the pre-#3227 behavior where type aliases are treated as completely transparent to the spec generation process:Without flag (default):
Generates swagger with three definitions:
With
--transparent-aliases:Generates swagger with two definitions (UserID omitted):
Example
See
examples/alias-compatibility/for a minimal working example demonstrating the difference.Testing
Related
--with-expandflag (which expands all$refentries)--flattenoptionsRefAliasesscanner option (which controls whether aliases are expanded or define their own model and are referred to by $ref).