Skip to content

Commit 5d7dec3

Browse files
feat: Add OpenAPI Support to oauth-apps.list API (#36586)
1 parent 1a23b72 commit 5d7dec3

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

.changeset/strange-worms-smoke.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.list 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: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,49 @@ import { updateOAuthApp } from '../../../oauth2-server-config/server/admin/metho
1818
import type { ExtractRoutesFromAPI } from '../ApiClass';
1919
import { API } from '../api';
2020

21-
API.v1.addRoute(
21+
const oauthAppsListEndpoints = API.v1.get(
2222
'oauth-apps.list',
23-
{ authRequired: true, permissionsRequired: ['manage-oauth-apps'] },
2423
{
25-
async get() {
26-
return API.v1.success({
27-
oauthApps: await OAuthApps.find().toArray(),
28-
});
24+
authRequired: true,
25+
query: ajv.compile<{ uid?: string }>({
26+
type: 'object',
27+
properties: {
28+
uid: {
29+
type: 'string',
30+
},
31+
},
32+
additionalProperties: false,
33+
}),
34+
permissionsRequired: ['manage-oauth-apps'],
35+
response: {
36+
400: validateBadRequestErrorResponse,
37+
401: validateUnauthorizedErrorResponse,
38+
403: validateForbiddenErrorResponse,
39+
200: ajv.compile<{ oauthApps: IOAuthApps[] }>({
40+
type: 'object',
41+
properties: {
42+
oauthApps: {
43+
type: 'array',
44+
items: {
45+
$ref: '#/components/schemas/IOAuthApps',
46+
},
47+
},
48+
success: {
49+
type: 'boolean',
50+
enum: [true],
51+
},
52+
},
53+
required: ['oauthApps', 'success'],
54+
additionalProperties: false,
55+
}),
2956
},
3057
},
58+
59+
async function action() {
60+
return API.v1.success({
61+
oauthApps: await OAuthApps.find().toArray(),
62+
});
63+
},
3164
);
3265

3366
API.v1.addRoute(
@@ -152,9 +185,13 @@ const oauthAppsCreateEndpoints = API.v1.post(
152185

153186
type OauthAppsCreateEndpoints = ExtractRoutesFromAPI<typeof oauthAppsCreateEndpoints>;
154187

155-
export type OAuthAppsEndpoints = OauthAppsCreateEndpoints;
188+
type OauthAppsListEndpoints = ExtractRoutesFromAPI<typeof oauthAppsListEndpoints>;
189+
190+
export type OAuthAppsEndpoints = OauthAppsCreateEndpoints | OauthAppsListEndpoints;
156191

157192
declare module '@rocket.chat/rest-typings' {
158193
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
159194
interface Endpoints extends OauthAppsCreateEndpoints {}
195+
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
196+
interface Endpoints extends OauthAppsListEndpoints {}
160197
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import type { IOAuthApps, IUser } from '@rocket.chat/core-typings';
1+
import type { IOAuthApps } from '@rocket.chat/core-typings';
22

33
import type { DeleteOAuthAppParams } from './oauthapps/DeleteOAuthAppParamsDELETE';
44
import type { OauthAppsGetParams } from './oauthapps/OAuthAppsGetParamsGET';
55
import type { UpdateOAuthAppParams } from './oauthapps/UpdateOAuthAppParamsPOST';
66

77
export type OAuthAppsEndpoint = {
8-
'/v1/oauth-apps.list': {
9-
GET: (params: { uid: IUser['_id'] }) => {
10-
oauthApps: IOAuthApps[];
11-
};
12-
};
13-
148
'/v1/oauth-apps.get': {
159
GET: (params: OauthAppsGetParams) => {
1610
oauthApp: IOAuthApps;

0 commit comments

Comments
 (0)