livery_openapi_validate (livery v0.2.0)
View SourceRequest validation against a JSON-Schema subset, plus a middleware
that rejects malformed request bodies with 422.
validate/2 checks a decoded JSON term (maps with binary keys,
lists, binaries, numbers, booleans, null) against a schema map.
Supported keywords:
- core:
type(single or a list of types),enum,const - numbers:
minimum,maximum,exclusiveMinimum,exclusiveMaximum,multipleOf - strings:
minLength,maxLength,pattern - objects:
required,properties,additionalProperties(falseor a schema),minProperties,maxProperties - arrays:
items,minItems,maxItems,uniqueItems - combinators:
allOf,anyOf,oneOf
Schema keys may be atoms or binaries; property names inside
properties must be binaries (they are matched against decoded
JSON keys). It is a pragmatic subset, not a complete JSON Schema
implementation ($ref, if/then/else, patternProperties,
and dependentSchemas are not supported).
The call/3 middleware reads #{body_schema => Schema} from its
state, decodes the request's JSON body, validates it, and on
failure short-circuits with a 422 whose body lists the errors.
On success it stores the decoded body under meta(body, Decoded).
Summary
Types
Functions
-spec call(livery_req:req(), livery_middleware:next(), #{body_schema := schema()}) -> livery_resp:resp().
Validate a decoded JSON term against a schema subset.