-
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
Models get mixed when using structs from several packages #2783
Comments
I'm noticing the same issue on my side where we have models names similarly across packages. I got around this by using |
@josephspurrier indeed, but this is impossible if you are using structs that are from a third party library. |
Right. I was hoping this was going to fix my issue where I define structs using the same names in different packages, but unfortunately it doesn't. The "FinishResponse": {
"description": "Result of the operation.",
"schema": {
"$ref": "#/definitions/Response"
}
},
"StartResponse": {
"description": "Result of the operation.",
"schema": {
"$ref": "#/definitions/Response"
}
}, This is what each of my packages look like: // Package start_response
// swagger:response StartResponse
type swaggerResponse struct {
// in: body
Body Response
}
type Response struct {
// Required: true
Data *Data `json:"data"`
} // Package finish_response
// swagger:response FinishResponse
type swaggerResponse struct {
// in: body
Body Response
}
type Response struct {
// Required: true
Data *Data `json:"data"`
} |
Code from go-swagger@5905b47
Problem statement
When generating spec from code, using structs with the same name from different packages results in their model definitions getting mixed up. This is a major problem when integrating third party packages (e.g. Docker and Kubernetes in the same codebase).
Swagger specification
Steps to reproduce
In package A:
In package B:
In package C:
Then run:
swagger generate spec
.This will result in the
Test
model being added only once. Instead, the generation routine should start numbering the models.Why naming models explicitly doesn't work
When integrating third party data structures, the comments can't be applied to the codebase. This is the case when integrating Docker and Kubernetes, both have a model called
Volume
, which will result in the following error:Environment
swagger version: 0.29.0
go version: 1.18.2
OS: linux/amd64
The text was updated successfully, but these errors were encountered: