Skip to main content

API Design, OpenAPI & Swagger Deep Dive

An API is a long-lived public contract. Code can be refactored tomorrow; a published field name lives for years because every consumer you cannot see has coded against it. Senior API design is mostly about evolvability, consistency and failure semantics, not about picking GET vs POST.

This group complements the broader API Design - REST, gRPC & GraphQL overview and the API Authentication & Security page with the contract tooling (OpenAPI / Swagger), style guide and governance layer.

The Contract Lifecycle

Design-First API Pipeline (click a stage)

DesignOpenAPI 3.1step 1LintSpectralstep 2Diffoasdiffstep 3MockPrismstep 4CodegenOpenAPI Generatorstep 5Contract TestPact / Schemathesisstep 6PublishPortal / Registrystep 7Every stage is a CI gate: a failing stage blocks merge

Design Β· OpenAPI 3.1

The spec is the contract and source of truth. Model resources, schemas, errors, security schemes, and examples BEFORE writing code. Consumers review via pull request.

Gate: Review by API guild + consumers

openapi.yaml (paths, components.schemas, securitySchemes)

Reading Order

#PageYou will learn
1OpenAPI & Swagger FundamentalsSwagger vs OpenAPI history, document anatomy, schemas, oneOf/discriminator, security schemes, webhooks, tooling
2Spring Boot + springdoc-openapiGenerating specs from code, annotations, groups, security, polymorphism, Pageable, pitfalls
3Naming ConventionsURLs, query params, JSON fields, headers, enums, operationIds, schema names, with a searchable rule book
4Resource Modeling & HTTP SemanticsResource design, custom actions, PUT vs PATCH, conditional requests, long-running operations, bulk APIs
5Errors, Pagination & FilteringRFC 9457 problem details, keyset vs offset pagination (with SQL), sorting, sparse fields, rate-limit headers
6Versioning & EvolutionBreaking-change catalog, versioning strategies, deprecation/Sunset, expand-contract, tolerant reader
7Reliability: Idempotency, Concurrency & WebhooksIdempotency-Key implementation, ETag/If-Match, retries, webhook signing, AsyncAPI
8Contract Governance & TestingDesign-first vs code-first, Spectral, oasdiff, Prism, Pact, Schemathesis, CI gates
9API Security Checklist (OWASP API Top 10)BOLA, mass assignment, rate limiting, OAuth scopes in OpenAPI
10Interview QuestionsJunior to staff-level Q&A and design prompts

Principles Every Page Builds On

  1. Consumers first. Design from the client's task, not from your database tables.
  2. Consistency beats cleverness. One way to paginate, one error format, one naming style - enforced by a linter, not by memory.
  3. Additive evolution. Add optional fields; never repurpose, remove, narrow or rename.
  4. Explicit failure semantics. Every operation documents which errors can happen and whether retrying is safe.
  5. The spec is executable. It drives mocks, SDKs, tests, gateways and docs - so it must be validated in CI.
  6. Least privilege & least data. Return only what the caller may see (BOLA, excessive data exposure).

Swagger vs OpenAPI in One Paragraph

Swagger was the original name of both the specification and the tools (2011, Tony Tam / Reverb). In 2015 the spec was donated to the Linux Foundation as the OpenAPI Initiative and became the OpenAPI Specification (OAS); versions 3.0 (2017) and 3.1 (2021, fully aligned with JSON Schema 2020-12) followed. Swagger now names SmartBear's tooling: Swagger UI, Swagger Editor, Swagger Codegen (the community fork is OpenAPI Generator). "Swagger 2.0" files are legacy; new work should target OAS 3.1.

πŸ“–
Track Page Progress0 / 635 Read
Knowledge Base Completion0%