Filtering
Strip matching items from your OpenAPI document based on methods, tags, flags, and more.
Try filtering in the PlaygroundCLI Usage
npx openapi-format openapi.json -o output.json --filterFile customFilter.yamlflags:
- x-visibility
flagValues: []
tags: []
operationIds:
- addPet
- findPetsByStatusFilter Options Reference
| Type | Description | Example |
|---|---|---|
| methods | Remove matching HTTP methods | ['get','post'] |
| inverseMethods | Keep only these methods | ['get','post'] |
| tags | Remove matching tags | ['pet','user'] |
| inverseTags | Keep only these tags | ['pet','user'] |
| operationIds | Remove matching operation IDs | ['findPets','updatePet'] |
| inverseOperationIds | Keep only these operation IDs | ['findPets'] |
| operations | Remove matching method::path combos | ['GET::/pets','PUT::/pets'] |
| flags | Remove items with these custom flags | ['x-exclude','x-internal'] |
| inverseFlags | Keep only items with these flags | ['x-public'] |
| flagValues | Remove items matching flag + value | ['x-version: 1.0'] |
| inverseFlagValues | Keep only matching flag + value | ['x-version: 2.0'] |
| responseContent | Remove response content types | ['application/xml'] |
| inverseResponseContent | Keep only these response types | ['application/json'] |
| requestContent | Remove request body content types | ['application/xml'] |
| inverseRequestContent | Keep only these request types | ['application/json'] |
| unusedComponents | Remove unreferenced components | ['schemas','examples'] |
| stripFlags | Strip flag properties (keep parent) | ['x-internal'] |
| preserveEmptyObjects | Keep empty objects | true or ['schema'] |
| textReplace | Search & replace text values | [{searchFor, replaceWith}] |
Filter by Methods
Remove all operations matching specified HTTP methods. Use inverseMethods to
keep only specified methods.
methods:
- get
- putopenapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
get:
summary: Finds Pets by status
put:
summary: Update an existing pet
post:
summary: Add a new petopenapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
post:
summary: Add a new petFilter by Tags
Remove all operations tagged with specified values:
tags:
- petopenapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
get:
tags:
- pet
summary: List all pets
post:
tags:
- pet
summary: Add a new pet
/users:
get:
tags:
- user
summary: List all usersopenapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/users:
get:
tags:
- user
summary: List all usersFilter by operationIds
Remove specific operations by their operationId:
operationIds:
- findPetsByStatusopenapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
get:
operationId: findPetsByStatus
summary: Finds Pets by status
post:
operationId: addPet
summary: Add a new petopenapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
post:
operationId: addPet
summary: Add a new petFilter by Operations
Target specific method + path combinations using the METHOD::path format.
Supports wildcards:
operations:
# Exact match
- "GET::/pets"
# All methods on a path
- "*::/pets"
# All sub-paths
- "GET::/pets/*"
# Full wildcard
- "*::/pets/*"openapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
get:
summary: Finds Pets by status
put:
summary: Update an existing pet
/users:
get:
summary: List all usersopenapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
get:
summary: Finds Pets by status
/users:
get:
summary: List all usersFilter by Flags
Remove items that have a specific custom property (e.g. x-internal):
flags:
- x-internalopenapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
get:
summary: List all pets
/internal/metrics:
get:
x-internal: true
summary: Get metrics
/internal/health:
get:
x-internal: true
summary: Health checkopenapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
get:
summary: List all petsFilter by Flag Values
Match flag + value combinations, including array values:
flagValues:
- x-version: 1.0
- x-version: 3.0openapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
get:
x-version: 1.0
summary: List pets (v1)
post:
x-version: 2.0
summary: Add pet (v2)
/users:
get:
x-version: 3.0
summary: List users (v3)openapi: 3.0.0
info:
title: API
version: 1.0.0
paths:
/pets:
post:
x-version: 2.0
summary: Add pet (v2)Filter Response Content
Remove specific content types from responses:
responseContent:
- application/xmlpaths:
/pet:
post:
summary: Add a new pet
responses:
'200':
description: Successful
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'paths:
/pet:
post:
summary: Add a new pet
responses:
'200':
description: Successful
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'Remove Unused Components
Strip unreferenced items from the components section. Recursively removes nested unused components (up to 10 levels).
unusedComponents:
- schemas
- parameters
- examplespaths:
/pets:
get:
summary: List all pets
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
type: object
Error:
type: object
Category:
type: objectpaths:
/pets:
get:
summary: List all pets
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
type: objectStrip Flags
Remove only the flag properties while keeping the parent operation intact:
stripFlags:
- x-internal
- x-betapaths:
/pets:
get:
x-internal: true
x-beta: true
summary: Finds Pets
operationId: findPetspaths:
/pets:
get:
summary: Finds Pets
operationId: findPetsText Replace
Search and replace text across descriptions, summaries, and URLs:
textReplace:
- searchFor: 'Pets'
replaceWith: 'Dogs'
- searchFor: 'swagger.io'
replaceWith: 'openapis.org'openapi: 3.0.0
info:
title: Pets API
description: Manage your Pets
paths:
/pets:
get:
summary: Find Pets by status
description: Returns Pets from swagger.ioopenapi: 3.0.0
info:
title: Dogs API
description: Manage your Dogs
paths:
/pets:
get:
summary: Find Dogs by status
description: Returns Dogs from openapis.org