Skip to content
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

Implement tags for request params structs #248

Open
arturLim opened this issue Nov 13, 2018 · 3 comments
Open

Implement tags for request params structs #248

arturLim opened this issue Nov 13, 2018 · 3 comments
Labels

Comments

@arturLim
Copy link

Is your feature request related to a problem? Please describe.
In our scenario, we have an API server (which is available only internally) and a gateway service supporting frontend app. This way, we keep server side rendering on a node app, a business logic (fetching data from multiple APIs, etc) and number of APIs behind it.

Few API endpoints take a number of parameters that allow us to control the responses - think search page on any shop - you'll have search term, min and max price, category, etc.

Given the API spec, we (the client) know what we params we support, however should the API change, we still need to map params from incoming request to params in the API client. It would be nice, if we could use the struct to automatically map matching params.

Describe the solution you'd like
We would like to have tags set on each params struct.

For example, this is a struct that we have now (shortened it for clarity):

type GetProductParams struct {
	XAPICountry *string
	XAcceptVersion *string
        SomeParam *string
        SomeParam2 *string

	timeout    time.Duration
	Context    context.Context
	HTTPClient *http.Client
}

while this is something that we would expect - the tag is just example.

type GetProductParams struct {
	XAPICountry *string `swag:"X-API-Country,header"`
	XAcceptVersion *string `swag:"X-Accept-Version,header"`
        SomeParam *string `swag:"some_param,query"`
        SomeParam2 *string `swag:"some_param2,query"`

	timeout    time.Duration
	Context    context.Context
	HTTPClient *http.Client
}

Describe alternatives you've considered
The obvious alternative is to map the fields manually. If we do that, we also lose the advantage of using a client like swag, because updating API version still requires manual effort.

@pei0804
Copy link
Member

pei0804 commented Mar 20, 2019

sry. I can't imagine.
Which does protocol?

@arturLim
Copy link
Author

arturLim commented Mar 20, 2019

I'm sorry @pei0804, but I do not understand the question, could you elaborate on it?

@pei0804
Copy link
Member

pei0804 commented Mar 20, 2019

Sry. I can't understand due to don't know usecase.
How does client request? for example http request? and How does swag want to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants