configfile

package
v0.18.5 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: 11 Imported by: 0

Documentation

Overview

Package configfile reads apic generator configs in JSON or YAML and normalises them to JSON bytes — the only form the generator, the schema validator, and the MCP config tools ever see.

YAML support is a thin, lossless front-end: a YAML document is converted to JSON preserving member order, integers stay integers, and anything with no JSON representation (custom tags, merge keys, non-string mapping keys, duplicate keys, multi-document streams, .inf/.nan) is refused fail-closed rather than silently coerced. Integer resolution follows yaml.v3 (YAML 1.1): "017" is octal 15, literals beyond uint64 resolve as floats, and "1e400" resolves as a string.

Index

Constants

View Source
const SchemaMember = "$schema"

SchemaMember is the top-level member editors use to bind a config to the published JSON Schema (schema/apic-config.schema.json). It is accepted in any config and stripped before the bytes reach the strict (RejectUnknownMembers) generator decoder.

Variables

View Source
var (
	// ErrYAML wraps every YAML-specific conversion failure.
	ErrYAML = errors.New("configfile: invalid YAML config")
	// ErrJSON wraps every JSON-specific conversion failure.
	ErrJSON = errors.New("configfile: invalid JSON config")
)

Functions

func IsJSON

func IsJSON(path string) bool

IsJSON reports whether path names a JSON config (.json, any case).

func IsYAML

func IsYAML(path string) bool

IsYAML reports whether path names a YAML config (.yaml or .yml, any case).

func JSONToYAML

func JSONToYAML(data []byte) ([]byte, error)

JSONToYAML converts a JSON config to a YAML document, preserving member order. Scalars YAML would otherwise reinterpret ("true", "1", "") are emitted quoted by the yaml.v3 encoder, so YAMLToJSON(JSONToYAML(x)) is semantically x.

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile reads a JSON or YAML config from disk and returns JSON bytes with the top-level "$schema" member removed. A path with any extension other than .yaml/.yml is treated as JSON (the historical behaviour of every caller). JSON input that carries no "$schema" member is returned byte-for-byte.

func StripTopLevelMember

func StripTopLevelMember(data []byte, name string) ([]byte, error)

StripTopLevelMember returns data with the named top-level object member removed. When the member is absent (or the document is not an object) data is returned unchanged — the same slice; when present the document is re-encoded with two-space indentation and a trailing newline.

func ToJSON

func ToJSON(data []byte, path string) ([]byte, error)

ToJSON normalises in-memory config bytes to JSON. YAML conversion happens only when IsYAML(path); otherwise data is already JSON. The top-level "$schema" member, if present, is removed.

func YAMLToJSON

func YAMLToJSON(data []byte) ([]byte, error)

YAMLToJSON converts a single-document YAML config to JSON, preserving member order. Output is two-space indented with a trailing newline.

Types

This section is empty.

Jump to

Keyboard shortcuts

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