{"id":43007812,"url":"https://github.com/vihuvac/go-openapi-validator","last_synced_at":"2026-01-31T05:03:56.802Z","repository":{"id":331189052,"uuid":"1125622378","full_name":"vihuvac/go-openapi-validator","owner":"vihuvac","description":"Framework-agnostic OpenAPI v3 validator for Go. High-performance validation of requests (body, params, headers) and responses. Supports net/http, Gin, and Gorilla Mux. Includes zero-config Swagger UI, custom errors, and zero external test deps. Lean, reliable, production-ready.","archived":false,"fork":false,"pushed_at":"2025-12-31T07:53:02.000Z","size":108,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-04T06:28:57.232Z","etag":null,"topics":["golang","openapi","swagger","swagger-ui"],"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/vihuvac.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-31T03:59:56.000Z","updated_at":"2026-01-01T20:39:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/vihuvac/go-openapi-validator","commit_stats":null,"previous_names":["vihuvac/go-openapi-validator"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/vihuvac/go-openapi-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihuvac%2Fgo-openapi-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihuvac%2Fgo-openapi-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihuvac%2Fgo-openapi-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihuvac%2Fgo-openapi-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vihuvac","download_url":"https://codeload.github.com/vihuvac/go-openapi-validator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihuvac%2Fgo-openapi-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28929865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T04:05:25.756Z","status":"ssl_error","status_checked_at":"2026-01-31T04:02:35.005Z","response_time":128,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","openapi","swagger","swagger-ui"],"created_at":"2026-01-31T05:03:56.749Z","updated_at":"2026-01-31T05:03:56.795Z","avatar_url":"https://github.com/vihuvac.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./docs/images/logo.webp\" width=\"300px\" alt=\"Go OpenAPI Validator Logo\" style=\"border-radius: 8px;\" /\u003e\n  \u003ch1\u003eGo OpenAPI Validator\u003c/h1\u003e\n  \u003cp\u003e\n    \u003cb\u003eA framework-agnostic OpenAPI v3 validator for Go, designed for performance and reliability.\u003c/b\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Go-v1.25+-00ADD8.svg?logo=go\u0026logoColor=white\" alt=\"Go Version\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" alt=\"License\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/OpenAPI-3.x-green\" alt=\"OpenAPI Version\" /\u003e\n    \u003cbr/\u003e\n    \u003cimg src=\"https://github.com/vihuvac/go-openapi-validator/actions/workflows/test.yml/badge.svg\" alt=\"Tests Status\" /\u003e\n    \u003cimg src=\"https://codecov.io/gh/vihuvac/go-openapi-validator/branch/main/graph/badge.svg\" alt=\"Coverage\" /\u003e\n    \u003cbr/\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Security%20Policy-Active-success\" alt=\"Security Policy\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Code%20of%20Conduct-Contributor%20Covenant-yellow\" alt=\"Code of Conduct\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/PRs-welcome-brightgreen.svg\" alt=\"PRs Welcome\" /\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n---\n\n## 📖 Overview\n\n**Go OpenAPI Validator** is a high-performance, framework-agnostic library for validating HTTP requests and responses against **OpenAPI v3** specifications. Inspired by [express-openapi-validator](https://github.com/cdimascio/express-openapi-validator), it provides a robust middleware layer that ensures your API remains consistent with its documentation.\n\nWe focus on minimalism and reliability, with **zero external testing dependencies** and a lean footprint.\n\n## ✨ Key Features\n\n- **🚀 Framework Agnostic**: Native support for `net/http`, [Gorilla Mux](https://github.com/gorilla/mux), and [Gin](https://github.com/gin-gonic/gin).\n- **🛡️ Request Validation**: Automatic validation of request bodies, query parameters, and headers.\n- **✅ Response Validation**: Optional outgoing response validation to catch implementation errors.\n- **📄 Swagger UI**: Built-in, zero-config Swagger UI integration served at `/docs`.\n- **🧪 Professional Grade**: Comprehensive test suite using only the Go standard library.\n- **⚙️ Highly Configurable**: Custom error encoders, router selection, and more.\n\n## 🛠️ System Requirements\n\nBefore you begin, ensure you have the following installed:\n\n- **Go**: v1.21.x or higher (Tested with v1.23+)\n- **Git**: For version control\n\n## 🚀 Getting Started\n\n### 1. Installation\n\n```bash\ngo get github.com/vihuvac/go-openapi-validator\n```\n\n### 2. Usage Examples\n\n#### Standard Library (`net/http`)\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\t\"github.com/getkin/kin-openapi/routers/legacy\"\n\tvalidator \"github.com/vihuvac/go-openapi-validator\"\n)\n\nfunc main() {\n\tv, err := validator.New(\"openapi.yaml\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// For net/http, use the legacy router\n\tr, _ := legacy.NewRouter(v.Swagger)\n\tvalidator.WithRouter(r)(v.Options)\n\n\tmux := http.NewServeMux()\n\tv.HandleSwaggerUI(mux)\n\n\tmux.HandleFunc(\"/hello\", func(w http.ResponseWriter, r *http.Request) {\n\t\tw.Header().Set(\"Content-Type\", \"application/json\")\n\t\tw.Write([]byte(`{\"message\": \"Hello World\"}`))\n\t})\n\n\tlog.Fatal(http.ListenAndServe(\":8080\", v.Middleware(mux)))\n}\n```\n\n## 📂 Project Structure\n\n```text\n.\n├── docs/             # Documentation and assets\n├── examples/         # Router-specific implementation examples\n│   ├── gin/          # Gin-gonic integration\n│   ├── gorilla/      # Gorilla Mux integration\n│   └── standard/     # Standard net/http integration\n├── swagger-ui/       # Embedded Swagger UI assets\n├── errors.go         # Custom error handling and encoders\n├── options.go        # Configuration options (Functional options pattern)\n├── swagger.go        # Swagger UI serving logic\n└── validator.go      # Core validation middleware\n```\n\n## ⚙️ Configuration\n\n| Option | Description | Default |\n| --- | --- | --- |\n| `WithValidateRequests(bool)` | Enable/Disable request validation | `true` |\n| `WithValidateResponses(bool)` | Enable/Disable response validation | `false` |\n| `WithSwaggerUIPath(string)` | Change Swagger UI base path | `/docs` |\n| `WithErrorEncoder(ErrorEncoder)` | Custom error response format | `DefaultErrorEncoder` |\n| `WithRouter(routers.Router)` | Set a custom OpenAPI router | `gorillamux.NewRouter` |\n\n## 🧪 Running Tests\n\nMaintain code quality by running the comprehensive test suite:\n\n```bash\n# Run all unit tests\ngo test ./...\n\n# Run tests with coverage\ngo test -coverprofile=coverage.out ./...\ngo tool cover -html=coverage.out\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Check out the [Contribution Guide](./CONTRIBUTING.md) to get started.\n\n## 📄 License\n\nThis project is licensed under the **MIT License**. See the [LICENSE](./LICENSE) file for more details.\n\n## Additional Resources\n\n### Project\n- [Changelog](./CHANGELOG.md)\n- [Security Policy](./SECURITY.md)\n- [Code of Conduct](./CODE_OF_CONDUCT.md)\n\n### Tools\n- [Swagger UI](https://swagger.io/tools/swagger-ui/)\n- [OpenAPI Specification v3](https://swagger.io/specification/v3/)\n- [Kin OpenAPI](https://github.com/getkin/kin-openapi)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvihuvac%2Fgo-openapi-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvihuvac%2Fgo-openapi-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvihuvac%2Fgo-openapi-validator/lists"}