yamlutil

package
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package yamlutil provides YAML decoding helpers shared across ToolHive.

Index

Constants

View Source
const MaxMappingKeys = 4096

MaxMappingKeys is the largest number of keys Unmarshal accepts in a single mapping. The yaml decoder compares every pair of keys in a mapping, so this bounds decoding to about MaxMappingKeys comparisons per key. Real documents stay far below it: the largest mapping in the MCP Registry OpenAPI spec has 30 keys, and large public OpenAPI specs have around a thousand paths.

Variables

This section is empty.

Functions

func MappingValue

func MappingValue(n *yaml.Node, key string) *yaml.Node

MappingValue returns the value stored under key in the mapping n, or nil if n is not a mapping or has no such key. A document node is looked through to its root, and alias nodes (for n and for the returned value) are resolved. Merge keys ("<<") are not expanded.

func Parse

func Parse(data []byte) (*yaml.Node, error)

Parse parses YAML data into a node tree and rejects duplicate mapping keys in linear time, using the same rule as yaml.Unmarshal (same node kind and value). It returns nil for an empty document.

yaml.Unmarshal into a Go value checks mapping keys for duplicates pairwise and formats an error for every duplicate pair, so a document of repeated keys costs quadratic time and memory (minutes for 64KB). Parsing into a yaml.Node skips that check.

Parse does not limit the number of keys in a mapping. Decoding the returned node into a Go value compares every pair of keys in each mapping it visits, which is quadratic in the number of distinct keys, so read the values you need from the node tree, or use Unmarshal, which caps keys per mapping.

func Unmarshal

func Unmarshal(data []byte, out any) error

Unmarshal decodes YAML data into out like yaml.Unmarshal, with two extra checks done in linear time before decoding: duplicate mapping keys are rejected (the same rule yaml.Unmarshal applies), and so is any mapping with more than MaxMappingKeys keys. Together they keep decoding time proportional to the input size.

Types

This section is empty.

Jump to

Keyboard shortcuts

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