Documentation
¶
Overview ¶
Package openapi provides loading, validation, and contract testing for OpenAPI 3.0.x, 3.1.x, and 3.2 documents using Navigator's shared index model.
Index ¶
- func ApplySecurity(idx *navigator.Index, op *navigator.Operation, req *http.Request, ...) error
- func BuildRequest(ctx context.Context, idx *navigator.Index, ...) (*http.Request, error)
- func Load(ctx context.Context, path string, opts *LoadOpts) (*navigator.Index, error)
- func LoadFromIndex(idx *navigator.Index) *navigator.Index
- func ResolveOperationByID(idx *navigator.Index, operationID string) (*navigator.OperationRef, error)
- func ResolveOperationByPath(idx *navigator.Index, pathPattern, method string) (*navigator.OperationRef, error)
- func ResolveOperationByPathFragment(idx *navigator.Index, fragment string) (*navigator.OperationRef, error)
- func Validate(idx *navigator.Index) error
- func ValidateResponse(ctx context.Context, idx *navigator.Index, resp *http.Response, ...) error
- func Version(idx *navigator.Index) string
- type ContractOpts
- type ContractResult
- type GuidelineValidationError
- type LoadOpts
- type ParamOverrides
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplySecurity ¶ added in v0.1.1
func ApplySecurity(idx *navigator.Index, op *navigator.Operation, req *http.Request, creds map[string]string) error
ApplySecurity applies OpenAPI security schemes to req using resolved credential strings keyed by security scheme name (same keys as components.securitySchemes).
func BuildRequest ¶
func BuildRequest(ctx context.Context, idx *navigator.Index, baseURL, pathTemplate, method string, pathItem *navigator.PathItem, op *navigator.Operation, pathParams map[string]string, overrides ParamOverrides, bodyOverride []byte) (*http.Request, error)
BuildRequest builds an HTTP request for the given path, method, and operation using Navigator-backed OpenAPI types. If bodyOverride is non-nil, it is used as the request body instead of building from the operation's requestBody schema.
func Load ¶
Load reads an OpenAPI document from a local path or URL and returns a Navigator index. Supports OpenAPI 3.0, 3.1, and 3.2 (YAML or JSON). Swagger/OAS 2.0 inputs are detected and rejected.
func LoadFromIndex ¶
LoadFromIndex returns the given index as-is when a caller already has a parsed Navigator index.
func ResolveOperationByID ¶
func ResolveOperationByID(idx *navigator.Index, operationID string) (*navigator.OperationRef, error)
ResolveOperationByID finds the OperationRef for the given operationId.
func ResolveOperationByPath ¶
func ResolveOperationByPath(idx *navigator.Index, pathPattern, method string) (*navigator.OperationRef, error)
ResolveOperationByPath finds the operation by path template and method. fragment may be a JSON Pointer like "#/paths/~1pet~1findByStatus/get" or path and method separately.
func ResolveOperationByPathFragment ¶
func ResolveOperationByPathFragment(idx *navigator.Index, fragment string) (*navigator.OperationRef, error)
ResolveOperationByPathFragment parses a JSON Pointer fragment (e.g. #/paths/~1pet~1findByStatus/get) and resolves the operation.
func Validate ¶
Validate performs structural validation of the loaded document (e.g. is it a valid OpenAPI root).
func ValidateResponse ¶
func ValidateResponse(ctx context.Context, idx *navigator.Index, resp *http.Response, op *navigator.Operation, statusCode int) error
ValidateResponse checks that the HTTP response is consistent with the operation's responses. Status must be declared in the operation's responses; if the response has a JSON body and the spec defines a schema for that status, the body is validated against the schema.
Types ¶
type ContractOpts ¶
type ContractOpts struct {
Tags []string
OperationID string
// Credentials maps security scheme name (components.securitySchemes) to secret values
// (API keys, bearer tokens, basic "user:pass", OAuth access tokens). Resolved by the host.
Credentials map[string]string
}
ContractOpts filters which operations to run.
type ContractResult ¶
type ContractResult struct {
Path string `json:"path"`
Method string `json:"method"`
OperationID string `json:"operationId"`
Pass bool `json:"pass"`
Status int `json:"status"`
Error string `json:"error,omitempty"`
GuidelineID string `json:"guidelineId,omitempty"`
DocURL string `json:"docUrl,omitempty"`
}
ContractResult is the result of a single operation contract check.
func RunContract ¶
func RunContract(ctx context.Context, idx *navigator.Index, baseURL string, client *runner.Client, opts *ContractOpts) ([]ContractResult, error)
RunContract runs contract tests for all (or filtered) operations in the spec against baseURL.
type GuidelineValidationError ¶ added in v0.2.0
GuidelineValidationError captures a runtime validation failure that maps to a specific SailPoint guideline.
func (*GuidelineValidationError) Error ¶ added in v0.2.0
func (e *GuidelineValidationError) Error() string
type LoadOpts ¶
type LoadOpts struct {
// BasePath is used to resolve relative $ref when path is a file path.
BasePath string
// HTTPClient is used when loading from URL. If nil, http.DefaultClient is used.
HTTPClient *http.Client
}
LoadOpts configures how to load an OpenAPI document.
type ParamOverrides ¶
ParamOverrides can supply values for parameters (key: "path:name", "query:name", "header:name", "cookie:name"). Used by Arazzo to inject resolved expression values.
type ValidationError ¶
ValidationError describes a single schema validation failure.
func ValidateJSON ¶
ValidateJSON validates the value against the schema using the index for $ref resolution. Returns a slice of validation errors (empty if valid).
func (ValidationError) Error ¶
func (e ValidationError) Error() string