Skip to content

Commit 1f2ecdc

Browse files
Merge branch 'develop' into feat/openapi-oauth-apps-update
2 parents ae41b0f + 5d7dec3 commit 1f2ecdc

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-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: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,49 @@ import { updateOAuthApp } from '../../../oauth2-server-config/server/admin/metho
1717
import type { ExtractRoutesFromAPI } from '../ApiClass';
1818
import { API } from '../api';
1919

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

3265
API.v1.addRoute(
@@ -199,11 +232,16 @@ type OauthAppsCreateEndpoints = ExtractRoutesFromAPI<typeof oauthAppsCreateEndpo
199232

200233
type OauthAppsuUpdateEndpoints = ExtractRoutesFromAPI<typeof oauthAppsuUpdateEndpoints>;
201234

202-
export type OAuthAppsEndpoints = OauthAppsCreateEndpoints | OauthAppsuUpdateEndpoints;
235+
type OauthAppsListEndpoints = ExtractRoutesFromAPI<typeof oauthAppsListEndpoints>;
236+
237+
export type OAuthAppsEndpoints = OauthAppsCreateEndpoints | OauthAppsListEndpoints | OauthAppsuUpdateEndpoints;
238+
203239

204240
declare module '@rocket.chat/rest-typings' {
205241
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
206242
interface Endpoints extends OauthAppsCreateEndpoints {}
207243
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
208244
interface Endpoints extends OauthAppsuUpdateEndpoints {}
245+
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
246+
interface Endpoints extends OauthAppsListEndpoints {}
209247
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
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

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

0 commit comments

Comments
 (0)