yera.runtime.form_widgets

Map JSON Schema nodes onto form input widgets.

Symbols

def field_label — Return the label shown for a form field.
def form_schema — Describe a model's fields for form rendering.
def inline_refs — Replace local ``$ref`` pointers with the definitions they name.
def redact_secrets — Mask every secret value in a submitted form.
def repeat_item_label — Return the noun for one row of a repeated field.
def struct_variants — Return the struct members of a union field.
def unwrap_optional — Return the value schema of an optional field.
def variant_constant — Return the constant a struct union member fixes for a field.
def variant_discriminator — Return the constant field shared by every member of a struct union.
def widget_for — Choose the input widget presenting one schema property.

field_label

field_label(
    node: Mapping[str, JsonValue],
    path: str,
) → str

Return the label shown for a form field.

Parameters

node
type: Mapping[str, JsonValue]

The field's schema node.

path
type: str

Dotted path of the field within the form.

Returns

type: str

The node's explicit title, or the last path segment with underscores replaced by spaces.

form_schema

form_schema(
    model_type: type[BaseModel],
) → dict[str, JsonValue]

Describe a model's fields for form rendering.

Parameters

model_type
type: type[BaseModel]

Pydantic model or struct class declaring the form fields.

Returns

type: dict[str, JsonValue]

The model's JSON Schema with references inlined, keeping only the titles declared explicitly on its fields.

Raises

ValueError

If the model's fields refer back to the model itself.

inline_refs

inline_refs(
    schema: Mapping[str, JsonValue],
) → dict[str, JsonValue]

Replace local $ref pointers with the definitions they name.

Parameters

schema
type: Mapping[str, JsonValue]

A JSON Schema whose references point into its $defs.

Returns

type: dict[str, JsonValue]

A copy of the schema without $defs in which every reference is replaced by its definition. Keys beside a reference take precedence, and a definition's type title is not copied onto the field.

Raises

ValueError

If a definition refers back to itself.

redact_secrets

redact_secrets(
    values: Mapping[str, JsonValue],
    schema: Mapping[str, JsonValue],
) → dict[str, JsonValue]

Mask every secret value in a submitted form.

Parameters

values
type: Mapping[str, JsonValue]

Submitted JSON values keyed by field name.

schema
type: Mapping[str, JsonValue]

Inlined form schema describing those values.

Returns

type: dict[str, JsonValue]

A copy of the values in which every write-only field holds the mask.

repeat_item_label

repeat_item_label(
    node: Mapping[str, JsonValue],
) → str

Return the noun for one row of a repeated field.

Parameters

node
type: Mapping[str, JsonValue]

A list field's schema node.

Returns

type: str

The field's ui.item_label, or "row" when it sets none.

struct_variants

struct_variants(
    node: Mapping[str, JsonValue],
) → list[Mapping[str, JsonValue]]

Return the struct members of a union field.

Parameters

node
type: Mapping[str, JsonValue]

An inlined schema node declaring oneOf or anyOf members.

Returns

type: list[Mapping[str, JsonValue]]

The members that describe structs, in declaration order.

unwrap_optional

unwrap_optional(
    node: Mapping[str, JsonValue],
) → Mapping[str, JsonValue] | None

Return the value schema of an optional field.

Parameters

node
type: Mapping[str, JsonValue]

A resolved JSON Schema property node.

Returns

type: Mapping[str, JsonValue] | None

The non-null member of a T | None union, or None when the node is not an optional single type.

variant_constant

variant_constant(
    member: Mapping[str, JsonValue],
    key: str,
) → JsonValue

Return the constant a struct union member fixes for a field.

Parameters

member
type: Mapping[str, JsonValue]

One struct member of a union field.

key
type: str

The discriminating field name.

Returns

type: JsonValue

The member's constant for that field, or None when it has none.

variant_discriminator

variant_discriminator(
    members: list[Mapping[str, JsonValue]],
) → str | None

Return the constant field shared by every member of a struct union.

Parameters

members
type: list[Mapping[str, JsonValue]]

Struct members of a union field.

Returns

type: str | None

The alphabetically first field that every member fixes to a constant, or None when the members share none.

widget_for

widget_for(
    node: Mapping[str, JsonValue],
) → Widget

Choose the input widget presenting one schema property.

Parameters

node
type: Mapping[str, JsonValue]

A resolved JSON Schema property node.

Returns

type: Widget

The widget kind used to present the property.