Skip to content

Normalizer

The normalizer takes a Postman-exported OpenAPI document and cleans it up into a lean, standard-compliant spec.

Usage

ts
import { normalize } from 'openapi-normalizer';

const result = normalize(openapiDocument);

Options

Pass a NormalizeOptions object as the second argument to customise behaviour:

ts
import { normalize } from 'openapi-normalizer';

const result = normalize(doc, {
  preserveHeaders: ['X-Request-Id', 'X-Correlation-Id'],
  additionalNoisyHeaders: ['X-Internal-Trace'],
  stripXExtensions: true,
  keepExamples: true,
  inferSchemas: false, // default: true
});
OptionTypeDefaultDescription
preserveHeadersstring[][]Header names to keep (bypass noisy-header stripping)
additionalNoisyHeadersstring[][]Extra header names to treat as noisy and remove
stripXExtensionsbooleanfalseRemove all x-* vendor extension keys
keepExamplesbooleanfalsePreserve named examples instead of collapsing
inferSchemasbooleantrueInfer schemas from example values when schema is empty

What it does

TransformBeforeAfter
Noisy response headersX-Request-Id, Content-Length, Set-Cookie, …Removed
Named examplesexamples: { ex1: {...}, ex2: {...} }Single example with first value
Missing schemasOnly examples existSchema inferred from example values
Per-property examples{ type: "string", example: "John" }{ type: "string" }
Duplicate descriptionsummary and description identicaldescription removed
Empty securitysecurity: [{}]Removed
Postman serversurl: ""url: "/" with descriptive annotation
Duplicate tagsSame tag name repeatedDeduplicated
Empty componentssecuritySchemes: {}Removed

File size reduction

On a typical Postman export, expect 60–70% reduction in file size. The largest contributors to bloat are:

  1. Per-property example values (thousands of instances)
  2. Noisy HTTP transport headers on every response
  3. Redundant named examples objects

Example

Input (simplified):

json
{
  "paths": {
    "/users": {
      "get": {
        "summary": "Get users",
        "description": "Get users",
        "security": [{}],
        "responses": {
          "200": {
            "description": "OK",
            "headers": {
              "X-Request-Id": { "schema": { "type": "string" } },
              "Content-Length": { "schema": { "type": "string" } }
            },
            "content": {
              "application/json": {
                "schema": {},
                "examples": {
                  "ex1": { "value": { "id": 1, "name": "John" } },
                  "ex2": { "value": { "id": 2, "name": "Jane" } }
                }
              }
            }
          }
        }
      }
    }
  }
}

Output:

json
{
  "paths": {
    "/users": {
      "get": {
        "summary": "Get users",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "integer" },
                    "name": { "type": "string" }
                  }
                },
                "example": { "id": 1, "name": "John" }
              }
            }
          }
        }
      }
    }
  }
}

Released under the MIT License.