mock

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package mock serves a stateless mock API from a parsed OpenAPI document: every operation responds with a synthesized example, and incoming requests can be validated against the spec. It is provider-free, depending only on kin-openapi, the oas helpers, and the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Status forces a specific response status. Zero selects automatically
	// (a Prefer: code=NNN header, then the lowest 2xx, then "default").
	Status int

	// ValidateRequests validates each incoming request against the spec and
	// responds 422 with the violations when it does not conform.
	ValidateRequests bool
}

Options configures the mock server.

type Route

type Route struct {
	Method string
	Path   string
}

Route is a single operation the mock serves.

func Handler

func Handler(doc *openapi3.T, opts Options) (http.Handler, []Route, error)

Handler builds an http.Handler that serves synthesized responses for the given OpenAPI document, returning the routes it serves. Routing is by path only: the document's servers are normalized so requests to the local mock match the spec's raw paths regardless of the declared server host. The document is not strictly validated, so specs with minor schema issues still serve.

Jump to

Keyboard shortcuts

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