Skip to content

Commit a54f883

Browse files
feat: Add OpenAPI Support to oauth-apps.update API (#36585)
Co-authored-by: Matheus Cardoso <matheus@cardo.so>
1 parent e81fedf commit a54f883

File tree

5 files changed

+69
-57
lines changed

5 files changed

+69
-57
lines changed

.changeset/clever-trees-occur.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
"@rocket.chat/rest-typings": patch
4+
---
5+
6+
Add OpenAPI support for the Rocket.Chat oauth-apps.update API endpoints by migrating to a modern chained route definition syntax and utilizing shared AJV schemas for validation to enhance API documentation and ensure type safety through response validation.

apps/meteor/app/api/server/v1/oauthapps.ts

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { IOAuthApps } from '@rocket.chat/core-typings';
22
import { OAuthApps } from '@rocket.chat/models';
33
import {
44
ajv,
5-
isUpdateOAuthAppParams,
65
isOauthAppsGetParams,
76
validateUnauthorizedErrorResponse,
87
validateBadRequestErrorResponse,
@@ -59,6 +58,37 @@ const OauthAppsAddParamsSchema = {
5958

6059
const isOauthAppsAddParams = ajv.compile<OauthAppsAddParams>(OauthAppsAddParamsSchema);
6160

61+
type UpdateOAuthAppParams = {
62+
appId: string;
63+
name: string;
64+
active: boolean;
65+
clientId?: string | undefined;
66+
clientSecret?: string | undefined;
67+
redirectUri: string;
68+
};
69+
70+
const UpdateOAuthAppParamsSchema = {
71+
type: 'object',
72+
properties: {
73+
appId: {
74+
type: 'string',
75+
},
76+
name: {
77+
type: 'string',
78+
},
79+
active: {
80+
type: 'boolean',
81+
},
82+
redirectUri: {
83+
type: 'string',
84+
},
85+
},
86+
required: ['appId', 'name', 'active', 'redirectUri'],
87+
additionalProperties: false,
88+
};
89+
90+
const isUpdateOAuthAppParams = ajv.compile<UpdateOAuthAppParams>(UpdateOAuthAppParamsSchema);
91+
6292
const oauthAppsEndpoints = API.v1
6393
.get(
6494
'oauth-apps.list',
@@ -156,6 +186,38 @@ const oauthAppsEndpoints = API.v1
156186

157187
return API.v1.success({ application });
158188
},
189+
)
190+
.post(
191+
'oauth-apps.update',
192+
{
193+
authRequired: true,
194+
body: isUpdateOAuthAppParams,
195+
permissionsRequired: ['manage-oauth-apps'],
196+
response: {
197+
400: validateBadRequestErrorResponse,
198+
401: validateUnauthorizedErrorResponse,
199+
403: validateForbiddenErrorResponse,
200+
200: ajv.compile<IOAuthApps | null>({
201+
allOf: [
202+
{ anyOf: [{ $ref: '#/components/schemas/IOAuthApps' }, { type: 'null' }] },
203+
{
204+
type: 'object',
205+
properties: {
206+
success: { type: 'boolean', enum: [true] },
207+
},
208+
required: ['success'],
209+
},
210+
],
211+
}),
212+
},
213+
},
214+
async function action() {
215+
const { appId } = this.bodyParams;
216+
217+
const result = await updateOAuthApp(this.userId, appId, this.bodyParams);
218+
219+
return API.v1.success(result);
220+
},
159221
);
160222

161223
API.v1.addRoute(
@@ -185,24 +247,6 @@ API.v1.addRoute(
185247
},
186248
);
187249

188-
API.v1.addRoute(
189-
'oauth-apps.update',
190-
{
191-
authRequired: true,
192-
validateParams: isUpdateOAuthAppParams,
193-
permissionsRequired: ['manage-oauth-apps'],
194-
},
195-
{
196-
async post() {
197-
const { appId } = this.bodyParams;
198-
199-
const result = await updateOAuthApp(this.userId, appId, this.bodyParams);
200-
201-
return API.v1.success(result);
202-
},
203-
},
204-
);
205-
206250
export type OauthAppsEndpoints = ExtractRoutesFromAPI<typeof oauthAppsEndpoints>;
207251

208252
declare module '@rocket.chat/rest-typings' {

packages/rest-typings/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ export * from './v1/integrations';
235235
export * from './v1/licenses';
236236
export * from './v1/omnichannel';
237237
export * from './v1/oauthapps';
238-
export * from './v1/oauthapps/UpdateOAuthAppParamsPOST';
239238
export * from './v1/oauthapps/OAuthAppsGetParamsGET';
240239
export * from './helpers/PaginatedRequest';
241240
export * from './helpers/PaginatedResult';
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import type { IOAuthApps } from '@rocket.chat/core-typings';
22

33
import type { OauthAppsGetParams } from './oauthapps/OAuthAppsGetParamsGET';
4-
import type { UpdateOAuthAppParams } from './oauthapps/UpdateOAuthAppParamsPOST';
54

65
export type OAuthAppsEndpoint = {
76
'/v1/oauth-apps.get': {
87
GET: (params: OauthAppsGetParams) => {
98
oauthApp: IOAuthApps;
109
};
1110
};
12-
13-
'/v1/oauth-apps.update': {
14-
POST: (params: UpdateOAuthAppParams) => IOAuthApps | null;
15-
};
1611
};

packages/rest-typings/src/v1/oauthapps/UpdateOAuthAppParamsPOST.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)