| Conditions | 1 |
| Paths | 256 |
| Total Lines | 91 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 46 | _.forEach(swagger.paths, function (api, path) { |
||
| 47 | let globalParams = [] |
||
| 48 | /** |
||
| 49 | * @param {Object} op - meta data for the request |
||
| 50 | * @param {string} m - HTTP method name - eg: 'get', 'post', 'put', 'delete' |
||
| 51 | */ |
||
| 52 | _.forEach(api, function (op, m) { |
||
| 53 | if (m.toLowerCase() === 'parameters') { |
||
| 54 | globalParams = op |
||
| 55 | } |
||
| 56 | }) |
||
| 57 | _.forEach(api, function (op, m) { |
||
| 58 | if (authorizedMethods.indexOf(m.toUpperCase()) === -1) { |
||
| 59 | return |
||
| 60 | } |
||
| 61 | let method = { |
||
| 62 | path: path, |
||
| 63 | className: opts.className, |
||
| 64 | methodName: op.operationId ? normalizeName(op.operationId) : getPathToMethodName(opts, m, path), |
||
| 65 | method: m.toUpperCase(), |
||
| 66 | isGET: m.toUpperCase() === 'GET', |
||
| 67 | isPOST: m.toUpperCase() === 'POST', |
||
| 68 | summary: op.description || op.summary, |
||
| 69 | tags: op.tags, |
||
| 70 | externalDocs: op.externalDocs, |
||
| 71 | isSecure: swagger.security !== undefined || op.security !== undefined, |
||
| 72 | parameters: [], |
||
| 73 | headers: [] |
||
| 74 | } |
||
| 75 | |||
| 76 | if (op.produces) { |
||
| 77 | let headers = [] |
||
| 78 | headers.value = [] |
||
| 79 | |||
| 80 | headers.name = 'Accept' |
||
| 81 | headers.value.push(op.produces.map(function (value) { return '\'' + value + '\'' }).join(', ')) |
||
| 82 | |||
| 83 | method.headers.push(headers) |
||
| 84 | } |
||
| 85 | |||
| 86 | let consumes = op.consumes || swagger.consumes |
||
| 87 | if (consumes) { |
||
| 88 | method.headers.push({ name: 'Content-Type', value: '\'' + consumes + '\'' }) |
||
| 89 | } |
||
| 90 | |||
| 91 | let params = [] |
||
| 92 | if (_.isArray(op.parameters)) { |
||
| 93 | params = op.parameters |
||
| 94 | } |
||
| 95 | params = params.concat(globalParams) |
||
| 96 | _.forEach(params, function (parameter) { |
||
| 97 | // Ignore parameters which contain the x-exclude-from-bindings extension |
||
| 98 | if (parameter['x-exclude-from-bindings'] === true) { |
||
| 99 | return |
||
| 100 | } |
||
| 101 | |||
| 102 | // Ignore headers which are injected by proxies & app servers |
||
| 103 | // eg: https://cloud.google.com/appengine/docs/go/requests#Go_Request_headers |
||
| 104 | if (parameter['x-proxy-header'] && !data.isNode) { |
||
| 105 | return |
||
| 106 | } |
||
| 107 | if (_.isString(parameter.$ref)) { |
||
| 108 | let segments = parameter.$ref.split('/') |
||
| 109 | parameter = swagger.parameters[segments.length === 1 ? segments[0] : segments[2]] |
||
| 110 | } |
||
| 111 | parameter.camelCaseName = _.camelCase(parameter.name) |
||
| 112 | if (parameter.enum && parameter.enum.length === 1) { |
||
| 113 | parameter.isSingleton = true |
||
| 114 | parameter.singleton = parameter.enum[0] |
||
| 115 | } |
||
| 116 | if (parameter.in === 'body') { |
||
| 117 | parameter.isBodyParameter = true |
||
| 118 | } else if (parameter.in === 'path') { |
||
| 119 | parameter.isPathParameter = true |
||
| 120 | } else if (parameter.in === 'query') { |
||
| 121 | if (parameter['x-name-pattern']) { |
||
| 122 | parameter.isPatternType = true |
||
| 123 | parameter.pattern = parameter['x-name-pattern'] |
||
| 124 | } |
||
| 125 | parameter.isQueryParameter = true |
||
| 126 | } else if (parameter.in === 'header') { |
||
| 127 | parameter.isHeaderParameter = true |
||
| 128 | } else if (parameter.in === 'formData') { |
||
| 129 | parameter.isFormParameter = true |
||
| 130 | } |
||
| 131 | parameter.cardinality = parameter.required ? '' : '?' |
||
| 132 | method.parameters.push(parameter) |
||
| 133 | }) |
||
| 134 | data.methods.push(method) |
||
| 135 | }) |
||
| 136 | }) |
||
| 137 | |||
| 215 |