|
1 | 1 | import isObject from 'lodash/isObject' |
2 | 2 |
|
3 | 3 | const toLower = str => String.prototype.toLowerCase.call(str) |
4 | | -const escapeString = str => { |
| 4 | +const escapeString = (str) => { |
5 | 5 | return str.replace(/[^\w]/gi, '_') |
6 | 6 | } |
7 | 7 |
|
8 | 8 | // Strategy for determining operationId |
9 | 9 | export function opId(operation, pathName, method = '') { |
10 | 10 | const idWithoutWhitespace = (operation.operationId || '').replace(/\s/g, '') |
11 | | - if(idWithoutWhitespace.length) { |
| 11 | + if (idWithoutWhitespace.length) { |
12 | 12 | return escapeString(operation.operationId) |
13 | | - } else { |
14 | | - return idFromPathMethod(pathName, method) |
15 | 13 | } |
| 14 | + return idFromPathMethod(pathName, method) |
16 | 15 | } |
17 | 16 |
|
18 | 17 |
|
@@ -124,19 +123,18 @@ export function normalizeSwagger(parsedSpec) { |
124 | 123 | Object.keys(map).forEach((op) => { |
125 | 124 | if (map[op].length > 1) { |
126 | 125 | map[op].forEach((o, i) => { |
127 | | - o.__originalOperationId = o.__originalOperationId || o.operationId |
128 | | - o.operationId = `${op}${i+1}` |
| 126 | + o.__originalOperationId = o.__originalOperationId || o.operationId |
| 127 | + o.operationId = `${op}${i + 1}` |
129 | 128 | }) |
130 | | - } else { |
131 | | - // Ensure we always add the normalized operation ID if one already exists ( potentially different, given that we normalize our IDs) |
| 129 | + } |
| 130 | + else if (typeof operation.operationId !== 'undefined') { |
| 131 | + // Ensure we always add the normalized operation ID if one already exists |
| 132 | + // ( potentially different, given that we normalize our IDs) |
132 | 133 | // ... _back_ to the spec. Otherwise, they might not line up |
133 | | - if(typeof operation.operationId !== 'undefined') { |
134 | | - let obj = map[op][0] |
135 | | - obj.__originalOperationId = obj.__originalOperationId || operation.operationId |
136 | | - obj.operationId = op |
137 | | - } |
| 134 | + const obj = map[op][0] |
| 135 | + obj.__originalOperationId = obj.__originalOperationId || operation.operationId |
| 136 | + obj.operationId = op |
138 | 137 | } |
139 | | - |
140 | 138 | }) |
141 | 139 | } |
142 | 140 |
|
|
0 commit comments