Linter rulesAsyncAPIschema-format-defined
schema-format-defined
Since 0.9.0
This rule ensures that numeric schemas specify the precision of their values
with a format.
Rule Details
JSON Schema does not limit the size or the precision of numbers. Without a
format, code generators and consumers written in strongly typed languages
have to guess which native type to use, which often leads to overflows or to
lost precision.
The schema-format-defined rule checks every schema of an AsyncAPI document
and reports:
Schema with integer type does not define proper formatwhen a schema of typeintegerdoes not have theint32orint64format,Schema with number type does not define proper formatwhen a schema of typenumberdoes not have thefloatordoubleformat.
Configuration
None.
Examples
Good.
asyncapi: 3.0.0
info:
title: Order Events
version: 1.0.0
components:
schemas:
OrderPlaced:
type: object
properties:
quantity:
type: integer
format: int32
total:
type: number
format: double
Bad.
asyncapi: 3.0.0
info:
title: Order Events
version: 1.0.0
components:
schemas:
OrderPlaced:
type: object
properties:
quantity:
type: integer
total:
type: number
format: decimal
When Not to Use It
You may disable this rule if your messages are consumed only by clients written in dynamically typed languages, where the precision of numbers does not matter.
Compatibility
This rule is compatible with AsyncAPI 3.x documents. AsyncAPI 2.x documents are rejected by the reader and are not linted.