What is API contract testing?
An API contract is the agreed description of an interface — its endpoints, parameters, request and response schemas and status codes — usually written as an OpenAPI document. Contract testing compares what a service actually returns with that description, so a renamed field or a changed type is caught by the producer or the consumer before it breaks the other side.
Read the guide: What is API Testing? How to Test a REST API
How to use OpenAPI Formatter
- Paste an OpenAPI or Swagger document.
- Pick the output format, indentation and sorting mode.
- Copy or download the formatted document (openapi.yaml / openapi.json).
OpenAPI Formatter features
- JSON ↔ YAML conversion with 2- or 4-space indentation
- Structural sorting: paths, component names and tags alphabetically, HTTP methods and top-level keys in canonical order, responses by status code
- Optional full canonical form with every key sorted
- Summary with detected version, size before/after and validation status
- Line-accurate parse errors for malformed input
OpenAPI Formatter example
Minified JSON to sorted YAML
Input:
{"openapi":"3.0.3","paths":{"/b":{"get":{…}},"/a":{"post":{…},"get":{…}}},"info":{"title":"X","version":"1"}}Output:
openapi: 3.0.3
info:
title: X
version: "1"
paths:
/a:
get: …
post: …
/b:
get: …Frequently asked questions about OpenAPI Formatter
What does "Sort paths, methods & components" do?
Paths and component names are ordered alphabetically, HTTP methods in the canonical order (GET, PUT, POST, DELETE, OPTIONS, HEAD, PATCH, TRACE), response codes numerically with default last, and top-level keys in the conventional OpenAPI order. Content stays identical, so the output is a stable canonical form for diffs.
Is YAML → JSON conversion lossless?
For OpenAPI documents, yes: they use only the JSON-compatible subset of YAML. Dates and binary values are converted to strings, and anchors/aliases are expanded.
Why are some keys quoted in the YAML output?
Keys such as "200", "yes" or "on" would be interpreted as numbers or booleans by YAML parsers, so they are quoted to keep them strings — exactly what OpenAPI tooling expects for response codes.
Does the formatter also validate?
It runs the structural validator and reports the error count in the summary, but it formats the document even when errors are present so you can fix it in the pretty-printed output.
References
- OpenAPI SpecificationThe standard for describing REST APIs: paths, operations, parameters, schemas, responses and security schemes.
- JSON Schema SpecificationThe vocabulary for describing and validating the shape of JSON documents (types, required properties, formats).
- RFC 9110: HTTP SemanticsThe meaning of HTTP methods, header fields, status codes and content negotiation, independent of the wire version.