{"id":16750108,"url":"https://github.com/alexferl/echo-openapi","last_synced_at":"2025-10-06T14:28:30.109Z","repository":{"id":62867078,"uuid":"557002965","full_name":"alexferl/echo-openapi","owner":"alexferl","description":"OpenAPI middleware for the Echo framework","archived":false,"fork":false,"pushed_at":"2024-10-02T15:01:05.000Z","size":47,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-14T13:50:03.668Z","etag":null,"topics":["echo","echo-middleware","echo-openapi","labstack-echo","openapi","openapi3"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexferl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-24T23:08:22.000Z","updated_at":"2024-10-02T14:58:39.000Z","dependencies_parsed_at":"2024-06-19T05:19:58.041Z","dependency_job_id":"35a57db8-5d41-4eff-a3c8-81041b131d9c","html_url":"https://github.com/alexferl/echo-openapi","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fecho-openapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fecho-openapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fecho-openapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fecho-openapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexferl","download_url":"https://codeload.github.com/alexferl/echo-openapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225832421,"owners_count":17531188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["echo","echo-middleware","echo-openapi","labstack-echo","openapi","openapi3"],"created_at":"2024-10-13T02:27:05.148Z","updated_at":"2025-10-06T14:28:25.056Z","avatar_url":"https://github.com/alexferl.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# echo-openapi [![Go Report Card](https://goreportcard.com/badge/github.com/alexferl/echo-openapi)](https://goreportcard.com/report/github.com/alexferl/echo-openapi) [![codecov](https://codecov.io/gh/alexferl/echo-openapi/branch/master/graph/badge.svg)](https://codecov.io/gh/alexferl/echo-openapi)\n\nAn [OpenAPI](https://www.openapis.org/) middleware for the [Echo](https://github.com/labstack/echo) framework using\n[getkin/kin-openapi](https://github.com/getkin/kin-openapi) to validate HTTP requests and responses.\n\n## Installing\n```shell\ngo get github.com/alexferl/echo-openapi\n```\n\n## Using\n\n### Code example\n```go\npackage main\n\nimport (\n    \"net/http\"\n\n    mw \"github.com/alexferl/echo-openapi\"\n    \"github.com/labstack/echo/v4\"\n    \"github.com/labstack/echo/v4/middleware\"\n)\n\n/*\n# openapi.yaml\nopenapi: 3.0.4\ninfo:\n  version: 1.0.0\n  title: Test API\n  description: A test API\npaths:\n  /hello:\n    post:\n      description: Hello\n      parameters:\n        - name: message\n          in: query\n          required: true\n          schema:\n            type: string\n            minLength: 1\n            maxLength: 100\n      responses:\n        '200':\n          description: Successful response\n          content:\n            application/json:\n              schema:\n                type: object\n                additionalProperties: false\n                required:\n                  - message\n                properties:\n                  message:\n                    type: string\n                    description: Welcome message\n                    minLength: 4\n*/\n\ntype Handler struct {\n    *mw.Handler\n}\n\nfunc (h *Handler) Hello(c echo.Context) error {\n    msg := c.QueryParam(\"message\")\n    return h.Validate(c, http.StatusOK, echo.Map{\"message\": msg})\n}\n\nfunc main() {\n    e := echo.New()\n\n    h := \u0026Handler{mw.NewHandler()}\n    e.Add(http.MethodPost, \"/hello\", h.Hello)\n\n    e.Use(middleware.Logger())\n    e.Use(mw.OpenAPI(\"./openapi.yaml\"))\n\n    e.Logger.Fatal(e.Start(\"localhost:1323\"))\n}\n```\nSend an invalid request to test request validation:\n```shell\ncurl -i -X POST http://localhost:1323/hello\nHTTP/1.1 422 Unprocessable Entity\nContent-Type: application/json; charset=UTF-8\nDate: Sat, 12 Nov 2022 17:31:24 GMT\nContent-Length: 117\n\n{\"message\":\"Validation error\",\"errors\":[\"parameter 'message' in query has an error: value is required but missing\"]}\n```\n\nSend a valid request:\n```shell\ncurl -i -X POST http://localhost:1323/hello\\?message\\=hello\nHTTP/1.1 200 OK\nContent-Type: application/json\nDate: Sat, 12 Nov 2022 17:31:47 GMT\nContent-Length: 19\n\n{\"message\":\"hello\"}\n```\n\nSend a valid request with an invalid response:\n```shell\ncurl -i -X POST http://localhost:1323/hello\\?message\\=a\nHTTP/1.1 500 Internal Server Error\nContent-Type: application/json\nDate: Sat, 12 Nov 2022 17:31:01 GMT\nContent-Length: 36\n\n{\"message\":\"Internal Server Error\"}\n```\nYou should also have the following in the server's log to help you debug your schema:\n```shell\n{\"error\":\"failed validating response: message: minimum string length is 4\"}\n```\n\n### Configuration\n```go\ntype Config struct {\n    // Skipper defines a function to skip middleware.\n    Skipper middleware.Skipper\n\n    // Schema defines the OpenAPI that will be loaded and\n    // that the request and responses will be validated against.\n    // Required.\n    Schema string\n\n    // ContextKey defines the key that will be used to store the validator\n    // on the echo.Context when the request is successfully validated.\n    // Optional. Defaults to \"validator\".\n    ContextKey string\n\n    // ExemptRoutes defines routes and methods that don't require tokens.\n    // Optional.\n    ExemptRoutes map[string][]string\n}\n\ntype HandlerConfig struct {\n    // ContentType sets the Content-Type header of the response.\n    // Optional. Defaults to \"application/json\".\n    ContentType string\n\n    // ValidatorKey defines the key that will be used to read the\n    // *openapi3filter.RequestValidationInput from the echo.Context\n    // set by the middleware.\n    // Optional. Defaults to \"validator\".\n    ValidatorKey string\n\n    // ExcludeRequestBody makes Validate skips request body validation.\n    // Optional. Defaults to false.\n    ExcludeRequestBody bool\n\n    // ExcludeResponseBody makes Validate skips response body validation.\n    // Optional. Defaults to false.\n    ExcludeResponseBody bool\n\n    // IncludeResponseStatus makes Validate fail on response\n    // statuses not defined in the OpenAPI spec.\n    // Optional. Defaults to true.\n    IncludeResponseStatus bool\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexferl%2Fecho-openapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexferl%2Fecho-openapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexferl%2Fecho-openapi/lists"}