feat: Add OpenAPI Support to oauth-apps.create API

Merged
AH
1y ago
+107-42

Description:
This PR integrates OpenAPI support into the Rocket.Chat API, migrate of Rocket.Chat API endpoints to the new OpenAPI pattern. The update includes improved API documentation, enhanced type safety, and response validation using AJV.

Key Changes:

  • Implemented the new pattern and added AJV-based JSON schema validation for API.
  • Uses the ExtractRoutesFromAPI utility from the TypeScript definitions to dynamically derive the routes from the endpoint specifications.
  • Enabled Swagger UI integration for this API.
  • This does not introduce any breaking changes to the endpoint logic.

Issue Reference:
Relates to #34983, part of the ongoing OpenAPI integration effort.

Testing:

  • Verified that the API response schemas are correctly documented in Swagger UI.
  • All tests passed without any breaking changes
$ yarn testapi -f '[OAuthApps]'

  [OAuthApps]
    [/oauth-apps.list]
      ✔ should return an error when the user does not have the necessary permission (283ms)
      ✔ should return an array of oauth apps (259ms)
    [/oauth-apps.create]
      ✔ should return an error when the user does not have the necessary permission (393ms)
      ✔ should return an error when the 'name' property is invalid (43ms)
      ✔ should return an error when the 'redirectUri' property is invalid
      ✔ should return an error when the 'active' property is not a boolean
      ✔ should create an oauthApp
    [/oauth-apps.get]
      ✔ should return a single oauthApp by client id
      ✔ should return a single oauthApp by _id
      ✔ should return a single oauthApp by appId (deprecated) (147ms)
      ✔ should return only non sensitive information if user does not have the permission to manage oauth apps when searching by clientId (309ms)
      ✔ should return only non sensitive information if user does not have the permission to manage oauth apps when searching by _id (210ms)
      ✔ should return only non sensitive information if user does not have the permission to manage oauth apps when searching by appId (deprecated) (206ms)
      ✔ should fail returning an oauth app when an invalid id is provided (avoid NoSQL injections)
      ✔ should fail returning an oauth app when an invalid id string is provided (avoid NoSQL injections)
      ✔ should fail returning an oauth app when an invalid clientId is provided (avoid NoSQL injections)
      ✔ should fail returning an oauth app when an invalid clientId string is provided (avoid NoSQL injections)
      ✔ should fail returning an oauth app when an invalid appId is provided (avoid NoSQL injections; deprecated)
      ✔ should fail returning an oauth app when an invalid appId string is provided (avoid NoSQL injections; deprecated)
    [/oauth-apps.update]
      ✔ should update an app's name, its Active and Redirect URI fields correctly by its id
      ✔ should fail updating an app if user does NOT have the manage-oauth-apps permission (218ms)
    [/oauth-apps.delete]
      ✔ should delete an app by its id
      ✔ should fail deleting an app by its id if user does NOT have the manage-oauth-apps permission (201ms)


  23 passing (5s)

Endpoints:

Looking forward to your feedback! 🚀