diff --git a/src/lib/routes/admin-api/addon.ts b/src/lib/routes/admin-api/addon.ts index da29cbd4ca..81de9cfe94 100644 --- a/src/lib/routes/admin-api/addon.ts +++ b/src/lib/routes/admin-api/addon.ts @@ -36,7 +36,7 @@ class AddonController extends Controller { super(config, { openApiService }); this.logger = config.getLogger('/admin-api/addon.ts'); this.addonService = addonService; - this.routeWithOpenApi(this.openApiService)({ + this.routeWithOpenApi({ method: 'get', path: '', permission: NONE, @@ -53,7 +53,7 @@ class AddonController extends Controller { }, }); - this.routeWithOpenApi(this.openApiService)({ + this.routeWithOpenApi({ method: 'post', path: '', handler: this.createAddon, @@ -71,7 +71,7 @@ class AddonController extends Controller { }, }); - this.routeWithOpenApi(this.openApiService)({ + this.routeWithOpenApi({ method: 'get', path: `${PATH}:id`, handler: this.getAddon, @@ -88,7 +88,7 @@ class AddonController extends Controller { }, }); - this.routeWithOpenApi(this.openApiService)({ + this.routeWithOpenApi({ method: 'put', path: `${PATH}:id`, handler: this.updateAddon, @@ -107,7 +107,7 @@ Note: passing \`null\` as a value for the description property will set it to an }, }); - this.routeWithOpenApi(this.openApiService)({ + this.routeWithOpenApi({ method: 'delete', path: `${PATH}:id`, handler: this.deleteAddon, diff --git a/src/lib/routes/controller.ts b/src/lib/routes/controller.ts index f9418b90db..252d77fa77 100644 --- a/src/lib/routes/controller.ts +++ b/src/lib/routes/controller.ts @@ -119,46 +119,44 @@ export default class Controller { ); } - routeWithOpenApi(openApiService: OpenApiService) { - return ({ - openApi, - ...options - }: IRouteOptions & { openApi: ApiOperation }): void => { - const errorCodes = new Set([401]); + routeWithOpenApi({ + openApi, + ...options + }: IRouteOptions & { openApi: ApiOperation }): void { + const errorCodes = new Set([401]); - if ( - ['put', 'post', 'patch'].includes( - options?.method?.toLowerCase() || '', - ) - ) { - errorCodes.add(400); - errorCodes.add(413); - errorCodes.add(415); - } + if ( + ['put', 'post', 'patch'].includes( + options?.method?.toLowerCase() || '', + ) + ) { + errorCodes.add(400); + errorCodes.add(413); + errorCodes.add(415); + } - if (options.path.includes(':')) { - errorCodes.add(404); - } + if (options.path.includes(':')) { + errorCodes.add(404); + } - if (options.permission !== NONE) { - errorCodes.add(403); - } + if (options.permission !== NONE) { + errorCodes.add(403); + } - const openApiWithErrorCodes = { - ...openApi, - responses: { - ...getStandardResponses(...errorCodes), - ...openApi.responses, - }, - }; - return this.route({ - ...options, - middleware: [ - ...(options.middleware ?? []), - openApiService.validPath(openApiWithErrorCodes), - ], - }); + const openApiWithErrorCodes = { + ...openApi, + responses: { + ...getStandardResponses(...errorCodes), + ...openApi.responses, + }, }; + return this.route({ + ...options, + middleware: [ + ...(options.middleware ?? []), + this.openApiService.validPath(openApiWithErrorCodes), + ], + }); } get(