adds each server route to the EchoRouter. // Registers handlers, and prepends BaseURL to the paths, so that the paths // can be served under a prefix. func func { RegisterHandlersWithBaseURL(router, si, ) } wrapper := ServerInterfaceWrapper{ Handler: si, } router.GET(baseURL+ , wrapper.GetItems) router.POST(baseURL+ , wrapper.PostItems) router.DELETE(baseURL+ , wrapper.DeleteItem) router.GET(baseURL+ , wrapper.GetItem) router.PUT(baseURL+ , wrapper.PutItem) } RegisterHandlers RegisterHandlersWithBaseURL (router EchoRouter, si ServerInterface) (router EchoRouter, si ServerInterface, bas "" "/items" "/items" "/items/:id" "/items/:id" "/items/:id" この関数を使いつつ各ルートに 別々のmiddlewareを適用するには? →全体で使うmiddlewareを作り、 その中で適用するかを判断する
return nil * . { err = openapi3filter.ValidateRequest(requestContext, validationInput) err != { e := err.( ) { *openapi3filter.RequestError: errorLines := strings.Split(e.Error(), ) &echo.HTTPError{ Code: http.StatusBadRequest, Message: errorLines[ ], Internal: err, } } } } ValidateRequestFromContext echo HTTPError 0 (ctx echo.Context, router routers.Router, options *Options) // --snip-- // We've got a bad request // Split up the verbose error by lines and return the first one // openapi errors seem to be multi-line with a decent message on the first // --snip-- "\n" ValidateRequestFromContext
templateも使えQ c 追随するのが面倒なので程々に c OpenAPIのyamlをどう書いていく c 薄めの生成コードなので実装者がスキーマ定義を守る意識は必要 OpenAPIでのAPI定義から実装に落とし込む際に、まず試してみたい https://github.com/deepmap/oapi-codegen