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

Query Params based on user defined struct #518

Closed
louis77 opened this issue Sep 13, 2019 · 5 comments
Closed

Query Params based on user defined struct #518

louis77 opened this issue Sep 13, 2019 · 5 comments

Comments

@louis77
Copy link

louis77 commented Sep 13, 2019

Is your feature request related to a problem? Please describe.
We have many endpoints sharing the same huge set of query parameters. I tried to declare it like this:
// @param params query model.FilterParams false "..."

However this doesn't work. So we have to copy/paste about 30 lines of params over 15 different endpoints. Is it possible to implement @param to use a user defined struct?

Describe the solution you'd like
// @param params query model.FilterParams false "..."

Describe alternatives you've considered
I see no alternative :-)

@letsfire
Copy link

letsfire commented Oct 2, 2019

I think this is a useful feature

@sdghchj
Copy link
Member

sdghchj commented Jan 3, 2020

Feature added, try latest master branch.
Reopen it if you have any more questions.

@sdghchj sdghchj closed this as completed Jan 3, 2020
@movpushmov
Copy link

movpushmov commented Sep 9, 2022

@sdghchj can you provide an example? This don't work:

type Params struct {
	test string
	anotherTest int32
}

// ListAccounts godoc
// @Summary      List accounts
// @Description  get accounts
// @Tags         accounts
// @Accept       json
// @Produce      json
// @Param        params  query  Params false "..."
// @Success      200  {array}   Account
// @Router       /accounts [get]
func test() {}

@muya
Copy link

muya commented Sep 25, 2022

@movpushmov

Something similar to this is working for me:

// QueryListOptions represents the query parameters for a list of resources.
type QueryListOptions struct {  
   // The page number to return.  
   Page int `json:"page" minimum:"1" validate:"optional" example:"1"`  
   // The number of items to return per page.  
   PageSize int `json:"page_size" minimum:"1" maximum:"20" validate:"optional" example:"10"`   
}

// @Summary     Some Endpoint
// @Produce     json
// @Param       request             query    QueryListOptions false "Query Params"
func someHandler() {

}

It has generated this
screenshot-20220925-142216

@kahunacohen
Copy link

I don't see this in the docs, unless I'm mistaken. Would you like a PR?

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

No branches or pull requests

6 participants