add option to select custom struct tag for spec-generation #2806
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi All,
First, thanks for this library. It makes many things easier to implement.
I'm using go-swagger to generate swagger files from the code for almost 3 years. I've been searching for a way to provide custom names other than JSON tag and field name for a while. I thought that providing a custom struct tag while generating spec would be awesome.
Example:
Let's say I've struct like
I'm decoding the request according to the
json, header, query
tags. But I have to add the JSON tag toXForwardedFor
field to show it in the swagger with the correct name. In this scenario, the client can override the XForwardedFor header by sendingX-Forwarded-For
field in the body. I think--struct-tag
option can be useful in anyways.Usage:
swagger generate spec -o ./docs/swagger.yaml --scan-models -w ./examples/generated --struct-tag swg
With
--struct-tag swg
struct will look likeSigned-off-by: furkan fufuceng@gmail.com