liveBook · Manning

OpenAPI library

As explained in The Design of Web APIs, Second Edition

An OpenAPI library is a separate OpenAPI document or collection of definitions that provides reusable components for other OpenAPI documents.

An OpenAPI library is a separate OpenAPI document containing reusable components for multiple APIs. It centralizes shared schemas, parameters, headers, and responses, improving consistency, interoperability, and maintainability. section 17.1 section 17.6

A library can provide:

Referencing shared pagination

A Shopping API can reuse a Pagination parameter from shared-components.yaml with a reference such as /path/to/shared-components.yaml#/components/parameters/Pagination. Relative references resolve from the location of the referring OpenAPI file. section 17.6.2

Listing 17.18 Creating an OpenAPI library
openapi: 3.1.0
info:
  title: Shared components
  version: "1.0"           #1
 #2

components:     #3
  schemas:
    Errors: ...
  parameters:
    Pagination: ...
  headers:
    ResourceLocation: ...
  responses:
    ResourceNotFound: ...

The component listing shows the minimal shape of an OpenAPI 3.1 library: independent metadata plus a components block, without paths or webhooks. section 17.6.1

How The Design of Web APIs, Second Edition covers it

How deep it goes
Defines library structure, component categories, external references, independent versioning, file independence, and breaking-change cautions.
Examples
Uses Errors, Pagination, ResourceLocation, ResourceNotFound, 500 responses, and Correlation-Id headers as shared components.
What you can do after
Apply it via external $ref and enforce shared-component usage with Spectral; bundle split files when tools require one document.
How it connects
Connects OpenAPI components with JSON Schema, API design guidelines, API governance, and Spectral linting.

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.