Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/clever-trees-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/rest-typings": patch
---

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.
82 changes: 63 additions & 19 deletions apps/meteor/app/api/server/v1/oauthapps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { IOAuthApps } from '@rocket.chat/core-typings';
import { OAuthApps } from '@rocket.chat/models';
import {
ajv,
isUpdateOAuthAppParams,
isOauthAppsGetParams,
validateUnauthorizedErrorResponse,
validateBadRequestErrorResponse,
Expand Down Expand Up @@ -59,6 +58,37 @@ const OauthAppsAddParamsSchema = {

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

type UpdateOAuthAppParams = {
appId: string;
name: string;
active: boolean;
clientId?: string | undefined;
clientSecret?: string | undefined;
redirectUri: string;
};

const UpdateOAuthAppParamsSchema = {
type: 'object',
properties: {
appId: {
type: 'string',
},
name: {
type: 'string',
},
active: {
type: 'boolean',
},
redirectUri: {
type: 'string',
},
},
required: ['appId', 'name', 'active', 'redirectUri'],
additionalProperties: false,
};

const isUpdateOAuthAppParams = ajv.compile<UpdateOAuthAppParams>(UpdateOAuthAppParamsSchema);

const oauthAppsEndpoints = API.v1
.get(
'oauth-apps.list',
Expand Down Expand Up @@ -156,6 +186,38 @@ const oauthAppsEndpoints = API.v1

return API.v1.success({ application });
},
)
.post(
'oauth-apps.update',
{
authRequired: true,
body: isUpdateOAuthAppParams,
permissionsRequired: ['manage-oauth-apps'],
response: {
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
403: validateForbiddenErrorResponse,
200: ajv.compile<IOAuthApps | null>({
allOf: [
{ anyOf: [{ $ref: '#/components/schemas/IOAuthApps' }, { type: 'null' }] },
{
type: 'object',
properties: {
success: { type: 'boolean', enum: [true] },
},
required: ['success'],
},
],
}),
},
},
async function action() {
const { appId } = this.bodyParams;

const result = await updateOAuthApp(this.userId, appId, this.bodyParams);

return API.v1.success(result);
},
);

API.v1.addRoute(
Expand Down Expand Up @@ -185,24 +247,6 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'oauth-apps.update',
{
authRequired: true,
validateParams: isUpdateOAuthAppParams,
permissionsRequired: ['manage-oauth-apps'],
},
{
async post() {
const { appId } = this.bodyParams;

const result = await updateOAuthApp(this.userId, appId, this.bodyParams);

return API.v1.success(result);
},
},
);

export type OauthAppsEndpoints = ExtractRoutesFromAPI<typeof oauthAppsEndpoints>;

declare module '@rocket.chat/rest-typings' {
Expand Down
1 change: 0 additions & 1 deletion packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export * from './v1/integrations';
export * from './v1/licenses';
export * from './v1/omnichannel';
export * from './v1/oauthapps';
export * from './v1/oauthapps/UpdateOAuthAppParamsPOST';
export * from './v1/oauthapps/OAuthAppsGetParamsGET';
export * from './helpers/PaginatedRequest';
export * from './helpers/PaginatedResult';
Expand Down
5 changes: 0 additions & 5 deletions packages/rest-typings/src/v1/oauthapps.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import type { IOAuthApps } from '@rocket.chat/core-typings';

import type { OauthAppsGetParams } from './oauthapps/OAuthAppsGetParamsGET';
import type { UpdateOAuthAppParams } from './oauthapps/UpdateOAuthAppParamsPOST';

export type OAuthAppsEndpoint = {
'/v1/oauth-apps.get': {
GET: (params: OauthAppsGetParams) => {
oauthApp: IOAuthApps;
};
};

'/v1/oauth-apps.update': {
POST: (params: UpdateOAuthAppParams) => IOAuthApps | null;
};
};

This file was deleted.

Loading