schemas

package
v0.41.0 Latest Latest
Warning

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

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

Documentation

Overview

Package schemas owns the JSON Schemas that back tap's editor modelines.

Every YAML document tap hands to $EDITOR — and every config file it persists — carries a `# yaml-language-server: $schema=<uri>` modeline so a language server can offer completion, hover, and validation. Pointing that modeline at the published GitHub URL means the editor resolves whatever is on main, which is the wrong answer for anyone running a build that is ahead of (or behind) main, and no answer at all offline.

Instead the schemas are embedded in the binary and materialized under the user's data dir on demand. The modeline then points at a file:// URI whose contents are guaranteed to match the binary that wrote it. Materialization compares content rather than versions, so a schema edit is picked up by the next command that writes a modeline.

The published URLs remain the canonical $id values inside the schema files, and are the fallback whenever materialization is not possible.

Index

Constants

View Source
const (
	TapConfig           = "tap-config.json"
	FlightManifest      = "flight-manifest.json"
	KegSettings         = "keg-settings.json"
	KegSchemaDefinition = "keg-schema-definition.json"
)

Schema file names, as they appear both in the embedded FS and on disk.

View Source
const (
	TapConfigURL           = publicBase + TapConfig
	FlightManifestURL      = publicBase + FlightManifest
	KegSettingsURL         = publicBase + KegSettings
	KegSchemaDefinitionURL = publicBase + KegSchemaDefinition
)

Published URLs for each schema. Exported so pkg/tapper and pkg/keg can keep their long-standing *SchemaURL constants pointing at a single definition.

View Source
const ModelinePrefix = "# yaml-language-server: $schema="

ModelinePrefix is the literal yaml-language-server directive. A modeline is this prefix followed by a schema URI, alone on its own line.

Variables

This section is empty.

Functions

func Dir

func Dir(rt *toolkit.Runtime) (string, error)

Dir returns the directory the embedded schemas are materialized into: <user data dir>/tapper/schemas. Resolution flows through the runtime, so a sandboxed test gets its own directory rather than the developer's.

func EnsureModeline

func EnsureModeline(data []byte, modeline string) []byte

EnsureModeline prepends modeline to data unless data already carries one.

func FileURI

func FileURI(path string) string

FileURI converts an absolute filesystem path to a file:// URI. Windows paths gain the extra leading slash (file:///C:/...) and forward slashes.

func HasModeline

func HasModeline(data []byte) bool

HasModeline reports whether data already carries a schema modeline in its leading comment block. Only the comments before the first content line are considered — a `# yaml-language-server:` string further down is data, not a directive.

func Materialize

func Materialize(rt *toolkit.Runtime) (string, error)

Materialize writes every embedded schema whose on-disk copy is missing or differs, and returns the directory holding them. Comparing content rather than a version stamp keeps it correct across development builds, where the version does not move but the schema does.

func Modeline

func Modeline(rt *toolkit.Runtime, name string) string

Modeline returns the complete modeline line, newline included, for name.

func ModelineURI

func ModelineURI(rt *toolkit.Runtime, name string) string

ModelineURI returns the URI a modeline for name should point at: a file:// URI for the materialized copy, or the published URL when the schemas cannot be written (a read-only data dir, a constrained sandbox). It never fails — a stale modeline is a worse outcome than a remote one, and both are only comments.

func Names

func Names() []string

Names lists every embedded schema, in a stable order.

func PublicURL

func PublicURL(name string) string

PublicURL returns the published URL for a schema file name.

func Read

func Read(name string) ([]byte, error)

Read returns the embedded bytes for a schema file name.

func ReplaceModeline

func ReplaceModeline(data []byte, modeline string) []byte

ReplaceModeline swaps whatever schema modeline data carries for modeline, prepending it when there is none. This is the choke point every write path runs its serialized YAML through: the serializers emit the published URL as a stable default, and the write path rewrites it to the local copy.

func StripModeline

func StripModeline(data []byte) []byte

StripModeline removes the schema modeline from data's leading comment block, leaving everything else byte-for-byte. Documents that are stored rather than merely displayed run through this on the way in, so the modeline stays an editor affordance instead of becoming content: it names a path that is only meaningful on the machine that opened the editor.

Types

This section is empty.

Jump to

Keyboard shortcuts

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