spec

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package spec parses, detects and validates interface specifications.

It is the single place in ifc7 where OpenAPI documents are parsed with libopenapi and JSON Schema documents are compiled. The CLI and ifc-server both call it instead of importing those libraries directly, so a document accepted by one is accepted by the other.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSpecification = errors.New("invalid interface specification")

ErrInvalidSpecification is returned (wrapped) for any document that cannot be detected or does not validate as its declared type.

View Source
var ErrUnsupportedType = errors.New("unsupported interface type")

ErrUnsupportedType is returned (wrapped) by Validate for an interface type that this package has no validator for.

Functions

func Detect

func Detect(raw []byte) (contract.InterfaceType, error)

Detect reports whether raw is a valid OpenAPI or JSON Schema document. OpenAPI is checked first so OpenAPI documents are not classified as JSON Schema.

func DetectFileFormat

func DetectFileFormat(raw []byte) contract.FileFormat

DetectFileFormat returns json or yaml based on content.

func ToJSON

func ToJSON(raw []byte) ([]byte, error)

ToJSON converts a JSON or YAML document to JSON bytes. JSON input is returned unchanged.

func Validate

func Validate(typ contract.InterfaceType, raw []byte) error

Validate checks that raw is a well-formed document of the given type.

func ValidateJSONSchema

func ValidateJSONSchema(raw []byte) error

ValidateJSONSchema checks that raw (JSON or YAML) compiles as a JSON Schema.

func ValidateOpenAPI

func ValidateOpenAPI(raw []byte) error

ValidateOpenAPI checks that raw parses as an OpenAPI (or Swagger) document.

Types

type ValidationError

type ValidationError struct {
	// Type is the interface type the document was validated as. Empty when
	// the type could not be detected.
	Type contract.InterfaceType
	// Err is the underlying parser or compiler error.
	Err error
}

ValidationError describes why a document failed validation.

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() []error

Unwrap lets errors.Is match both ErrInvalidSpecification and the cause.

Jump to

Keyboard shortcuts

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