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

Allow mix of body input and param input #45

Closed
snicol opened this issue Sep 5, 2022 · 1 comment
Closed

Allow mix of body input and param input #45

snicol opened this issue Sep 5, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@snicol
Copy link

snicol commented Sep 5, 2022

Due to this check and potentially missing implementation, a mix of JSON/XML bodies along with other directives is not possible.

This blocks common REST calls, for example creating/updating entities (POST /entity/:id/PUT /entity/:id), where you wish to decode both the URL param :id and the incoming JSON body into a single struct.

@ggicci
Copy link
Owner

ggicci commented Sep 8, 2022

Hi @snicol , actually httpin does support mixing body input and param input currently. We can use the body directive along with other param input related directives. Let's see an example:

type UpdateUserInput struct {
	ID      string `in:"path=id"` // NOTE: register a path directive before using
	Payload struct {
		Display string `json:"display"`
		Email   string `json:"email"`
		IsAdmin bool   `json:"is_admin"`
	} `in:"body=json"`
}

Please checkout a runable demo here https://go.dev/play/p/kDHljK4PbGF

So, the problem here is that the Body Annotations don't support a mix. I think it's okay now, I will update the docs and make it more clear. Thanks for the report :)

@ggicci ggicci added the documentation Improvements or additions to documentation label Sep 8, 2022
@ggicci ggicci closed this as completed Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants