decode

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidYamlTryZed = errors.New("invalid yaml")

Functions

func FetchFromFile added in v0.36.1

func FetchFromFile(u *url.URL) ([]byte, error)

func FetchFromHTTP added in v0.36.1

func FetchFromHTTP(u *url.URL) ([]byte, error)

func FetchFromURL added in v0.36.1

func FetchFromURL(u *url.URL) ([]byte, error)

FetchFromURL interprets the URL, fetches the content, and returns the bytes.

func LooksLikeYAMLValidationFile added in v1.0.0

func LooksLikeYAMLValidationFile(input string) bool

LooksLikeYAMLValidationFile returns true if the input appears to be a YAML validation file based on the presence of top-level YAML keys (schema:, schemaFile:, or relationships:).

func ResolveSchemaFileIfPresent added in v0.36.1

func ResolveSchemaFileIfPresent(filename string, validationFile *validationfile.ValidationFile) error

ResolveSchemaFileIfPresent takes a ValidationFile and if the SchemaFile key is present, uses it to populate the `Schema` key.

func UnmarshalAsYAMLOrSchema added in v0.36.1

func UnmarshalAsYAMLOrSchema(contents []byte) (*validationfile.ValidationFile, error)

UnmarshalAsYAMLOrSchema tries to unmarshal as YAML first, falling back to treating the contents as a raw schema.

func UnmarshalSchemaValidationFile added in v0.36.1

func UnmarshalSchemaValidationFile(contents []byte) *validationfile.ValidationFile

UnmarshalSchemaValidationFile wraps raw schema bytes into a ValidationFile.

func UnmarshalYAMLValidationFile added in v0.36.1

func UnmarshalYAMLValidationFile(contents []byte) (*validationfile.ValidationFile, error)

UnmarshalYAMLValidationFile unmarshals YAML validation file contents into a ValidationFile struct.

Types

type DecoderResult added in v1.0.0

type DecoderResult struct {
	// Schema is the parsed schema, including its source position within the YAML file.
	Schema blocks.SchemaWithPosition
	// DisplayContents is the raw file bytes used for error display context.
	// This may differ from Schema when the schema is inline: DisplayContents
	// is the full YAML (so error messages can reference assertions, relations,
	// etc.), while Schema is only the schema block.
	DisplayContents []byte
	// SchemaFileName is the base name of the file containing the schema,
	// used for error reporting. For inline schemas this is the YAML filename
	// (e.g. "validation.yaml"); for external schemas it is the schemaFile
	// basename (e.g. "schema.zed").
	SchemaFileName string
	// RootSchemaDir is the directory to root the filesystem at for resolving schema
	// imports. For inline schemas this is the YAML file's directory; for
	// external schemas it is the SchemaFileName's directory.
	RootSchemaDir     string
	Relationships     blocks.ParsedRelationships
	Assertions        blocks.Assertions
	ExpectedRelations blocks.ParsedExpectedRelations
	// ValidationFile is the parsed validation file. For schemaFile YAML, the
	// schema has been inlined into Schema and SchemaFile is still set; callers
	// that pass this to development.NewDevContextForValidationFile should clear
	// SchemaFile on a copy first.
	ValidationFile *validationfile.ValidationFile
}

DecoderResult holds the decoded contents of a validation file or a zed file.

func ValidationFileFromFilename added in v0.36.1

func ValidationFileFromFilename(filename string, fileType FileType, mustDefineSchema bool) (decoderResult *DecoderResult, err error)

ValidationFileFromFilename takes a filename and a desired/expected FileType and returns the decoded file.

type FileType added in v0.36.1

type FileType int
const (
	FileTypeUnknown FileType = iota
	FileTypeYaml
	FileTypeZed
)

type SourceType added in v0.36.1

type SourceType int
const (
	SourceTypeUnknown SourceType = iota
	SourceTypeFile
	SourceTypeHTTP
)

func SourceTypeFromURL added in v0.36.1

func SourceTypeFromURL(u *url.URL) (SourceType, error)

Jump to

Keyboard shortcuts

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