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 bounded, lossless front-end: member order and arbitrary- precision numeric identity are preserved, while values with no unambiguous JSON representation (including timestamps, binary/custom tags, merge keys, non-string or duplicate keys, multi-document streams and non-finite numbers) are refused fail-closed rather than silently coerced.
Package configfile normalizes build-tool config files to strict JSON. Runtime packages continue consuming JSON and must not import this build-time package. YAML supports map, sequence, string, finite number, boolean and null nodes, plus bounded value aliases. Merge keys, alias keys, timestamps, binary values, custom tags and recursive aliases are refused. Quote date-like strings. Source size is checked before parsing; node/depth/expansion budgets are checked during JSON token reading or traversal of the unexpanded YAML syntax tree.
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, _ ...string) ([]byte, error)
- func YAMLToJSON(data []byte) ([]byte, error)
Constants ¶
const MaxBytes = 8 << 20
MaxBytes limits both source bytes and normalized output to 8 MiB. Referenced schema fragments retain their separate, stricter 4 MiB source-file limit.
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 deterministically converts strict JSON to YAML without losing scalar identity or numeric precision. Member order is retained.
func ReadFile ¶
ReadFile reads a regular file with a bounded read, then normalizes its content. The caller retains responsibility for path authorization and reference bases.
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. When present, the document is re-encoded with two-space indentation and a trailing newline. Callers that need the strict string-only $schema contract should use ToJSON, which validates the complete document before removing the hint.
func ToJSON ¶
ToJSON detects content, ignoring filename extensions. The optional path is accepted only for compatibility with callers from before content detection; it never selects the parser. Leading '{' or '[' is reserved for strict JSON (including malformed JSON); other content is YAML. YAML flow collections remain available inside a block document or after '---'. Valid JSON is returned byte-identically unless it has an editor hint. Only a top-level string $schema editor hint is removed, without fetching it; nested $schema and all other members remain for the typed consumer to validate.
func YAMLToJSON ¶
YAMLToJSON converts YAML through the strict bounded representation and then applies the historical two-space JSON presentation used by public callers.
Types ¶
This section is empty.