command
Version:
v1.0.1
Opens a new window with list of versions in this module.
Published: Dec 31, 2025
License: MIT
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Standard Library Example
This example demonstrates how to use go-openapi-validator with the Go standard library's http.ServeMux.
Features
- Minimal Dependencies: Shows how to use the validator with standard
net/http.
- Legacy Router Support: Uses the
legacy router from kin-openapi (required for ServeMux).
- Post Request Validation: Includes an example of validating JSON bodies in POST requests.
Usage
1. Run the Server
go run main.go
2. Test Endpoints
Code Overview
For net/http, we manually configure the router to use the legacy implementation:
v, _ := validator.New("openapi.yaml")
router, _ := legacy.NewRouter(v.Swagger)
validator.WithRouter(router)(v.Options)
mux := http.NewServeMux()
// ... register routes ...
handler := v.Middleware(mux)
http.ListenAndServe(":8081", handler)
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.