You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When generating my swagger collection, where I use parameters in the headers, I encountered a problem. The generated code has an error. I'm using the fiber framework. Using a brute force method, I discovered that the error was also present for chi. But since the main direction is echo, I checked it too, there is no error in echo.
I have prepared a minimal version of the swagger yml with which you can reproduce the error
I placed the following code in the example-error.yml file
After doing this, you will probably be able to reproduce the problem. There will be an error on line 43 in the generated file fiber-server.gen.go
func (siw*ServerInterfaceWrapper) GetTest(c*fiber.Ctx) error {
varerrerror// Parameter object where we will unmarshal all parameters from the contextvarparamsGetTestParamsheaders:=c.GetReqHeaders()
// ------------- Required header parameter "TESTV" -------------ifvalue, found:=headers[http.CanonicalHeaderKey("TESTV")]; found {
varTESTV openapi_types.UUID// An error occurs here, we are passing value ([]string type), but it is expected (string type)err=runtime.BindStyledParameterWithLocation("simple", false, "TESTV", runtime.ParamLocationHeader, value, &TESTV)
iferr!=nil {
returnfiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter TESTV: %w", err).Error())
}
params.TESTV=TESTV
} else {
err=fmt.Errorf("Header parameter TESTV is required, but not found: %w", err)
returnfiber.NewError(fiber.StatusBadRequest, err.Error())
}
returnsiw.Handler.GetTest(c, params)
}
I suggest running the following code to generate echo server code
we get code with a similar situation, but the problem is solved, instead of a list, an element with a [0] index is passed to the function
// GetTest converts echo context to params.func (w*ServerInterfaceWrapper) GetTest(ctx echo.Context) error {
varerrerror// Parameter object where we will unmarshal all parameters from the contextvarparamsGetTestParamsheaders:=ctx.Request().Header// ------------- Required header parameter "TESTV" -------------ifvalueList, found:=headers[http.CanonicalHeaderKey("TESTV")]; found {
varTESTV openapi_types.UUIDn:=len(valueList)
ifn!=1 {
returnecho.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for TESTV, got %d", n))
}
// a similar function call, with correctly passed arguments and header valueserr=runtime.BindStyledParameterWithLocation("simple", false, "TESTV", runtime.ParamLocationHeader, valueList[0], &TESTV)
iferr!=nil {
returnecho.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter TESTV: %s", err))
}
params.TESTV=TESTV
} else {
returnecho.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter TESTV is required, but not found"))
}
// Invoke the callback with all the unmarshaled argumentserr=w.Handler.GetTest(ctx, params)
returnerr
}
I also want to thank you for developing oapi-codegen, I hope that the problem will be solved soon. Since I would like to use the fiber framework
When generating my swagger collection, where I use parameters in the headers, I encountered a problem. The generated code has an error. I'm using the fiber framework. Using a brute force method, I discovered that the error was also present for chi. But since the main direction is echo, I checked it too, there is no error in echo.
I have prepared a minimal version of the swagger yml with which you can reproduce the error
I placed the following code in the example-error.yml file
then to reproduce the error you need to run the following command to generate code
After doing this, you will probably be able to reproduce the problem. There will be an error on line 43 in the generated file fiber-server.gen.go
I suggest running the following code to generate echo server code
we get code with a similar situation, but the problem is solved, instead of a list, an element with a [0] index is passed to the function
I also want to thank you for developing oapi-codegen, I hope that the problem will be solved soon. Since I would like to use the fiber framework
example files.zip
The text was updated successfully, but these errors were encountered: