-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow different names for swagger specs #885
Conversation
For backwards compatibility, preserve the functionality of EchoWrapHandler but create new EchoWrapHandlerName which accepts a name parameter. See: swaggo/swag#885
3cf89d5
to
afa7d2c
Compare
In the case where we need to include multiple docs packages in the same process, swag.Register will fail. Despite looking like having support for swagger specs with different names it actually does not work. Define RegisterName and ReadDocName functions which allow you to specify the name of the swag. Default method will still use this path but with the 'classic' swag name of 'swagger'.
The CI fails for the same reason as the latest master commit. |
We need to investigate and rollback asap. Please be patient. |
Codecov Report
@@ Coverage Diff @@
## master #885 +/- ##
==========================================
- Coverage 84.83% 84.59% -0.25%
==========================================
Files 8 8
Lines 1649 1655 +6
==========================================
+ Hits 1399 1400 +1
- Misses 145 147 +2
- Partials 105 108 +3
Continue to review full report at Codecov.
|
Hi, is this waiting for me to add tests to restore the code coverage? |
+1 to this. I want to serve multiple swagger instances from one gin router. Currently swag.Register could only called once, no matter what name parameter is. This will require some changes in gin-swagger |
Yes. You introduced new code branches that are not covered by testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't introduce breaking changes.
} | ||
|
||
// ReadDocName reads swagger document with specific name. | ||
func ReadDocName(name string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the function signature is not an acceptable solution. This is a breaking change and breaks all other projects.
func ReadDoc() (string, error) {
to
func ReadDocName(name string) (string, error) {
func ReadDocName(name string) (string, error) { | ||
if swags == nil { | ||
return "", errors.New("no swag has yet been registered") | ||
} else if swag, ok := swags[name]; !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Race condition: searching in the swags
map without a mutex !
return "", errors.New("no swag has yet been registered") | ||
} else if swag, ok := swags[name]; !ok { | ||
return "", fmt.Errorf("no swag named \"%s\" was registered", name) | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use return instead if nested else.
@@ -309,6 +309,6 @@ func (s *s) ReadDoc() string { | |||
} | |||
|
|||
func init() { | |||
swag.Register(swag.Name, &s{}) | |||
swag.Register({{ printf "%q + %q" .Host .BasePath}}, &s{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the expected behavior In the event of many API applications don't have a Host and Basepath defined?
Closing: fixed in #1022! |
Describe the PR
In the case where we need to include multiple docs packages in the same
process, swag.Register will fail. Despite looking like having support
for swagger specs with different names it actually does not work.
Define RegisterName and ReadDocName functions which allow you to specify
the name of the swag. Default method will still use this path but with
the 'classic' swag name of 'swagger'.
Relation issue
None
Additional context
None