Tutorials
OpenAPI Spec Validation: Common Errors and How to Fix Them
Every OpenAPI validation error has a pattern. Here are the 10 errors you will hit most often, why they happen, and the exact fix, with copy-paste YAML.
Morgan Kotter · Updated March 30, 2026
OpenAPI validation errors block documentation generation, break code generators, and prevent CI pipelines from passing. The error messages are often cryptic. A single misplaced property can cascade into dozens of downstream failures.
This guide covers the 10 most common validation errors across OpenAPI 3.0 and 3.1 specs, ordered by frequency. Each error includes the exact error message you will see, why it happens, and a before/after YAML fix. If you are chasing one specific message from Spectral, swagger-cli, kin-openapi, or openapi-generator, the OpenAPI error reference has a dedicated page per error with a minimal reproduction.
1. Broken $ref Path
Error: Can't resolve $ref: #/components/schemas/user
The most common OpenAPI error. A $ref points to a schema that does not exist, usually because of a case mismatch or typo.
Broken (case mismatch)
# The $ref says "user" but the schema is "User"
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/user' # lowercase
components:
schemas:
User: # uppercase
type: objectFixed
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User' # matches exactly
components:
schemas:
User:
type: objectFix: $ref values are case-sensitive. Search your spec for every $ref and verify the target exists with the exact same casing.
2. Missing responses Object
Error: Operation must have at least one response defined
Every operation (get, post, etc.) requires a responses object. This is easy to forget on draft endpoints.
Missing responses
paths:
/health:
get:
summary: Health check
# No responses definedFixed
paths:
/health:
get:
summary: Health check
responses:
'200':
description: Service is healthy3. Invalid type Value
Error: Schema type must be one of: string, number, integer, boolean, array, object
OpenAPI 3.0 only allows six types. Common mistakes: using float (use number with format: float), date (use string with format: date), or null (use nullable: true in 3.0, or type: ['string', 'null'] in 3.1).
Invalid types
# These are NOT valid OpenAPI types
properties:
price:
type: float # not a valid type
birthday:
type: date # not a valid type
deleted_at:
type: null # not valid in 3.0Fixed
properties:
price:
type: number
format: float
birthday:
type: string
format: date
deleted_at:
type: string
format: date-time
nullable: true # OpenAPI 3.0
# For 3.1: type: ['string', 'null']4. Example/Default Type Mismatch
Error: Example value "100" is not valid for schema type integer
YAML treats unquoted numbers as integers and quoted values as strings. If your schema says type: integer but your example is "100"(a string), validation fails.
Mismatched example types
properties:
port:
type: integer
example: "8080" # string, not integer
enabled:
type: boolean
example: "true" # string, not booleanFixed
properties:
port:
type: integer
example: 8080 # unquoted = integer
enabled:
type: boolean
example: true # unquoted = boolean5. Duplicate operationId
Error: operationId "getUser" is already used by another operation
Every operationId must be unique across the entire spec. This commonly happens when copy-pasting endpoint definitions.
Fix: Use a consistent naming convention like verb + Resource: listUsers, getUser, createUser, updateUser, deleteUser.
6. Missing or Invalid info Object
Error: Info object must have a title and version
The info object at the root of every spec requires title and version. Both must be strings. A common mistake: using a number for version.
Invalid info
openapi: 3.0.3
info:
title: My API
version: 1.0 # number, not stringFixed
openapi: 3.0.3
info:
title: My API
version: "1.0" # stringSpecway reads your spec on import and builds the reference from it, so fixing these errors first means fewer surprises in the published docs. Import your spec.
7. Path Parameter Not Declared
Error: Path parameter "id" must be defined in the parameters section
If your path contains {id}, there must be a matching parameter definition with in: path and required: true.
Missing path parameter definition
paths:
/users/{id}: # {id} in path
get:
summary: Get user
responses:
'200':
description: OK
# No parameters defined for {id}Fixed
paths:
/users/{id}:
get:
summary: Get user
parameters:
- name: id
in: path
required: true # path params MUST be required
schema:
type: string
responses:
'200':
description: OK8. Required Field Not in Properties
Error: Required property "email" is not defined in properties
Every item in the required array must match a key in properties. Typos in either location cause this error.
Mismatched required field
schemas:
User:
type: object
required:
- email # listed as required
properties:
email_address: # but the property is named differently
type: stringFixed
schemas:
User:
type: object
required:
- email_address # matches the property name
properties:
email_address:
type: string9. Invalid HTTP Status Code
Error: Response status code must be a string "200", not integer 200
In OpenAPI, HTTP status codes under responses must be strings (quoted). YAML interprets unquoted 200 as an integer.
Integer status codes
responses:
200: # YAML sees this as integer
description: OK
404:
description: Not foundFixed
responses:
'200': # quoted string
description: OK
'404':
description: Not found10. Array Without items
Error: Schema of type array must have an items property
Every type: array schema requires an items definition. Without it, tools cannot generate types or validate responses.
Array without items
properties:
tags:
type: array
# Missing items definitionFixed
properties:
tags:
type: array
items:
type: stringValidation Tools
Run validation before every commit. Here are the main options:
# Spectral (most popular, customizable rules)
npx @stoplight/spectral-cli lint openapi.yaml
# Redocly CLI
npx @redocly/cli lint openapi.yaml
# swagger-cli (basic validation)
npx swagger-cli validate openapi.yaml
# Online: paste your spec at editor.swagger.ioAdd linting to CI so invalid specs never reach production:
# .github/workflows/lint-spec.yml
name: Lint OpenAPI
on: [pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npx @stoplight/spectral-cli lint openapi.yaml