Skip to content

Commit

Permalink
document operationIds.rename functionality in examples and README
Browse files Browse the repository at this point in the history
  • Loading branch information
tmack8001 committed Mar 1, 2019
1 parent 98e0862 commit b27862a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,35 @@ Tags can be renamed in the same manner as paths with simple, object like configu
}
```

### Renaming Path OperationIds

When merging different swagger definitions there are situations were the operationIds used in these separate swaggers could collide. If this is the case and changing source isn't desired or possible. OperationIds can be renamed by specifying the existing id to rename and the new id as key/value pairs in `operationIds.rename`.

This will replace each operationId matched by the provided key with the new value.

```json
{
"swagger": "2.0",
"info": {
"title": "Swagger Combine Simple OperationId Rename Example",
"version": "1.0.0"
},
"apis": [
{
"url": "http://petstore.swagger.io/v2/swagger.json",
"operationIds": {
"rename": {
"addPet": "createPet"
}
}
},
{
"url": "https://api.apis.guru/v2/specs/medium.com/1.0.0/swagger.yaml"
}
]
}
```

### Adding Tags

Tags can be added to all operations in a schema, using the `tags.add` field.
Expand Down
28 changes: 28 additions & 0 deletions examples/operationIds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const swaggerCombine = require('../src');

const config = (module.exports = {
swagger: '2.0',
info: {
title: 'Swagger Combine Rename OperationId Example',
version: {
$ref: './package.json#/version',
},
},
apis: [
{
url: 'http://petstore.swagger.io/v2/swagger.json',
paths: {
include: "/pet.post"
},
operationIds: {
rename: {
'addPet': 'createPet',
},
}
}
],
});

if (!module.parent) {
swaggerCombine(config).then(res => console.log(JSON.stringify(res, false, 2))).catch(err => console.error(err));
}

0 comments on commit b27862a

Please sign in to comment.