Documentation
¶
Overview ¶
Package defaults synthesizes an example value map from an OpenAPI schema.
Generate is the only entry point. It walks the schema's properties and produces a value for each one using this precedence:
- The `x-example` extension (single illustrative value).
- The `x-examples` extension (first entry, including the OpenAPI 3.0 named-examples map form).
- `enum`, preferring `default` if set, else the first enum value.
- Object walk — explicit `type: object`, structural `properties`, or composition keywords (allOf / oneOf / anyOf) contribute properties. If `default` is a map, it is overlaid on top of the walked properties (same precedence rule as `x-example`), so a schema can declare both a property set and a richer default map without losing either.
- `default` for non-object schemas (deep-copied so callers may mutate).
- Array walk — one element synthesized from `items.schema`.
- Scalar placeholder by type: 123 for integer/number, true for boolean, a pattern-matching string via reggen for string.
Properties the generator cannot synthesize (unknown types, dynamic additionalProperties, tuple-form arrays) are silently omitted.
Output is deterministic for a given input schema.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
Generate synthesizes an example value map from an OpenAPI schema.
Returns (nil, nil) when root is nil, which is the contract callers rely on for optional schema files that may be absent on disk.
The returned map and all nested values are freshly allocated, so callers may mutate the result without affecting the schema in memory.
Types ¶
This section is empty.