liveBook · Manning

Semantic versioning

As explained in The Design of Web APIs, Second Edition

A semantic version number is a version identifier with major, minor, and patch components whose changes conventionally communicate compatibility impact.

Semantic versioning communicates compatibility impact through major, minor, and patch components. For API interfaces, increment major versions for breaking changes and minor versions for backward-compatible changes; reserve patch versions for implementation bug fixes rather than API versioning. section 15.4.2

API changes map to version increments according to their effect on consumers:

  • Add a backward-compatible operation: increment the minor version, such as 1.0 to 1.1. section 15.4.2
  • Add backward-compatible response fields: increment the minor version, such as 1.1 to 1.2. section 15.4.2
  • Replace a path parameter or remove always-returned data: increment the major version, such as 1.2 to 2.0 or 3.0. section 15.4.2

Representing the version in OpenAPI

Set the API version as a quoted string in info.version: version: "1.2". If the document itself changes without changing the interface contract, use a document patch value such as version: "1.2.1". Check generated documents because tools may insert an implementation version instead of the API version. section 15.7.1

Figure 15.9 Semantic versioning indicates the type of change and date-based versioning doesn’t.
figure

Compare semantic versioning, which signals the type of change, with date-based versioning, which signals release timing but requires documentation to identify differences. section 15.4.2

Choose the scheme and its representation early, assess affected consumers before breaking changes, and document updates with changelogs and deprecated elements. Semantic versioning is the default choice; date-based versions may suit frequent, regular releases. section 15.8

Automated enforcement

A Spectral rule can target $.info.version and validate the API and document version format. Test the JSONPath on a valid OpenAPI document before replacing a temporary undefined function with the final validation function. section 18.12 section 18.5.1

How The Design of Web APIs, Second Edition covers it

How deep it goes
Explains major, minor, and patch roles, applies them to API changes, and shows OpenAPI representation and linting.
Examples
Uses banking operations, path parameters, response fields, OpenAPI info.version, and a Spectral rule.
What it assumes
Assumes familiarity with APIs and OpenAPI documents while explaining compatibility effects through concrete banking changes.
What you can do after
Apply semantic API versions, represent them in OpenAPI, compare date-based alternatives, and enforce formats with Spectral.
How it connects
Connects API versioning with backward compatibility, breaking changes, OpenAPI, date-based versioning, deprecation, and Spectral.

Also explained in

Compare how 8 books explain semantic versioning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.