← Back to blog
Architecture

Documenting a REST API with OpenAPI and Swagger

An API without documentation is an unusable API. OpenAPI has become the de facto standard for describing, documenting and testing your REST APIs. Here's how to get the most out of it.

An undocumented API is a black box. Even your own team forgets the details after a few weeks. OpenAPI (formerly Swagger) solved this problem by defining a standard format — YAML or JSON — to fully describe a REST API: endpoints, parameters, request bodies, responses, error codes, data schemas. This file is both human-readable documentation and a machine-consumable contract.

In Java/Spring Boot, springdoc-openapi automatically generates the specification from @RestController annotations. A few additional annotations (@Operation, @ApiResponse, @Schema) enrich the documentation with minimal effort. Swagger UI, included, exposes an interactive interface allowing direct API calls from the browser — ideal for onboarding new developers. For Node.js, swagger-jsdoc or frameworks like NestJS offer similar integration.

Beyond documentation, OpenAPI unlocks powerful possibilities. Prism (Stoplight) can create a mock server from your specification, allowing the frontend to work in parallel with the backend. Code generation tools like OpenAPI Generator produce typed clients in almost every language. Contract testing tools like Pact verify that the implementation respects the defined contract. The specification becomes the foundation of the entire development chain.

  • Generate the spec automatically from code (springdoc, NestJS)
  • Enrich with real request and response examples
  • Version your OpenAPI spec with your code
  • Use Prism for quick mocks on the frontend side

Have a project in mind?

Let's talk about your challenges and see how Gotan can help.

Contact us