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 ¶
- Variables
- func Detect(raw []byte) (contract.InterfaceType, error)
- func DetectFileFormat(raw []byte) contract.FileFormat
- func ToJSON(raw []byte) ([]byte, error)
- func Validate(typ contract.InterfaceType, raw []byte) error
- func ValidateJSONSchema(raw []byte) error
- func ValidateOpenAPI(raw []byte) error
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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 ¶
ValidateJSONSchema checks that raw (JSON or YAML) compiles as a JSON Schema.
func ValidateOpenAPI ¶
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.