Registry / devops / openapi-minifier

openapi-minifier

JSON →
library1.0.2jsnpmunverified

A CLI tool by Treblle that minifies OpenAPI V3 specification files by up to 80% by removing redundant information irrelevant to AI agents and LLMs. Version 1.0.2 runs on Node >=18, ships TypeScript types, and supports JSON & YAML input/output with three presets (max, balanced, min). Key differentiator: reduces token usage for LLMs while preserving essential API details for integration.

npm install openapi-minifier
INSTALL
IMPORT
SIG · OPENAPI-MINIFIER
O
openapi-minifier
devopsjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import openapiMinifier from 'openapi-minifier'
const openapiMinifier = require('openapi-minifier')
CLI is the primary interface; the package exports default function for programmatic use.
MinifyResult
import { MinifyResult } from 'openapi-minifier'
import MinifyResult from 'openapi-minifier'
TypeScript type export for the result object.
Preset
import { Preset } from 'openapi-minifier'
TypeScript type for preset strings: 'max' | 'balanced' | 'min'.

Programmatic usage: read OpenAPI spec, minify with 'max' preset, write output.

import openapiMinifier from 'openapi-minifier'; import { readFileSync, writeFileSync } from 'fs'; const input = JSON.parse(readFileSync('spec.json', 'utf8')); const output = openapiMinifier(input, { preset: 'max' }); writeFileSync('spec-min.json', JSON.stringify(output, null, 2)); console.log('Minified successfully');
Debug
Known issues
breakingCLI requires Node >=18.0.0; older versions throw engine error.
fix
Upgrade Node to v18 or later.
affects: <18.0.0
gotchaUsing --preset max removes all descriptions and examples, which may break consumers relying on documentation.
fix
Use --preset balanced or --keep-descriptions all if documentation is needed.
affects: all
gotchaOutput is JSON by default; use --format yaml for YAML output but ensure input is valid YAML.
fix
Specify --format yaml if YAML output is desired.
affects: all
gotchaThe tool is built by Treblle and may send telemetry or analytics (no explicit opt-out documented). Review source if concerned about data leakage.
fix
Check source code or use --no-analytics if available (verify).
affects: all
Errors
Common errors & fixes
Error: Input is not a valid OpenAPI 3.x specification
The tool only supports OpenAPI 3.x specs; older Swagger 2.0 or invalid JSON/YAML causes this.
fix
Convert your spec to OpenAPI 3.x first (e.g., using api-spec-converter) and ensure valid syntax.
openapi-minifier: command not found
CLI not globally installed or not in PATH.
fix
Run via npx openapi-minifier or install globally: npm install -g openapi-minifier.
SyntaxError: Unexpected token < in JSON at position 0
Input file contains non-JSON content (e.g., HTML error page or YAML without --format yaml).
fix
Ensure input is valid JSON or use --format yaml for YAML files.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
openapi-minifier — npm install openapi-minifier · libregistry