Generate
Automatically generate OpenAPI elements like operationId using
customizable templates.
CLI Usage
Terminal
npx openapi-format openapi.json -o output.json --generateFile customGenerate.yamlConfiguration
customGenerate.yaml
operationIdTemplate: "<method>_<pathPart2>"
overwriteExisting: false| Option | Description |
|---|---|
| operationIdTemplate | Template with dynamic placeholders for generating operationId |
| overwriteExisting | Whether to overwrite existing values (default: false) |
Template Placeholders
| Placeholder | Description | Example |
|---|---|---|
| <operationId> | Existing operationId | leadsAll |
| <method> | HTTP method | GET |
| <path> | Full path | /crm/leads |
| <pathRef> | Method::path combination | GET::/crm/leads |
| <tag> | First tag name | Leads |
| <tag1> | First tag | Leads |
| <tag2> | Second tag | CRM |
| <pathPart1> | First path segment | crm |
| <pathPart2> | Second path segment | leads |
| <pathPartN> | Nth path segment | ... |
Example: Generate Missing operationIds
customGenerate.yaml
operationIdTemplate: "<method>_<pathPart1>_<pathPart2>"
overwriteExisting: falseBefore — missing operationIds
openapi: 3.0.3
paths:
/crm/leads:
get:
summary: List all leads
post:
summary: Create a lead
/crm/leads/{leadId}:
get:
summary: Get a lead
put:
operationId: updateLead
summary: Update a leadAfter — generated (existing kept)
openapi: 3.0.3
paths:
/crm/leads:
get:
operationId: GET_crm_leads
summary: List all leads
post:
operationId: POST_crm_leads
summary: Create a lead
/crm/leads/{leadId}:
get:
operationId: GET_crm_leads
summary: Get a lead
put:
operationId: updateLead
summary: Update a leadExample: Overwrite All operationIds
customGenerate.yaml
operationIdTemplate: "<method>-<pathPart1>-<pathPart2>"
overwriteExisting: trueBefore
openapi: 3.0.3
paths:
/store/orders:
get:
operationId: listOrders
summary: List orders
post:
operationId: createOrder
summary: Create an order
/store/inventory:
get:
operationId: getInventory
summary: Get inventoryAfter — all overwritten
openapi: 3.0.3
paths:
/store/orders:
get:
operationId: GET-store-orders
summary: List orders
post:
operationId: POST-store-orders
summary: Create an order
/store/inventory:
get:
operationId: GET-store-inventory
summary: Get inventoryAdvanced Template with Static Text
customGenerate.yaml
operationIdTemplate: "Api_<method>_<pathPart2>_Handler"
For GET /crm/leads,
this generates: Api_GET_leads_Handler
For POST /store/orders,
this generates: Api_POST_orders_Handler