liveBook · Manning

Sad path

As explained in Automating API Delivery

A sad path is an API execution path in which an error or exceptional condition produces an unsuccessful response.

A sad path is an API execution path where an error or exceptional condition produces an unsuccessful response. Testing it checks whether the API handles invalid conditions consistently with its published contract. section 7.4 section 7.8

Use sad paths in two complementary ways:

  • Generate happy- and sad-path schema tests from an OpenAPI definition, then run them against the API gateway or service. section 7.4
  • Write a sad-path test for a custom linting rule and assert the expected diagnostic, location, and severity. section 10.1.2
  • Prefer generated tests when endpoint changes make hand-maintained response scenarios costly; retain code-based tests for multi-call workflows and complex application states. section 7.3

Invalid operation identifier

A linting-rule test supplies a GET operation with operationId "listUsers" even though the convention requires a prefix such as "retrieve" or "download". The sad path expects an error diagnostic at paths → /v1/users → get → operationId, with error severity. section 10.1.2

Figure 7.3 Generating schema tests from an OpenAPI definition
figure

Follow the flow from an OpenAPI definition to generated happy- and sad-path schema tests executed against an API service. section 7.4

How Automating API Delivery covers it

How deep it goes
Defines the failure-path pattern and demonstrates assertions, but does not detail a universal response-handling implementation.
Examples
Uses generated OpenAPI scenarios and an invalid operationId test that expects a precise linting diagnostic.
What it assumes
Assumes an API definition or linting rule and basic test assertions, while showing the required scenario and expected-error structure.
What you can do after
Apply it via Schemathesis, Portman, or custom tests to verify unsuccessful API or linting outcomes.
How it connects
Connects sad paths with API schema testing, OpenAPI, linting rules, happy paths, and end-to-end or controller-level testing.

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.