-
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
Support embedded struct with json tag #886
Comments
Have you tried ?
|
Unfortunately I can't in my situation. When using sqlx the struct scanning doesn't handle nested structs it uses embedded instead. |
I have the same problem. Is there currently any way to solve this? |
Anyway, I think, swaggo has to respect the standard library json |
I just came across same problem. Using velero, structs have defined metadata as embeded, but as field in json - https:/vmware-tanzu/velero/blob/48d185985ab044a46dc91864a2fbd1f6430f56ee/pkg/apis/velero/v1/backup.go#L339 So it results as embeded in swagger docs, but as field in json, which is huge problem. |
Same problem here + an extra one. Problem 1. Embedded structs are flattened out in the parent struct in generated docs, even if in the real response they are notEmbedded structs (required when working with sql(x)):type Address struct {
ID uint64 `db:"id"`
StreetAddress string `db:"street_address"`
ZipCode string `db:"zip_code"`
City string `db:"city"`
Region string `db:"region"`
Country string `db:"country"`
TimeZoneID string `db:"time_zone_id"`
CreatedOn time.Time `db:"created_on"`
UpdatedOn time.Time `db:"updated_on"`
Version uint16 `db:"version"`
}
type Organization struct {
Address `db:"address" json:"Address"`
ID uint64 `db:"id"`
Name string `db:"name"`
CreatedOn time.Time `db:"created_on"`
UpdatedOn time.Time `db:"updated_on"`
Version uint16 `db:"version"`
} How they look in the generated docsHow they look in the actual HTTP responseProblem 2. Struct fields in Go and JSON are in PascalCase, but they are camelCase in the generated docs.ℹ️ There are no |
I submitted a PR for this, please test :) Note that there is a panic in the latest version (#1392) so you may have to build from the previous release instead https:/jgillich/swag/tree/prev |
Is your feature request related to a problem? Please describe.
Currently If you have an embded struct with a json tag, the json tag is ignored by swaggo. When marshaling to json normally it is not.
output (should also be the expected result for swaggo):
Currently with swaggo generation the result would be
which is not expected
Describe the solution you'd like
When using a custom type that has a embeded struct it should still read the json tag and generate the definition the same as my expected result above.
The text was updated successfully, but these errors were encountered: