def with.null

ezmcp@0.1.0.0 · src/openapi.bend:437

import ezmcp@0.1.0.0/src/openapi.bend as Openapi
import Base
import emerging-ezjson@1.2.0.0/main.bend as Json
import emerging-ezjson@1.2.0.0/src/value.bend as Value

437# a type that also admits null (OpenAPI 3.0 `nullable`): a type name as an
438# array of it and "null", an array of names with "null" added when it lacks
439# it, anything else as it is
440def with.null(typ: Value.Json) -> Value.Json:
441  match typ:
442    case Value.JStr{str}:
443      Json.arr([Value.JStr{str}, Json.str("null")])
444    case Value.JSpan{src, +n}:
445      Json.arr([Value.JSpan{src, n}, Json.str("null")])
446    case Value.JArr{+cs}:
447      with.null.arr(any.null(Json.items(Value.JArr{cs})),
448        Json.items(Value.JArr{cs}))
449    case other:
450      other

Uses (7)

Used by (1)