Format, Sort & Filter your OpenAPI definitions

A CLI and library to sort, filter, and format OpenAPI specs — making them consistent, clean, and diff-friendly.

$ npx openapi-format openapi.yaml

Trusted by the OpenAPI community

150+ GitHub Stars
320K+ Monthly Downloads
87 Versions Released

More OpenAPI tools from the community can be found on openapi.tools .

Use Cases

Public Docs

Strip internal endpoints and sort your spec before publishing external documentation.

Maintenance

Keep large OpenAPI files readable and diff-friendly for easier code reviews.

CI/CD

Automate formatting and filtering in your pipeline to enforce spec standards.

Before & After

Before

openapi: 3.0.3
info:
  title: Pet Store API
  version: 1.0.0
paths:
  /pets/{petId}:
    get:
      summary: Get pet by ID
  /pets:
    post:
      summary: Create a pet
    get:
      summary: List all pets
components:
  schemas:
    Pet:
      type: object
    Error:
      type: object

After

openapi: 3.0.3
info:
  title: Pet Store API
  version: 1.0.0
paths:
  /pets:
    get:
      summary: List all pets
    post:
      summary: Create a pet
  /pets/{petId}:
    get:
      summary: Get pet by ID
components:
  schemas:
    Error:
      type: object
    Pet:
      type: object

Quick Start

Format a spec

npx openapi-format openapi.yaml -o formatted.yaml

Sort & filter

npx openapi-format openapi.yaml --sortFile sort.json --filterFile filter.json

Convert to JSON

npx openapi-format openapi.yaml -o openapi.json

Install

npm install --save openapi-format

Explore the Docs

Everything you need to get started — from installation to advanced programmatic usage.