# schema-format-defined

Source: https://api-genie.dev/docs/linter/asyncapi/rules/schema-format-defined

A rule of the AsyncAPI linter, which reads AsyncAPI 3 documents; the reader rejects AsyncAPI 2 documents. Since 0.9.0. In the rulesets: Recommended at error, Strict at error, All at error.

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 format` when a schema of
  type `integer` does not have the `int32` or `int64` format,
- `Schema with number type does not define proper format` when a schema of
  type `number` does not have the `float` or `double` format.

Turn the rule off if your messages are consumed only by clients written in dynamically typed
languages, where the precision of numbers does not matter.

## Examples

**Good**.

```yaml
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**.

```yaml
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
```
