Ensures that a schema's structural properties match its declared type. In particular:
- Only a schema of type
arraymay include anitemsfield. - Only a schema of type
objectmay include apropertiesfield.
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.
| OAS | Compatibility |
|---|---|
| 2.0 | ✅ |
| 3.0 | ✅ |
| 3.1 | ✅ |
| 3.2 | ✅ |
| AsyncAPI | Compatibility |
|---|---|
| 2.6 | ✅ |
| 3.0 | ✅ |
| Arazzo | Compatibility |
|---|---|
| 1.0 | ✅ |
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 useitems. - Arrays are ordered lists of items and must use
itemsto define their content. Includingpropertiesis invalid. - Primitive types (
string,number,integer,boolean,null) have neitherpropertiesnoritems.
This rule helps catch typos and misconfigurations early in your API definition.
| Option | Type | Description |
|---|---|---|
| severity | string | Possible values: off, warn, error. Default is error in the recommended configuration. |
Example configuration:
rules:
no-schema-type-mismatch: error
properties:
user:
type: object
properties:
id:
type: string
items:
type: number
Error: An object type should not include an items field.
properties:
tags:
type: array
properties:
name:
type: string
Error: An array type should not include a properties field.
properties:
notification_email:
type: string
properties:
address:
type: string
Error: A string type should not include a properties field.
properties:
user:
type: object
properties:
id:
type: string
name:
type: string
properties:
tags:
type: array
items:
type: string