liveBook · Manning

OpenAPI specification

As explained in Automating API Delivery

The OpenAPI Specification is a standard machine-readable format for describing HTTP APIs, including their operations, inputs, and responses.

When an API reference promises a response field that the live API omits, consumers cannot rely on the published contract. The OpenAPI Specification (OAS) provides a shared, machine-readable way to describe an HTTP API before implementation and check it afterward. OAS is the standard; an OpenAPI definition is a YAML or JSON file describing a particular API. section 6.1 section 1.4

A definition describes operations, expected requests and responses, and security mechanisms. OAS can describe an HTTP API whether or not it is RESTful. It is not the same as JSON:API, which prescribes how to design a REST API; an API following JSON:API can still be described in an OpenAPI definition. section 1.4 section 3.2

Figure 4.3 Top-level structure of an OpenAPI document structure
figure

Use the document-structure diagram to locate the root OpenAPI object before following paths to path items and operations. section 4.2

Treat the definition as a working contract throughout delivery:

  • Design it first, then render documentation or mock the API for consumer feedback before writing the backend. section 1.5.1
  • Keep it in Git and review changes through pull requests. Run automated linting against design rules; reserve human review for questions such as resource models and operation design. section 1.5.2 section 1.7
  • Compare definition versions for breaking changes, generate server or client code where useful, and test the running API against the agreed operations and response schemas. section 1.6 section 1.5.4
  • Publish API reference documentation from the authoritative definition, and update that definition when requirements change. section 6.1 section 6.2.5

Find and prevent contract drift

Suppose GET /v1/catalog/products/{id} declares keywords mandatory, but the live response omits it. A rendered reference repeats the promise; it does not prove the server meets it. Update the authoritative definition when requirements change, generate controller code from it where appropriate, and run conformance tests against the implementation. For design-time feedback, a Spectral ruleset in VS Code can highlight violations directly in an OpenAPI file. section 6.1 section 1.5.4 section 3.5

Automation checks what can be expressed as rules or tested against a running API; it does not replace consumer feedback and design judgment. Hand-writing YAML can also be slow, so choose editing tools that integrate with the Git repository holding the primary definition. section 1.7 section 1.8

How Automating API Delivery covers it

How deep it goes
Defines the standard and definition-file distinction, illustrates document hierarchy, and follows operational workflows rather than specifying every OAS field.
Examples
Uses a missing mandatory response field, a changed catalog endpoint, Spectral editor feedback, and regenerated API reference documentation.
What it assumes
Assumes familiarity with HTTP APIs and Git workflows; distinguishes OAS from a particular API definition and from JSON:API.
What you can do after
Apply it via Git-based reviews, Spectral linting, conformance checks, and generated documentation to keep an API definition useful through delivery.
How it connects
Connects API design-first development with Git, API linting, breaking-change checks, API conformance testing, code generation, and developer portals.

Also explained in

Compare how 12 books explain OpenAPI specification →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Automating API Delivery. The section links point to the parts of the book it draws on.