Back to TypeMorph
5 minutes·Updated

Detect API Schema Drift Without an OpenAPI Spec

typemorph check saves a schema baseline from a live API response and exits 1 when it detects breaking changes — removed fields, type changes — on the next run. No OpenAPI spec required.

The problem

Third-party APIs change without notice. Your code breaks in production because a field was renamed or a type changed. Tools like oasdiff require two OpenAPI spec files that you may not have, especially for external APIs.

The solution

typemorph check infers a schema from a real API response, saves it as a baseline JSON, then compares future responses against it. Breaking changes (field removed, type changed) exit 1 so your CI pipeline catches them before they reach production.

Step-by-step

  1. 1

    Save your first baseline

    On first run with no existing baseline file, typemorph check creates one and exits 0.

    Terminal

    mkdir -p .typemorph
    curl -s https://api.example.com/users/1 \
      | npx typemorph-cli check --baseline .typemorph/users.json
  2. 2

    Run again to detect drift

    Subsequent runs compare against the saved baseline. Breaking changes exit 1 with a summary.

    Terminal

    curl -s https://api.example.com/users/1 \
      | npx typemorph-cli check --baseline .typemorph/users.json
    
    # Output on breaking change:
    # ✖  2 breaking changes detected
    #   email  string → undefined  (field removed)
  3. 3

    Update the baseline when changes are intentional

    After confirming a change is expected, update the baseline so future runs are clean.

    Terminal

    curl -s https://api.example.com/users/1 \
      | npx typemorph-cli check --baseline .typemorph/users.json --update
  4. 4

    Commit the baseline to git

    The baseline file is plain JSON. Committing it lets the whole team and CI pipeline use the same reference.

    Terminal

    git add .typemorph/
    git commit -m "chore: add API schema baselines"

Try it in the browser first

The API Drift Check tool at typemorph.dev/tools/api-drift-check lets you paste a baseline and a current response to see the diff interactively — before adding it to CI.

Open TypeMorph Workbench

Frequently asked

How is this different from oasdiff?

oasdiff compares two OpenAPI spec files — you need a spec for both the old and new API. typemorph check works directly from live JSON responses with no spec file at all.

Does it produce false positives on enum fields?

Enum changes are downgraded to warnings (not errors) because a single-sample baseline can't prove the inferred enum is complete. Field removals and type changes remain errors.

Can I monitor multiple endpoints?

Yes — use a different --baseline path for each endpoint and run the check command once per endpoint in your CI step.

Does it work for internal APIs behind auth?

Yes. Pass --header "Authorization: Bearer $TOKEN" to include request headers when fetching from a URL, or pipe from curl with your auth headers.

Related guides