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

Inline Definition ? #1936

Open
alexeightsix opened this issue Dec 4, 2024 · 0 comments
Open

Inline Definition ? #1936

alexeightsix opened this issue Dec 4, 2024 · 0 comments

Comments

@alexeightsix
Copy link

I'm defining my struct inside the function itself:

// CreateClient godoc
// @Summary      Create a new client
// @Tags         Client, Create
// @Produce      json
// @Consumes     json
// @Param        client body NewClientRequest true "Client object"
// @Success      200  {string}  string  "OK"
// @Router       /clients [post]
func (h *ClientHandler) handleCreateClient(c echo.Context) error {
	type NewClientRequest struct {
		FirstName   string `json:"first_name" validate:"required,alpha,min=2,max=50"`
		MiddleName  string `json:"middle_name" validate:"omitempty,alpha,min=0,max=50"`
		LastName    string `json:"last_name" validate:"required,alpha,min=2,max=50"`
		Phone       string `json:"phone" validate:"omitempty,e164"`
		DateOfBirth string `json:"date_of_birth" validate:"required,yyyy-mm-dd"`
	}

When parsing I get the following error unless I move the struct above the annotations.

:cannot find type definition: NewClientRequest

Is there a way to make this work? Can we add comments inside the function itself?

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

1 participant