Documentation ¶
Index ¶
- Constants
- Variables
- func APIMethodNotAllowedHandler() http.HandlerFunc
- func APINotFoundHandler() http.HandlerFunc
- func APIValidator(options Options) func(h http.Handler) http.Handler
- func RadiusResourceTypeGetter(r *http.Request) (string, error)
- func UCPResourceTypeGetter(r *http.Request) (string, error)
- type Loader
- type Options
- type ValidationError
- type Validator
Constants ¶
const ( // This comes from the path: /Users/vinayada/radius/radius/swagger/specification/ucp/resource-manager/UCP/preview/2023-10-01-preview/openapi.json // This spec path is parsed and this string needs to be provider/resourceType. // For UCP, the provider is UCP and since all UCP resource types are in a single json, the file is named openapi.json. // Therefore, resourceType = ucp UCPEndpointType = "ucp/openapi" UCPApiVersion = "2023-10-01-preview" )
const (
APIVersionQueryKey = "api-version"
)
Variables ¶
var (
ErrSpecDocumentNotFound = errors.New("not found OpenAPI specification document")
)
var (
ErrUndefinedRoute = errors.New("undefined route path")
)
Functions ¶
func APIMethodNotAllowedHandler ¶
func APIMethodNotAllowedHandler() http.HandlerFunc
APIMethodNotAllowedHandler is the handler when the request method does not match the route. It handles requests with invalid methods by returning a MethodNotAllowedResponse and an error if the response fails to be applied.
r := mux.NewRouter() r.MethodNotAllowedHandler = APIMethodNotAllowedHandler()
func APINotFoundHandler ¶
func APINotFoundHandler() http.HandlerFunc
APINotFoundHandler is the handler when the request url route does not exist. It handles requests that are invalid and returns a NotFoundMessageResponse. If an error occurs, it is handled by the handleError function.
r := mux.NewRouter() r.NotFoundHandler = APINotFoundHandler()
func APIValidator ¶
APIValidator is the middleware to validate incoming request with OpenAPI spec. It wraps a handler to validate requests against a given spec loader and resource type getter.
func RadiusResourceTypeGetter ¶
RadiusResourceTypeGetter parses the request URL and method to get the resource type and returns it, returning an error if parsing fails.
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is the OpenAPI spec loader implementation.
func LoadSpec ¶
func LoadSpec(ctx context.Context, providerName string, specs fs.FS, rootScopePrefixes []string, rootScopeParam string) (*Loader, error)
LoadSpec loads OpenAPI spec documents from the given FS and returns a Loader instance. If no spec documents are found, an error is returned.
func (*Loader) GetValidator ¶
GetValidator returns the cached validator.
func (*Loader) SupportedVersions ¶
// SupportedVersions returns a list of supported versions for the given resource type, or an empty list if the resource type is not supported.
type Options ¶
type Options struct { // SpecLoader is the loader to load the OpenAPI spec. SpecLoader *Loader // ResourceType is the function to get the resource type from the request. ResourceTypeGetter func(*http.Request) (string, error) }
Options represents the options for APIValidator.
type ValidationError ¶
type ValidationError struct { // Code represents the code of validation error. Code string // Message contains the error message, e.g. "location is required". Message string }
ValidationError represents a validation error.
type Validator ¶
type Validator interface { // ValidateRequest validates a http request and returns all the errors. ValidateRequest(req *http.Request) []ValidationError }
Validator validates HTTP request.