How Literal types are translated to JSON Schema
mainWhen translating a LiteralType, the behavior depends on the diversity of the values within the literal:
- Homogeneous Literals: If all values in the
Literalmap to the same JSON type (e.g.,Literal["a", "b"]), the resulting schema includes both thetypeand theenumkeys. - Heterogeneous Literals: If the values span multiple JSON types (e.g.,
Literal[True, "yes"]), thetypekey is omitted, and only theenumkey is emitted to allow for multi-type validation.
Example behavior:
Literal["a", "b"]$\rightarrow${"type": "string", "enum": ["a", "b"]}Literal[1, "a"]$\rightarrow${"enum": [1, "a"]}