openapicheck

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package openapicheck validates live HTTP responses against the canonical OpenAPI contract.

Static contract tests prove the document is internally consistent and that every route is declared. They cannot prove the server actually emits what the document promises: a required property the handler stopped serializing, or a property the handler emits that the document never declared, passes every static check while breaking any strict client. This package closes that gap by validating real responses as the integration suite produces them.

It implements only the JSON Schema vocabulary the canonical contract uses. An unknown keyword is a deliberate failure rather than a silent pass, so the validator cannot rot into a no-op as the contract grows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

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

Document is a loaded OpenAPI contract prepared for response validation.

func Load

func Load(path string) (*Document, error)

Load reads and prepares the canonical contract at path.

func (*Document) Handler

func (document *Document) Handler(report Reporter, inner http.Handler) http.Handler

Handler wraps inner so that every JSON response it produces is validated against the contract before the test observes it. Streaming upgrades are passed through untouched: a hijacked connection is no longer an HTTP response the contract describes.

func (*Document) ValidateAgainstSchema

func (document *Document) ValidateAgainstSchema(schema map[string]any, value any) error

ValidateAgainstSchema checks one decoded value against one schema. It exists so the validator's own coverage can be exercised directly.

func (*Document) ValidateResponse

func (document *Document) ValidateResponse(
	method string,
	urlPath string,
	status int,
	contentType string,
	body []byte,
) error

ValidateResponse checks one live response against the contract. It reports nil when the contract declares no JSON body for the matched operation.

type Reporter

type Reporter func(format string, args ...any)

Reporter receives one message per contract violation. Tests pass t.Errorf.

Jump to

Keyboard shortcuts

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