chore: Add OpenAPI Support to push.test API

Merged
AH
7mo ago
+42-16

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.
  • Route Methods Chaining for the endpoints.
  • 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 '[Push]'                       
    
    
      [Push]
        POST [/push.token]
          ✔ should fail if not logged in
          ✔ should fail if missing type
          ✔ should fail if missing value
          ✔ should fail if missing appName
          ✔ should fail if type param is unknown
          ✔ should fail if token param is empty
          ✔ should add a token if valid (127ms)
        DELETE [/push.token]
          ✔ should fail if not logged in
          ✔ should fail if missing token key (80ms)
          ✔ should fail if token is empty
          ✔ should fail if token is invalid (45ms)
          ✔ should delete a token if valid
          ✔ should fail if token is already deleted (53ms)
        [/push.test]
          ✔ should fail if not logged in
          ✔ should fail if push is disabled
        [/push.info]
          ✔ should fail if not logged in
          ✔ should succesfully retrieve non default push notification info
          ✔ should succesfully retrieve default push notification info (221ms)
    
    
      18 passing (2s)
    

Endpoints:

  • Test Push Token

    Test Push Token

Looking forward to your feedback! 🚀

Summary by CodeRabbit

  • Documentation
    • Added OpenAPI support for the push.test API, improving discoverability and docs accuracy.
  • New Features
    • Standardized push.test responses with a defined success schema (tokensCount and success) and clear 400/401 error formats.
    • Added rate limiting (1 req/sec) and explicit permission requirements for push.test.
  • Refactor
    • Migrated push.test to a modern, consistent endpoint definition.
  • Chores
    • Updated API typings and package alignments to support the new endpoint and validation.

COMM-144