liveBook · Manning

OpenAPI specification

As explained in Contract Testing in Action

OpenAPI is a standard, human-readable specification for describing the structure and behavior of HTTP APIs.

When frontend and backend teams work in parallel, an OpenAPI specification gives both sides a shared, human-readable description of the HTTP API. It defines endpoints, request details, and response expectations, supporting frontend mocks and backend test scenarios. As implementation changes, contract tests can verify that the service still matches those expectations before deployment. section 12.1 section 1.4

An OpenAPI specification can describe:

  • Available endpoints and operations, such as GET /movies or GET /movie/{id}. section 12.1
  • Parameters, required fields, response status codes, content types, schemas, properties, and example values. section 1.4 section 12.1
  • Documentation generated from provider code, which tools such as Dredd can execute against a running service. section 11.3.2
  • A shared boundary for contract testing, while leaving infrastructure, database, and deployment-configuration failures to integration tests. section 12.1

Verifying an Express movies API

An Express provider documents GET /movies with a 200 response containing movie objects whose id and year are integers and whose name is a string. The provider exposes the generated specification at /swagger.json. A Dredd configuration points to that specification and the running endpoint; running Dredd tests the documented scenarios and writes a report. Publishing the specification and results enables comparison with consumer contracts. section 11.3.2

openapi: 3.0.3
info:
  title: Contract Testing - OpenAPI 3.0
  version: 1.0.0
tags:
  - name: user
    description: Operations about user
paths:
  /user/{id}:
    get:
      summary: Get an existing user
      operationId: getUser
      parameters:
        - name: id
          in: path
          description: Id of user to return
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        firstName:
          type: string
          example: Marie
        lastName:
          type: string
          example: Cruz

Use the compact YAML listing to inspect how an OpenAPI document combines metadata, paths, parameters, responses, schemas, and examples. section 1.4

How Contract Testing in Action covers it

How deep it goes
Defines endpoints, parameters, responses, schemas, and examples, but stops short of automatically preventing integration bugs without contract-test enforcement.
Examples
Uses user and movie endpoints, Express-generated JSON, Dredd configuration, endpoint execution, and Markdown test reports.
What it assumes
Assumes familiarity with HTTP APIs and development across frontend or backend services, while defining API structure in human-readable terms.
What you can do after
Apply it via Dredd or another API testing tool to verify documented provider interactions before deploying changes.
How it connects
Connects API documentation with integration testing, contract testing, consumer-driven contract testing, mocks, and API testing tools.

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 Contract Testing in Action. The section links point to the parts of the book it draws on.