validator

module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0

README

Go OpenAPI Contract Verification for use with net/http

A Go library for making it easier to validate that your OpenAPI contracts match your HTTP request/responses used in your tests.

See documentation on pkg.go.dev.

Usage

go get openapi.tanna.dev/go/validator/openapi3
import (
	validator "openapi.tanna.dev/go/validator/openapi3"
)

func Test_Handler_Contract(t *testing.T) {
	doc, err := openapi3.NewLoader().LoadFromFile("testdata/fedmodel.yaml")
	if err != nil {
		t.Error("unexpected test setup error reading OpenAPI contract", err)
	}

	rr := httptest.NewRecorder()
	req := httptest.NewRequest("GET", "/apis", nil)
	req.Header.Add("tracing-id", "123")
	v := validator.NewValidator(doc).ForTest(t, rr, req)

	Handler(rr, req)

	// validation happens automagically!
}

Structure

  • openapi3 (godoc) - OpenAPI 3.x support

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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