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
- Variables
- func IsJSON(path string) bool
- func IsYAML(path string) bool
- func JSONToYAML(data []byte) ([]byte, error)
- func ReadFile(path string) ([]byte, error)
- func StripTopLevelMember(data []byte, name string) ([]byte, error)
- func ToJSON(data []byte, path string) ([]byte, error)
- func YAMLToJSON(data []byte) ([]byte, error)
Constants ¶
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 ¶
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 JSONToYAML ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.