openapi

package
v0.0.0-...-a46f814 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRouteNotFound is returned when the request path/method does not match any OpenAPI route.
	ErrRouteNotFound = ae.GetCustomErr(
		"ERR_OPENAPI_1001",
		"route not found",
		false)

	// ErrValidationUnexpectedType is returned when the validator returns an error that is not openapi3.MultiError.
	ErrValidationUnexpectedType = ae.GetCustomErr(
		"ERR_OPENAPI_1002",
		"validation error is not of type openapi3 multi error",
		false)

	// ErrValidationFailed is the base error for request validation failures; message is replaced with the actual validation details.
	ErrValidationFailed = ae.GetCustomErr(
		"ERR_OPENAPI_1003",
		"openapi request validation failed",
		false)

	// ErrLoadSpec is returned when the OpenAPI spec file cannot be loaded.
	ErrLoadSpec = ae.GetCustomErr(
		"ERR_OPENAPI_1004",
		"failed to load open api specification",
		false)

	// ErrCreateRouter is returned when the OpenAPI router cannot be created from the spec.
	ErrCreateRouter = ae.GetCustomErr(
		"ERR_OPENAPI_1005",
		"failed to create router for open api validation",
		false)

	// ErrResponseValidationFailed is returned when the response does not match the OpenAPI spec (logged; response already sent).
	ErrResponseValidationFailed = ae.GetCustomErr(
		"ERR_OPENAPI_1006",
		"openapi response validation failed",
		false)
)

Functions

func NewOpenAPIValidatorRouter

func NewOpenAPIValidatorRouter(config *SwaggerConfig) (*routers.Router, error)

func OpenAPIValidatorRequest

func OpenAPIValidatorRequest(router routers.Router) gin.HandlerFunc

func OpenAPIValidatorRequestAndResponse

func OpenAPIValidatorRequestAndResponse(router routers.Router) gin.HandlerFunc

OpenAPIValidatorRequestAndResponse runs request validation, then captures and validates the response against the OpenAPI spec. Response validation failures are logged only (response is already sent to the client).

Types

type SwaggerConfig

type SwaggerConfig struct {
	SwaggerFilePath string
	SwaggerFileName string
}

Directories

Path Synopsis
Package main demonstrates the OpenAPI validator middleware.
Package main demonstrates the OpenAPI validator middleware.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL