def fits

ezmcp@0.1.0.0 · src/openapi.bend:1420

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

1420# whether a value fits a property's schema, one level deep: its `type`
1421# (`typed`), one of its `anyOf` alternatives' types when it has `anyOf`,
1422# and one of its `enum` values when it has `enum`
1423def fits(+sch: Value.Json, +val: Value.Json) -> Bool:
1424  +any = Json.get(sch, "anyOf")
1425  +en = Json.get(sch, "enum")
1426  Bool.and(typed(Json.get(sch, "type"), val),
1427    Bool.and(Bool.or(Bool.not(Json.is_arr(any)), alts(Json.items(any), val)),
1428      Bool.or(Bool.not(Json.is_arr(en)), same.json(val, Json.items(en)))))

Uses (11)

Used by (1)