OpenAPI Specification Exercises
Let's practice writing OpenAPI specifications through hands-on exercises.
Exercise 1: Define a Schema
Loading JavaScript Exercise...
Exercise 2: Complete API Specification
Loading JavaScript Exercise...
Validating OpenAPI
Use tools to validate your specifications:
# Using swagger-cli
npx @apidevtools/swagger-cli validate openapi.yaml
# Using spectral
npx @stoplight/spectral lint openapi.yaml
Common OpenAPI Patterns
Pagination
paths:
/items:
get:
parameters:
- name: page
in: query
schema:
type: integer
default: 1
- name: limit
in: query
schema:
type: integer
default: 20
maximum: 100
Authentication
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
security:
- bearerAuth: []
Summary
You've learned to:
- Build OpenAPI schemas
- Define API endpoints
- Generate complete specifications
- Use common patterns
OpenAPI is essential for modern API development and enables powerful tooling for documentation, testing, and code generation.

