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 });
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,

View File

@ -119,46 +119,44 @@ export default class Controller {
);
}
routeWithOpenApi(openApiService: OpenApiService) {
return ({
openApi,
...options
}: IRouteOptions & { openApi: ApiOperation }): void => {
const errorCodes = new Set<StandardResponseCodes>([401]);
routeWithOpenApi({
openApi,
...options
}: IRouteOptions & { openApi: ApiOperation }): void {
const errorCodes = new Set<StandardResponseCodes>([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(