prettier-plugin-openapi weekly downloads statistics
By LukasParke · npm · Prettier plugins
A Prettier plugin for formatting OpenAPI/Swagger JSON and YAML files
prettier-plugin-openapi has 47 recorded weekly downloads on npm, an increase of 30.6% over the past 30 days, ranking #2782 of 3,247 tracked listings.
About prettier-plugin-openapi
Prettier Plugin OpenAPI
A Prettier plugin for formatting OpenAPI/Swagger JSON and YAML files with intelligent key sorting, proper indentation, and support for modular OpenAPI file structures.
Features
- 🎯 OpenAPI/Swagger Support: Formats both JSON and YAML OpenAPI specifications
- 🔄 Smart Key Sorting: Automatically sorts OpenAPI keys in the recommended order
- 📁 Modular File Support: Handles both monolithic and modular OpenAPI file structures
- 🧩 Component Files: Supports individual component files (schemas, parameters, responses, etc.)
- 📝 YAML & JSON: Supports both
.yaml/.ymland.jsonfile formats - 🎨 Consistent Formatting: Applies consistent indentation and line breaks
- 🔌 Vendor Extensions: Programmatic loading of vendor-specific extensions
- ⚡ Fast: Built with performance in mind using modern JavaScript
- 🧪 Comprehensive Testing: 142 tests with 95.69% line coverage
- 🚀 CI/CD Ready: Automated testing, building, and publishing
- 🔒 Strict Validation: Properly rejects non-OpenAPI content
- 📊 High Quality: Biome, Prettier, and TypeScript for code quality
Current Status
✅ Production Ready: Version 1.0.1 with comprehensive test coverage
✅ Modern Tooling: Updated to use Biome for fast linting and formatting
✅ Comprehensive Testing: 142 tests covering all major functionality
✅ High Performance: Optimized for large OpenAPI files
✅ Active Development: Regular updates and improvements
Installation
This plugin has a prettier peer dependency and works with Prettier 3 on Node 18+.
npm install --save-dev prettier prettier-plugin-openapi
# or
pnpm add --save-dev prettier prettier-plugin-openapi
# or
yarn add --dev prettier prettier-plugin-openapi
# or
bun add --dev prettier prettier-plugin-openapi
Usage
Command Line
# Format a single file
pnpx prettier --write api.yaml
# Format all OpenAPI files in a directory
pnpx prettier --write "**/*.{openapi.json,openapi.yaml,swagger.json,swagger.yaml}"
# Format with specific options
pnpx prettier --write api.yaml --tab-width 4 --print-width 100
Configuration
Add the plugin to your Prettier configuration:
package.json
{
"prettier": {
"plugins": ["prettier-plugin-openapi"]
}
}
.prettierrc
{
"plugins": ["prettier-plugin-openapi"],
"tabWidth": 2,
"printWidth": 80
}
.prettierrc.js
module.exports = {
plugins: ['prettier-plugin-openapi'],
tabWidth: 2,
printWidth: 80,
};
Repo Setup
For a typical repository, add a couple of scripts so local development and CI use the same commands:
package.json
{
"scripts": {
"format": "prettier --write \"openapi/**/*.{yaml,yml,json}\"",
"format:check": "prettier --check \"openapi/**/*.{yaml,yml,json}\""
}
}
.prettierrc.json
{
"plugins": ["prettier-plugin-openapi"]
}
Then you can run:
npm run format
npm run format:check
Adjust the openapi/**/*.{yaml,yml,json} glob to match wherever your specs live.
GitHub Actions
If you want formatting to run whenever main is updated and automatically push formatting fixes back to pull requests, you can use autofix.ci.
- Install the autofix.ci GitHub App for your repository.
- Add a workflow like this:
.github/workflows/format-openapi.yml
name: Format OpenAPI
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 20
- run: npm ci
- run: npm run format
- uses: autofix-ci/action@7a166d7532b277f34e16238930461bf77f9d7ed8
This runs the same Prettier command on pushes to main and on pull requests, while autofix.ci writes any formatting changes back to the PR branch for you.
If you only want CI to verify formatting instead of auto-fixing it, replace npm run format with npm run format:check and remove the autofix-ci step.
Supported File Extensions
.openapi.json.openapi.yaml.openapi.yml.swagger.json.swagger.yaml.swagger.yml.json(for component files).yaml/.yml(for component files)
Modular File Structure Support
The plugin supports both monolithic and modular OpenAPI file structures:
Monolithic Structure
api.yaml # Single file with everything
Modular Structure
├─ openapi.yaml # Root document
├─ paths/ # Path files
│ ├─ users.yaml
│ ├─ users_{id}.yaml
│ └─ auth_login.yaml
├─ components/ # Component files
│ ├─ schemas/
│ │ ├─ User.yaml
│ │ ├─ UserCreate.yaml
│ │ └─ Error.yaml
│ ├─ parameters/
│ │ ├─ CommonPagination.yaml
│ │ └─ UserId.yaml
│ ├─ responses/
│ │ ├─ ErrorResponse.yaml
│ │ └─ UserResponse.yaml
│ ├─ requestBodies/
│ │ └─ UserCreateBody.yaml
│ ├─ headers/
│ │ └─ RateLimitHeaders.yaml
│ ├─ examples/
│ │ └─ UserExample.yaml
│ ├─ securitySchemes/
│ │ └─ BearerAuth.yaml
│ ├─ links/
│ │ └─ UserCreatedLink.yaml
│ └─ callbacks/
│ └─ NewMessageCallback.yaml
└─ webhooks/ # Webhook files
└─ messageCreated.yaml
Key Sorting
The plugin automatically sorts OpenAPI keys in the recommended order:
📖 Complete Key Reference: For a comprehensive reference of all keys, their ordering, and detailed reasoning, see KEYS.md.
Examples
Monolithic File Structure
Before (unformatted):
paths:
/users:
get:
responses:
'200':
description: OK
components:
schemas:
User:
type: object
openapi: 3.0.0
info:
version: 1.0.0
title: My API
```…
Description from the npm listing.
- prettier
- prettier-plugin
- openapi
- swagger
- yaml
- json
- formatting
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (170)Similar npm Prettier plugins plugins
All 20 prettier-plugin-openapi alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/prettier-plugin-openapi. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.