Oaskit.JsonSchema.Formats (oaskit v0.3.0)

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. While this library does not provide header validation yet, they are supported for OpenAPI specification compliance.

The {:abnf_parsec, "~> 2.0"} dependency is required for them to be available.

  • 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.