1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-19 17:52:45 +02:00

openapi: remove redundant openapiservice param from route

This commit is contained in:
Thomas Heartman 2023-08-17 10:03:42 +02:00
parent d8c9bb61d6
commit a2723adad9
No known key found for this signature in database
GPG Key ID: BD1F880DAED1EE78
2 changed files with 38 additions and 40 deletions

View File

@ -36,7 +36,7 @@ class AddonController extends Controller {
super(config, { openApiService }); super(config, { openApiService });
this.logger = config.getLogger('/admin-api/addon.ts'); this.logger = config.getLogger('/admin-api/addon.ts');
this.addonService = addonService; this.addonService = addonService;
this.routeWithOpenApi(this.openApiService)({ this.routeWithOpenApi({
method: 'get', method: 'get',
path: '', path: '',
permission: NONE, permission: NONE,
@ -53,7 +53,7 @@ class AddonController extends Controller {
}, },
}); });
this.routeWithOpenApi(this.openApiService)({ this.routeWithOpenApi({
method: 'post', method: 'post',
path: '', path: '',
handler: this.createAddon, handler: this.createAddon,
@ -71,7 +71,7 @@ class AddonController extends Controller {
}, },
}); });
this.routeWithOpenApi(this.openApiService)({ this.routeWithOpenApi({
method: 'get', method: 'get',
path: `${PATH}:id`, path: `${PATH}:id`,
handler: this.getAddon, handler: this.getAddon,
@ -88,7 +88,7 @@ class AddonController extends Controller {
}, },
}); });
this.routeWithOpenApi(this.openApiService)({ this.routeWithOpenApi({
method: 'put', method: 'put',
path: `${PATH}:id`, path: `${PATH}:id`,
handler: this.updateAddon, 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', method: 'delete',
path: `${PATH}:id`, path: `${PATH}:id`,
handler: this.deleteAddon, handler: this.deleteAddon,

View File

@ -119,46 +119,44 @@ export default class Controller {
); );
} }
routeWithOpenApi(openApiService: OpenApiService) { routeWithOpenApi({
return ({ openApi,
openApi, ...options
...options }: IRouteOptions & { openApi: ApiOperation }): void {
}: IRouteOptions & { openApi: ApiOperation }): void => { const errorCodes = new Set<StandardResponseCodes>([401]);
const errorCodes = new Set<StandardResponseCodes>([401]);
if ( if (
['put', 'post', 'patch'].includes( ['put', 'post', 'patch'].includes(
options?.method?.toLowerCase() || '', options?.method?.toLowerCase() || '',
) )
) { ) {
errorCodes.add(400); errorCodes.add(400);
errorCodes.add(413); errorCodes.add(413);
errorCodes.add(415); errorCodes.add(415);
} }
if (options.path.includes(':')) { if (options.path.includes(':')) {
errorCodes.add(404); errorCodes.add(404);
} }
if (options.permission !== NONE) { if (options.permission !== NONE) {
errorCodes.add(403); errorCodes.add(403);
} }
const openApiWithErrorCodes = { const openApiWithErrorCodes = {
...openApi, ...openApi,
responses: { responses: {
...getStandardResponses(...errorCodes), ...getStandardResponses(...errorCodes),
...openApi.responses, ...openApi.responses,
}, },
};
return this.route({
...options,
middleware: [
...(options.middleware ?? []),
openApiService.validPath(openApiWithErrorCodes),
],
});
}; };
return this.route({
...options,
middleware: [
...(options.middleware ?? []),
this.openApiService.validPath(openApiWithErrorCodes),
],
});
} }
get( get(