openapi

package
v1.37.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SchemaURL is the URL to the Auth0 Management API OpenAPI schema.
	SchemaURL = "https://auth0.com/docs/oas/management/v2/management-api-oas.json"

	// CacheTTL is how long to cache the schema before re-fetching.
	CacheTTL = 3 * 24 * time.Hour
)

Variables

This section is empty.

Functions

func ExtractPathFromURL

func ExtractPathFromURL(fullURL string) string

ExtractPathFromURL extracts the API path from a full URL. Example: "https://tenant.auth0.com/api/v2/actions/actions" -> "/actions/actions".

func FindOperation

func FindOperation(doc *openapi3.T, method, path string) (*openapi3.Operation, error)

FindOperation finds an operation by HTTP method and path ("/actions/actions" or "actions/actions").

func GetDoc

func GetDoc() (*openapi3.T, error)

GetDoc returns the OpenAPI document from cache (in-memory then on-disk) or fetches it; returns a stale copy on failure.

func GetQueryParamSchema

func GetQueryParamSchema(operation *openapi3.Operation) *openapi3.Schema

GetQueryParamSchema builds a synthetic object schema from an operation's query parameters.

func GetRequestSchema

func GetRequestSchema(operation *openapi3.Operation) *openapi3.SchemaRef

GetRequestSchema returns the request body schema for an operation.

func LoadDocFromData added in v1.36.0

func LoadDocFromData(data []byte) (*openapi3.T, error)

LoadDocFromData parses an OpenAPI document from raw bytes using the same loader configuration as the network and on-disk paths. It is exported so tests can build a fixture document and validate against it without touching the network.

Types

type FieldError added in v1.36.0

type FieldError struct {
	Field  string `json:"field,omitempty"`
	Reason string `json:"reason"`
}

FieldError is a single structured validation failure. Field is a JSONPath-style location within the payload ("payload" for a whole-body error, empty when the failure is not tied to a location, e.g. malformed JSON); Reason is the message.

func (FieldError) String added in v1.36.0

func (e FieldError) String() string

String renders a FieldError as "field: reason", or just the reason when the error is not tied to a field.

type OperationSchema

type OperationSchema struct {
	OperationID        string
	Summary            string
	Description        string
	Method             string
	Path               string
	RequestSchema      *openapi3.Schema
	IsQueryParamSchema bool
}

OperationSchema contains schema information for an API operation.

func (*OperationSchema) FormatAsJSON

func (op *OperationSchema) FormatAsJSON() (string, error)

FormatAsJSON formats the schema as JSON for display.

func (*OperationSchema) FormatAsText

func (op *OperationSchema) FormatAsText() string

FormatAsText formats the schema as human-readable text.

type SchemaManager

type SchemaManager struct {
	// contains filtered or unexported fields
}

SchemaManager provides access to OpenAPI operation schemas and request validation.

func NewSchemaManager

func NewSchemaManager() (*SchemaManager, error)

NewSchemaManager creates a new schema manager backed by the cached OpenAPI document.

func NewSchemaManagerFromDoc added in v1.36.0

func NewSchemaManagerFromDoc(doc *openapi3.T) *SchemaManager

NewSchemaManagerFromDoc creates a schema manager backed by an already-loaded document instead of fetching one. Tests use it with a fixture document so the unit suite validates locally and never reaches the network.

func (*SchemaManager) EnhanceError

func (sm *SchemaManager) EnhanceError(err error, method, path string) error

EnhanceError appends the expected request schema to a 400 Bad Request error. Non-400 errors are returned unchanged.

func (*SchemaManager) GetOperationSchema

func (sm *SchemaManager) GetOperationSchema(method, path string) (*OperationSchema, error)

GetOperationSchema returns the schema information for an operation.

func (*SchemaManager) ValidateRequest

func (sm *SchemaManager) ValidateRequest(method, path string, body []byte) (*ValidationResult, error)

ValidateRequest checks a --data payload against the operation's OpenAPI request schema by visiting the parsed JSON with kin-openapi (VisitJSON). JSON syntax is always checked first, so malformed input is reported as StatusInvalid even when the operation defines no schema to validate against.

type ValidationResult

type ValidationResult struct {
	Status      ValidationStatus
	Errors      []string
	FieldErrors []FieldError
}

ValidationResult contains the result of schema validation. Status reports whether a schema existed and whether the payload satisfied it; Errors holds the human-readable strings; FieldErrors holds the same failures in structured form for the JSON error envelope's "details" field.

type ValidationStatus added in v1.36.0

type ValidationStatus int

ValidationStatus describes what happened when a payload was checked against the operation's OpenAPI request schema.

const (
	// StatusUnknown is the zero value and means no outcome was recorded. It exists
	// so a ValidationResult{} left unset fails closed (never reads as StatusValid)
	// rather than silently passing a payload through as validated.
	StatusUnknown ValidationStatus = iota
	// StatusValid means a request schema existed and the payload satisfied it.
	StatusValid
	// StatusInvalid means a request schema existed and the payload failed it (see Errors).
	StatusInvalid
	// StatusNoSchema means the operation defines no request schema, so the payload
	// was not checked and is sent as-is.
	StatusNoSchema
)

Jump to

Keyboard shortcuts

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