schema_validation

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package schema_validation contains all the logic, models and interfaces for validating OpenAPI 3+ Schemas. Functionality for validating individual *base.Schema instances, but as well as validating a complete OpenAPI 3+ document

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LocateSchemaPropertyNodeByJSONPath

func LocateSchemaPropertyNodeByJSONPath(doc *yaml.Node, JSONPath string) *yaml.Node

LocateSchemaPropertyNodeByJSONPath will locate a schema property node by a JSONPath. It converts something like #/components/schemas/MySchema/properties/MyProperty to something like $.components.schemas.MySchema.properties.MyProperty

func ValidateOpenAPIDocument

func ValidateOpenAPIDocument(doc libopenapi.Document) (bool, []*liberrors.ValidationError)

ValidateOpenAPIDocument will validate an OpenAPI document against the OpenAPI 2, 3.0 and 3.1 schemas (depending on version) It will return true if the document is valid, false if it is not and a slice of ValidationError pointers.

Types

type SchemaValidator

type SchemaValidator interface {

	// ValidateSchemaString accepts a schema object to validate against, and a JSON/YAML blob that is defined as a string.
	ValidateSchemaString(schema *base.Schema, payload string) (bool, []*liberrors.ValidationError)

	// ValidateSchemaObject accepts a schema object to validate against, and an object, created from unmarshalled JSON/YAML.
	// This is a pre-decoded object that will skip the need to unmarshal a string of JSON/YAML.
	ValidateSchemaObject(schema *base.Schema, payload interface{}) (bool, []*liberrors.ValidationError)

	// ValidateSchemaBytes accepts a schema object to validate against, and a byte slice containing a schema to
	// validate against.
	ValidateSchemaBytes(schema *base.Schema, payload []byte) (bool, []*liberrors.ValidationError)
}

SchemaValidator is an interface that defines the methods for validating a *base.Schema (V3+ Only) object. There are 3 methods for validating a schema:

ValidateSchemaString accepts a schema object to validate against, and a JSON/YAML blob that is defined as a string.
ValidateSchemaObject accepts a schema object to validate against, and an object, created from unmarshalled JSON/YAML.
ValidateSchemaBytes accepts a schema object to validate against, and a JSON/YAML blob that is defined as a byte array.

func NewSchemaValidator

func NewSchemaValidator() SchemaValidator

NewSchemaValidator will create a new SchemaValidator instance, ready to accept schemas and payloads to validate.

func NewSchemaValidatorWithLogger

func NewSchemaValidatorWithLogger(logger *slog.Logger) SchemaValidator

NewSchemaValidatorWithLogger will create a new SchemaValidator instance, ready to accept schemas and payloads to validate.

Directories

Path Synopsis
Package openapi_schemas contains the OpenAPI 3.0 and 3.1 schemas that are loaded from libopenapi, or our own fork of the official OpenAPI repo specifications.
Package openapi_schemas contains the OpenAPI 3.0 and 3.1 schemas that are loaded from libopenapi, or our own fork of the official OpenAPI repo specifications.

Jump to

Keyboard shortcuts

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