Skip to content
Last updated

no-schema-type-mismatch

Ensures that a schema's structural properties match its declared type. In particular:

  • Only a schema of type array may include an items field.
  • Only a schema of type object may include a properties field.

The rule checks only schemas whose type is a single value. Schemas with a list of types, such as type: [string, 'null'], are not checked.

OASCompatibility
2.0✅
3.0✅
3.1✅
3.2✅
AsyncAPICompatibility
2.6✅
3.0✅
ArazzoCompatibility
1.0✅

if type is not array

if type is not object

Schema

'items' field exists?

'properties' field exists?

if type is not array

if type is not object

Schema

'items' field exists?

'properties' field exists?

API design principles

When designing an API schema, the defined type should be consistent with its structure:

  • Objects are collections of key/value pairs. They should be defined using properties (or additionalProperties) and must not use items.
  • Arrays are ordered lists of items and must use items to define their content. Including properties is invalid.
  • Primitive types (string, number, integer, boolean, null) have neither properties nor items.

This rule helps catch typos and misconfigurations early in your API definition.

Configuration

OptionTypeDescription
severitystringPossible values: off, warn, error. Default is error in the recommended configuration.

Example configuration:

rules:
  no-schema-type-mismatch: error

Examples

Incorrect Examples

Object type with an items field

properties:
  user:
    type: object
    properties:
      id:
        type: string
    items:
      type: number

Error: An object type should not include an items field.

Array type with a properties field

properties:
  tags:
    type: array
    properties:
      name:
        type: string

Error: An array type should not include a properties field.

Primitive type with a properties field

properties:
  notification_email:
    type: string
    properties:
      address:
        type: string

Error: A string type should not include a properties field.

Correct Examples

Object type with proper properties

properties:
  user:
    type: object
    properties:
      id:
        type: string
      name:
        type: string

Array type with proper items

properties:
  tags:
    type: array
    items:
      type: string

Resources