OpenAPI Errors Cheat Sheet

8 most common validation errors & how to fix them

1

nullable Is Deprecated in OpenAPI 3.1

In OpenAPI 3.1, nullable: true is no longer valid. Use JSON Schema style with null in the type array.

✗ Broken
components:
  schemas:
    UserNickname:
      type: string
      nullable: true  # ✗ deprecated
✓ Fixed
components:
  schemas:
    UserNickname:
      type:
        - string
        - "null"  # ✓ 3.1

Ref: spec.openapis.org/oas/v3.1.0

2

Payload Must Match Exactly One Schema in oneOf

oneOf requires the payload to validate against exactly one subschema. Add a discriminator with unique enum values to prevent ambiguity.

✗ Broken
Pet:
  oneOf:
    - $ref: '#/…/Cat'
    - $ref: '#/…/Dog'
# Cat & Dog have same shape
# → matches both → error
✓ Fixed
Pet:
  oneOf:
    - $ref: '#/…/Cat'
    - $ref: '#/…/Dog'
  discriminator:
    propertyName: petType
Cat:
  properties:
    petType: { enum: [cat] }

Ref: json-schema.org · combining

3

Reference Object Must Have Required Property $ref

A Reference Object that lacks a $ref property is invalid. Replace any bare descriptions with a proper $ref pointing to a defined component.

✗ Broken
schema:
  # missing $ref!
  description: User ref
✓ Fixed
schema:
  $ref: '#/components/
         schemas/User'

Ref: spec.openapis.org · reference-object

4

Object Must NOT Have Additional Properties

When additionalProperties: false is set, every key in an example or payload must be defined in properties. Either add the missing key or remove it from the example.

✗ Broken
User:
  additionalProperties: false
  properties:
    id: { type: integer }
    email: { type: string }

example:
  id: 1
  role: admin  # ✗ not defined
✓ Fixed
User:
  additionalProperties: false
  properties:
    id: { type: integer }
    email: { type: string }
    role: { type: string }

example:
  id: 1
  role: admin

Ref: json-schema.org · object

5

Value Must Be Equal to One of the Allowed Values (enum)

When a field uses enum, the provided value must be one of the listed options. Update the example or extend the enum to include the value.

✗ Broken
status:
  type: string
  enum:
    - pending
    - paid
    - cancelled

# example value:
status: completed  # ✗ not in enum
✓ Fixed
status:
  type: string
  enum:
    - pending
    - paid
    - cancelled

# example value:
status: paid  # ✓ in enum

Ref: json-schema.org · enum

6

Value Must Be String

When a schema declares type: string, the example value must be a string — not a number, boolean, or object. Wrap the value in quotes.

✗ Broken
username:
  type: string

# example value:
username: 12345  # ✗ number
✓ Fixed
username:
  type: string

# example value:
username: "12345"  # ✓ string

Ref: json-schema.org · string

7

Value Must Be Array

When a schema defines type: array, the example must be a list — not a single string or object. Wrap the value in YAML sequence syntax.

✗ Broken
tags:
  type: array
  items:
    type: string

tags: backend  # ✗ single string
✓ Fixed
tags:
  type: array
  items:
    type: string

tags:
  - backend  # ✓ array

Ref: json-schema.org · array

8

Cannot Resolve $ref (Broken Reference)

A $ref pointing to a component path that does not exist causes validation to fail. Make sure the target schema name matches exactly what is defined under components/schemas.

✗ Broken
schema:
  $ref: '#/components/
         schemas/Product'
# …but only "Item" defined:
schemas:
  Item: { ... }
✓ Fixed
schema:
  $ref: '#/components/
         schemas/Product'

schemas:
  Product:  # ✓ name matches
    type: object

Ref: spec.openapis.org · reference-object

Automate these checks in CI

The ApiNotes OpenAPI Validate & Diff GitHub Action validates your spec and detects breaking changes on every PR.

- uses: apinotes/openapi-validate@main
  with:
    api-key: ${{ secrets.APINOTES_API_KEY }}
    spec-path: 'openapi.yaml'
    diff-enabled: 'true'
    fail-on-errors: 'true'
    comment-on-pr: 'true'
Install from GitHub Marketplace →