AC-011 Contract caught CS-RESP-009

A body that can have several shapes fits none of them

The response does not match the contract

How to run this card's commands yourself

1. The problem

In one sentence

The spec allows a body to have one of several shapes (oneOf or anyOf), and the response fits none of them.

A story

An endpoint can answer in one of two shapes: a body with a field a, or a body with a field b. The spec lists these two shapes. After a change, the server answers {"c": 1}, a third shape nobody declared. The client decides what to do by checking which field is present. It finds neither, and does nothing.

Why it hurts

Polymorphic bodies are where clients are most fragile: they branch on a field and have no fallback. A shape outside the list is not a small mistake; it is a new kind of answer.

  • For developers: the error often says only “no shape matched”, which is hard to debug without help. The usual cause is a discriminator field with a wrong or new value.
  • For managers: a whole category of results silently disappears from a screen or a report.
  • For DevOps: this is a strong signal after a deploy that adds a new result type: update the spec in the same change.

Example

The spec fragment (AorB):

AorB:
  oneOf:
    - type: object
      required: [a]
      properties:
        a: { type: string }
    - type: object
      required: [b]
      properties:
        b: { type: string }

The response from GET /contract-fail/cases/resp-009-oneof-no-match:

{"c": 1}

How to detect it without clrsig

  • curl -s URL | jq 'keys' and compare with the fields of each allowed shape.
  • In a review, ask: “which code decides which shape to send, and what does it do for a case nobody listed?”

How to fix it

There are two usual causes:

  1. The code is wrong. It sends a field name or a discriminator value that is not in any shape. Fix it so it matches one.
  2. The spec is out of date. A new result type was added. Add the new shape to the spec (and tell clients).

To tell which: ask whether the new shape is intended. Never silence the check.

AC-005 A required field is missing, AC-006 A field has the wrong type, AC-012 An extra field in a closed schema.

Words used on this page are explained once in the glossary.

2. How clrsig helps

Check

CS-RESP-009 Body matches no oneOf / anyOf branch (finding no-branch-matched). State: caught. Severity today: failure (exit code 1). For oneOf, a body that fits more than one shape is also reported.

Command

--paths limits the run to this one GET, so nothing is written:

clrsig conform specs/contract-fail.yaml \
  -b http://localhost:8080/contract-fail \
  --env clrsig/environments/contract-fail.yaml \
  --paths /cases/resp-009-oneof-no-match --explain

Exit code: 0 clean, 1 a finding, 2 the spec or the setup is broken. Here it is 1.

What you see

Output from clrsig v0.21.0, recorded on 2026-11-30. The lines for the 36 operations that --paths skipped are left out by grep -v '^ SKIP'; no line is edited.

contract-fail API  1.0.0
Base URL: http://localhost:8080/contract-fail
Limited by --paths /cases/resp-009-oneof-no-match

  FAIL  GET     /cases/resp-009-oneof-no-match  200  16ms
         ✗ GET /cases/resp-009-oneof-no-match 200: the response body matches none of the 2 shapes the spec allows (oneOf); the first shape fails because: Error at "/a": property "a" is missing
         → [CS-RESP-009] The response body fits none of the allowed shapes. Why: The spec allows several shapes for this body (oneOf / anyOf) and the response fits none of them. Where: response body (spec: GET /cases/resp-009-oneof-no-match → response 200 → body schema). Fix: Make the response match one declared shape (for a discriminator, send its property), or add the shape the server really sends to the spec.

FAILED  37 operations  ·  0 passed  ·  1 failed  ·  36 skipped  16ms

How to read it: clrsig says how many shapes the spec allows (2) and why the first one fails. It does not blame one field, because the body could have been meant for any of them.

Where to look

  • Desktop app: Check Conformance lists the failure. Help, What We Check lists CS-RESP-009.
  • Reports: with --format json, the finding carries "checkId": "CS-RESP-009" and the kind no-branch-matched.
  • GitHub Action: it runs the same command.
  • Scenario: a schema assertion reports the same problem.

How clrsig helps you fix it

It tells you how many shapes were tried and why the first failed, and suggests sending the discriminator property or adding the new shape. It cannot guess which shape the server meant.

Limits

  • The message explains only the first shape. Read the schema for the others.
  • With an OpenAPI 3.0 spec, as here, only the first problem in a response body is reported. With 3.1, each problem has its own line.

More ways

Nothing yet.

3. Video