Documentation
¶
Overview ¶
Package yaml is a thin wrapper around go.yaml.in/yaml/v3 for consuming the RawYAML bodies that internal/parsers/grammar/ isolates between `---` fences, plus the typed-extensions service the grammar lexer calls for `extensions:` raw blocks.
Importers:
- The builder layer — bridge taggers that decide when to parse a given RawYAML body (operations, meta, schema).
- internal/parsers/grammar — calls TypedExtensions from its extensions raw-block lexer so Extension.Value ships typed.
The grammar import is the one carve-out from the "grammar stays YAML-free" architecture rule.
See README.md for the long-form rationale (typed-extensions pipeline, dedent strategies, sibling-sub-parser seam).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse unmarshals the given raw YAML body into a generic value (typically a map[string]any or []any). YAML library errors carry their own line/column numbers relative to the body, not to the Go source — callers that need source-relative positions wrap the error with their own annotation position.
Returns (nil, nil) for an empty body so callers can handle "annotation had a fence but no content" without branching on error-vs-nil.
func ParseInto ¶
ParseInto unmarshals body into the given destination, typically a pointer to a struct the caller defined to match an expected YAML shape (e.g., operation-body or extension-value). Wraps the underlying error for uniform error reporting.
func RemoveIndent ¶
RemoveIndent normalises the common leading indentation of a YAML body lifted from a godoc comment block: the first line's indent length is treated as the canonical strip width and applied to every subsequent line. Any tabs in the stripped lines' leading-whitespace run are then expanded to two spaces, because YAML refuses tab indentation.
The first-line dedent (vs "shortest leading-whitespace run across every non-blank line") is the operations / meta path's contract — the existing operation goldens depend on it. The typed-extensions path uses common-prefix dedent instead; see README.md §dedent.
Whitespace tokens recognised here are space (' '), tab ('\t'), and the leading `/` characters that survive when the lexer hasn't stripped a godoc comment marker yet. Unicode space separators (\p{Zs}) are NOT recognised: real Go source code uses ASCII whitespace. If a corpus surfaces that depends on it, reintroduce the Unicode branch.
func TypedExtensions ¶
TypedExtensions parses the body of an `extensions:` raw block and returns its top-level entries as JSON-typed values (bool / float64 / string / []any / map[string]any).
The body is dedented before parsing — the grammar lexer preserves godoc-level indentation per line, but YAML refuses tab indentation and treats leading whitespace as structural. The YAML → JSON normalisation enforces map[string]any with concrete leaf types via swag/yamlutils.YAMLToJSON; downstream consumers (vendor-extension targets, code generators, AddExtension surfaces) rely on that shape.
No name filtering is applied here: the caller decides whether to accept only x-* keys (via classify.IsAllowedExtension) or to consume the full mapping. Empty body returns (nil, nil).
See README.md §typed-extensions for the full contract.
func UnmarshalBody ¶
UnmarshalBody runs a raw godoc-comment YAML body through the standard godoc → YAML → JSON pipeline expected by every Swagger target that consumes JSON-shape input:
- RemoveIndent — strip the common indent godoc adds to every line and turn leading tabs into two-space sequences (YAML refuses tab indentation).
- yaml.Unmarshal into a generic map[any]any.
- yamlutils.YAMLToJSON — coerce the map[any]any soup into JSON-shaped values with concrete leaf types.
- Hand the resulting JSON bytes to the caller's callback, typically a *spec.<Target>.UnmarshalJSON or a json.Unmarshal into a caller-provided struct.
Empty body returns nil — the caller's target is left untouched.
Used by the operations bridge (swagger:operation YAML body), the meta bridge (securityDefinitions, infoExtensions, extensions raw blocks), and any future target that needs the same shape.
Types ¶
This section is empty.