A2UICore.Catalog.SchemaCleaner (A2UICore v0.1.1)

Copy Markdown View Source

Normalizes the schema nodes a catalog's validation schema is assembled from, as the reference catalog does before bundling common types:

  • a title keyword is dropped unless it was marked as authored (mark_titles/1);
  • default: null and items: {} are dropped;
  • null branches leave unions, and a union with one branch left becomes that branch;
  • an inline dynamic value union (a literal, a DataBinding and a FunctionCall branch) becomes a $ref to the common type it matches (DynamicString, DynamicStringList, DynamicValue, …);
  • anyOf becomes oneOf, except under additionalProperties and where a branch only constrains (required without type).

clean/2 also reports the #/$defs/… names the result references.

Summary

Types

The dynamic value defs of a common types document, by the literal branches of their unions.

Functions

Cleans node (see the module doc) with the dynamic value index, returning the cleaned node and the #/$defs/… names it references.

Builds the dynamic value index of a $defs map: every def whose union has a DataBinding branch, a FunctionCall branch and literal branches.

Marks the title keywords of an authored schema so clean/2 keeps them. A property named title and the values of data keywords (const, default, enum, examples) are left alone.

Types

index()

(since 0.1.0)
@type index() :: %{
  names: MapSet.t(String.t()),
  by_scalar_kind: %{optional(String.t()) => String.t()},
  catch_all: String.t() | nil,
  by_literal_shape: %{optional(term()) => String.t()}
}

The dynamic value defs of a common types document, by the literal branches of their unions.

Functions

clean(node, index)

(since 0.1.0)
@spec clean(term(), index()) :: {term(), MapSet.t(String.t())}

Cleans node (see the module doc) with the dynamic value index, returning the cleaned node and the #/$defs/… names it references.

index(defs)

(since 0.1.0)
@spec index(map()) :: index()

Builds the dynamic value index of a $defs map: every def whose union has a DataBinding branch, a FunctionCall branch and literal branches.

mark_titles(node, in_properties \\ false)

(since 0.1.0)

Marks the title keywords of an authored schema so clean/2 keeps them. A property named title and the values of data keywords (const, default, enum, examples) are left alone.