bodyinput

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package bodyinput decodes a request body supplied as a file, accepting either JSON or YAML.

It exists so the Platform and Security Cloud commands accept the same input formats the Pro generated commands do. The Pro template carries its own copy (normalizeInputToJSON in generator/parser/generator.go's registryTemplate) because generated code stands alone; these two products share this one, so the fallback ladder cannot drift between them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Normalize

func Normalize(raw []byte) (any, error)

Normalize decodes raw as JSON, falling back to YAML, and returns a value built from JSON-native types only (map[string]any, []any, string, float64, bool). YAML input is round-tripped through JSON rather than returned as yaml.v3 decoded it, because yaml.v3 produces types encoding/json refuses to marshal — a mapping with non-string keys decodes to map[any]any, and a timestamp scalar to time.Time. Returning those would move the failure from here to whichever transport marshals the body, where it reads as an internal error rather than as a malformed input file.

The round trip alone cannot do that job, which is the trap this once fell into: json.Marshal is the call that refuses map[any]any, so handing it the value straight turned the two shapes it exists to fix into "re-marshaling YAML as JSON: json: unsupported ..." — the malformed-input error, for a perfectly good YAML file. jsonSafe converts them first and the round trip then only settles number types.

What json.Marshal refuses has moved: Go 1.26 rejects any map[any]any, while 1.27 spells an *integer* key and still rejects a boolean, float or null one ("object member name must be a string"). YAML permits all four, so the walker is still doing work on the current toolchain — and the test pins the resulting shapes rather than an error string, since which keys fail is a moving target.

Input carrying no content is an error rather than a nil body. A nil body means "send no body" to every caller here, so an empty file, a file of YAML comments, or a literal null would otherwise make a write that sent nothing indistinguishable from one that was never given a --file at all.

Types

This section is empty.

Jump to

Keyboard shortcuts

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