Oaskit.JsonSchema.Formats (oaskit v0.14.0)

Copy Markdown View Source

Implements formats described in https://spec.openapis.org/api/format.json for JSV's format validation. Some of the described formats are already implemented in JSV directly.

All schemas used by this library can use those formats in any schema, on top of all formats already supported by JSV.

Use the Oaskit.jsv_opts/0 callback to add your own formats.

The html and commonmark formats are not validating anything and will accept any string.

Number formats

Number formats apply to the number JSON type. So an int16 format will be used on floats and reject them.

Decimal values are supported.

  • double
  • double-int
  • float
  • int16
  • int32
  • int8
  • uint16
  • uint32
  • uint8

Numeric formats

Those apply to numbers and strings, as their value is not representable in every programming language.

Decimal values are supported.

  • decimal
  • decimal128
  • int64
  • uint64

String formats

String formats only apply when the value is a string, much like the default JSON schema formats like "date", "uri", etc..

  • base64url
  • binary
  • byte
  • char
  • commonmark
  • html
  • media-range
  • password

HTTP Structured fields formats

HTTP structured fields are generally used for headers. These formats validate and cast a string into the corresponding structured field value, so they can be used on header parameter schemas (in: :header).

These are the structured field bare items defined by the OpenAPI Format Registry. RFC 8941 lists and dictionaries are not part of the registry and are not supported, see the comment on the format definitions in this module.

  • sf-binary
  • sf-boolean
  • sf-decimal
  • sf-integer
  • sf-string
  • sf-token

Summary

Functions

applies_to_type?(format, data)

Callback implementation for JSV.FormatValidator.applies_to_type?/2.

supported_formats()

Callback implementation for JSV.FormatValidator.supported_formats/0.

validate_cast(binary, data)

Callback implementation for JSV.FormatValidator.validate_cast/2.