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:
parent
d8c9bb61d6
commit
a2723adad9
@ -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,
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user