openapi

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 25 Imported by: 0

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

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

func Load(ctx context.Context, path string, opts *LoadOpts) (*navigator.Index, error)

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

func LoadFromIndex(idx *navigator.Index) *navigator.Index

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

func Validate(idx *navigator.Index) error

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.

func Version

func Version(idx *navigator.Index) string

Version returns the openapi version string from the document (e.g. "3.0.3", "3.1.0", "3.2.0").

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
	ResponseValidator ResponseValidator
}

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

type GuidelineValidationError struct {
	GuidelineID string
	DocURL      string
	Message     string
}

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

type ParamOverrides map[string]string

ParamOverrides can supply values for parameters (key: "path:name", "query:name", "header:name", "cookie:name"). Used by Arazzo to inject resolved expression values.

type ResponseValidator added in v0.3.0

type ResponseValidator interface {
	ValidateResponse(request *http.Request, response *http.Response) []ValidationError
}

ResponseValidator validates a runtime HTTP response against an OpenAPI document.

func NewLibOpenAPIResponseValidator added in v0.3.0

func NewLibOpenAPIResponseValidator(ctx context.Context, specPath string, httpClient *http.Client) (ResponseValidator, error)

NewLibOpenAPIResponseValidator creates a response validator backed by pb33f/libopenapi-validator.

type ValidationError

type ValidationError struct {
	Path    string // JSON path or description
	Message string
}

ValidationError describes a single schema validation failure.

func ValidateJSON

func ValidateJSON(idx *navigator.Index, schema *navigator.Schema, value any) []ValidationError

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

Jump to

Keyboard shortcuts

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