(verb: string, path: string, spec: OperationObject)
| 489 | } |
| 490 | |
| 491 | private _setupOperation(verb: string, path: string, spec: OperationObject) { |
| 492 | const handler = spec['x-operation']; |
| 493 | if (typeof handler === 'function') { |
| 494 | // Remove a field value that cannot be represented in JSON. |
| 495 | // Start by creating a shallow-copy of the spec, so that we don't |
| 496 | // modify the original spec object provided by user. |
| 497 | spec = Object.assign({}, spec); |
| 498 | delete spec['x-operation']; |
| 499 | |
| 500 | const route = new Route(verb, path, spec, handler); |
| 501 | this._httpHandler.registerRoute(route); |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | const controllerName = spec['x-controller-name']; |
| 506 | if (typeof controllerName === 'string') { |
| 507 | const b = this.getBinding(`controllers.${controllerName}`, { |
| 508 | optional: true, |
| 509 | }); |
| 510 | if (!b) { |
| 511 | throw new Error( |
| 512 | `Unknown controller ${controllerName} used by "${verb} ${path}"`, |
| 513 | ); |
| 514 | } |
| 515 | |
| 516 | const ctor = b.valueConstructor; |
| 517 | if (!ctor) { |
| 518 | throw new Error( |
| 519 | `The controller ${controllerName} was not bound via .toClass()`, |
| 520 | ); |
| 521 | } |
| 522 | |
| 523 | const controllerFactory = createControllerFactoryForBinding<object>( |
| 524 | b.key, |
| 525 | ); |
| 526 | const route = new ControllerRoute( |
| 527 | verb, |
| 528 | path, |
| 529 | spec, |
| 530 | ctor as ControllerClass<object>, |
| 531 | controllerFactory, |
| 532 | ); |
| 533 | this._httpHandler.registerRoute(route); |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | throw new Error( |
| 538 | `There is no handler configured for operation "${verb} ${path}`, |
| 539 | ); |
| 540 | } |
| 541 | |
| 542 | private async _serveOpenApiSpec( |
| 543 | request: Request, |
no test coverage detected