# schema-format-defined

Source: https://apigenie.pl/docs/linter/openapi/rules/schema-format-defined

A rule of the OpenAPI linter, which reads OpenAPI 3.0, 3.1 and 3.2 documents. Since 0.0.1. In the rulesets: Recommended at error, Strict at error, All at error.

This rule checks that every `integer` and `number` schema has a `format` that says its size:
`int32`, `int64` or another integer format for integers, `float`, `double`, `decimal` or another
number format for numbers.

## Rule details

A bare `integer` is a 32-bit `int` in one generated client and a 64-bit one in another, and a
bare `number` is a `float` in one and a `double` in the next; an ID that fits one and not the
other is a bug found in production. The format names the size, and every generator picks the
same type.

The rule accepts, for `integer`, the integer formats of the
[OpenAPI format registry](/docs/reference/cli/formats) (`int8` to `uint64`, `int32`, `int64`,
`double-int`, `sf-integer`) and `unixtime`; for `number`, the number formats (`float`, `double`,
`decimal`, ...); and a format of `openapi.custom_formats` of the matching type. It reports
`Schema with integer type does not define proper format` and `Schema with number type does not
define proper format`.

## Examples

**Good**. A 64-bit identifier.

```yaml
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          format: int64
```

**Bad**. 32 or 64 bits? Each generator decides.

```yaml
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
```
