matchopenapi

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package matchopenapi holds the openapi matcher of mock files, [openapi, {spec, operation, check}], which matches a request that keeps the contract an OpenAPI 3 spec gives one of its operations. Under not, it matches a request that breaks it: the mocks vlatte openapi writes refuse such a request with the error the spec's server would answer.

The vlatte command knows the matcher. A server of this module loads the mocks that use it once its registry has it, which links kin-openapi, an OpenAPI library, only into the programs that ask for it:

m := mockhttp.MustNew(mockhttp.Setup().Matchers(matchbuild.MustNew(matchopenapi.WithMatcher())))

Index

Constants

View Source
const Name = "openapi"

Name is the name of the matcher in mock files.

Variables

This section is empty.

Functions

func WithMatcher

func WithMatcher() matchbuild.Option

WithMatcher returns the option that adds the openapi matcher to a matchbuild.Registry. Its arguments are an object: spec, the file of an OpenAPI 3 spec, relative to the mock file, in which every reference is local; operation, the operationId of one of its operations, or its method and path, such as GET /pets/{id}, the path under the path of the operation's first server; and check, what the request must keep: security, a credential of one of the operation's security requirements; content_type, a body in a media type the operation takes; or request, its parameters and body as the spec describes them, but for the readOnly properties it requires, which a client needn't send. A request of another operation keeps the contract, such as one of /pets/mine, of any method, for the operations of /pets/{id}: OpenAPI matches the path before the method, and a path of fewer templated segments first. The matcher compares a request's path as the mocks vlatte openapi writes of the operation do, under the path of its first server: GET /foo%2Fbar is a request of GET /foo/bar.

The request check reads and checks parameters as kin-openapi does, each number as a float64. It checks a body against the schema of its media type as the spec writes it, an integer past 2^53 and a const of null included, with JSON Schema 2020-12, which an OpenAPI 3.0 schema is translated to, keeping what kin-openapi checks besides: a oneOf or an anyOf with a discriminator takes an object by the branch the discriminator names, a nullable schema of OpenAPI 3.0 takes null, and only the formats kin-openapi checks are, byte, date, date-time, int32 and int64. A body other than JSON is read as kin-openapi reads it, a number of a form as a float64. A body whose schema doesn't compile, such as one that refers into the paths of the spec, is checked as kin-openapi checks it.

The matcher records what a request breaks in its explanation, and never fails: a spec that doesn't load fails the mock file. The matchers of a registry load each spec once, and again when its file changes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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