Documentation
¶
Index ¶
- Variables
- func FetchFromFile(u *url.URL) ([]byte, error)
- func FetchFromHTTP(u *url.URL) ([]byte, error)
- func FetchFromURL(u *url.URL) ([]byte, error)
- func LooksLikeYAMLValidationFile(input string) bool
- func ResolveSchemaFileIfPresent(filename string, validationFile *validationfile.ValidationFile) error
- func UnmarshalAsYAMLOrSchema(contents []byte) (*validationfile.ValidationFile, error)
- func UnmarshalSchemaValidationFile(contents []byte) *validationfile.ValidationFile
- func UnmarshalYAMLValidationFile(contents []byte) (*validationfile.ValidationFile, error)
- type DecoderResult
- type FileType
- type SourceType
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidYamlTryZed = errors.New("invalid yaml")
Functions ¶
func FetchFromURL ¶ added in v0.36.1
FetchFromURL interprets the URL, fetches the content, and returns the bytes.
func LooksLikeYAMLValidationFile ¶ added in v1.0.0
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 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)