(controllerName: string, method: Tsoa.Method, pathObject: any, defaultProduces?: string[])
| 256 | } |
| 257 | |
| 258 | protected buildMethod(controllerName: string, method: Tsoa.Method, pathObject: any, defaultProduces?: string[]) { |
| 259 | const pathMethod: Swagger.Operation3 = (pathObject[method.method] = this.buildOperation(controllerName, method, defaultProduces)); |
| 260 | pathMethod.description = method.description; |
| 261 | pathMethod.summary = method.summary; |
| 262 | pathMethod.tags = method.tags; |
| 263 | |
| 264 | // Use operationId tag otherwise fallback to generated. Warning: This doesn't check uniqueness. |
| 265 | pathMethod.operationId = method.operationId || pathMethod.operationId; |
| 266 | |
| 267 | if (method.deprecated) { |
| 268 | pathMethod.deprecated = method.deprecated; |
| 269 | } |
| 270 | |
| 271 | if (method.security) { |
| 272 | pathMethod.security = method.security; |
| 273 | } |
| 274 | |
| 275 | const bodyParams: Tsoa.Parameter[] = method.parameters.filter(p => p.in === 'body'); |
| 276 | const bodyPropParams: Tsoa.Parameter[] = method.parameters.filter(p => p.in === 'body-prop'); |
| 277 | const formParams: Tsoa.Parameter[] = method.parameters.filter(p => p.in === 'formData'); |
| 278 | const queriesParams: Tsoa.Parameter[] = method.parameters.filter(p => p.in === 'queries'); |
| 279 | |
| 280 | pathMethod.parameters = method.parameters |
| 281 | .filter(p => { |
| 282 | return ['body', 'formData', 'request', 'body-prop', 'res', 'queries', 'request-prop'].indexOf(p.in) === -1; |
| 283 | }) |
| 284 | .map(p => this.buildParameter(p)); |
| 285 | |
| 286 | if (queriesParams.length > 1) { |
| 287 | throw new Error('Only one queries parameter allowed per controller method.'); |
| 288 | } |
| 289 | |
| 290 | if (queriesParams.length === 1) { |
| 291 | pathMethod.parameters.push(...this.buildQueriesParameter(queriesParams[0])); |
| 292 | } |
| 293 | |
| 294 | if (bodyParams.length > 1) { |
| 295 | throw new Error('Only one body parameter allowed per controller method.'); |
| 296 | } |
| 297 | |
| 298 | if (bodyParams.length > 0 && formParams.length > 0) { |
| 299 | throw new Error('Either body parameter or form parameters allowed per controller method - not both.'); |
| 300 | } |
| 301 | |
| 302 | if (bodyPropParams.length > 0) { |
| 303 | if (!bodyParams.length) { |
| 304 | bodyParams.push({ |
| 305 | in: 'body', |
| 306 | name: 'body', |
| 307 | parameterName: 'body', |
| 308 | required: true, |
| 309 | type: { |
| 310 | dataType: 'nestedObjectLiteral', |
| 311 | properties: [], |
| 312 | } as Tsoa.NestedObjectLiteralType, |
| 313 | validators: {}, |
| 314 | deprecated: false, |
| 315 | }); |
no test coverage detected