apiexample

package
v1.1.11 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateAndMarshalToMap

func ValidateAndMarshalToMap(example any) map[string]any

ValidateAndMarshalToMap marshals the JSON-body fields of a struct into a map whose shape matches the actual wire payload, so generated examples agree with the generated schema. It mirrors encoding/json with one deliberate exception: exported fields without a json tag (path/query/header-only request fields) are dropped so body examples stay payload-only.

In particular, and unlike a naive "skip every empty value" marshaller:

  • a non-omitempty pointer that is nil is emitted as JSON null — a nullable "value or null" response field stays visible instead of vanishing;
  • omitempty/omitzero fields are dropped only when empty, exactly like the wire;
  • field.Optional[T]/field.Clearable[T] encode through their own MarshalJSON (set value, or null for an explicit Clearable clear) and drop when unset.

Types

This section is empty.

Jump to

Keyboard shortcuts

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