feat: Add OpenAPI Support to dm.delete/im.delete API

Merged
AH
1y ago
+86-63

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 '[Direct Messages]'      
    
    
    [Direct Messages]
      ✔ /im.history (39ms)
      ✔ /im.list
      ✔ /im.open (41ms)
      ✔ /im.close (46ms)
      /im.setTopic
        ✔ should set the topic of the DM with a string (64ms)
        ✔ should set the topic of DM with an empty string(remove the topic) (57ms)
      Testing DM info
        ✔ sending a message... (95ms)
        ✔ REACTing with last message (43ms)
        ✔ STARring last message (55ms)
        ✔ PINning last message (269ms)
        ✔ should return all DM messages where the last message of array should have the "star" array with USERS star ONLY (85ms)
      /im.list.everyone
        ✔ should succesfully return a list of direct messages (62ms)
        ✔ should fail if user does NOT have the view-room-administration permission (255ms)
      Setting: 'Use Real Name': true
        ✔ /im.list (56ms)
        ✔ /im.list.everyone (50ms)
      /im.counters
        ✔ should require auth
        ✔ should require a roomId (54ms)
        ✔ should work with all params right (62ms)
        with valid room id
          ✔ should properly return counters before opening the dm (49ms)
        with deactived users
          ✔ should not include deactivated users in members count (115ms)
      [/im.files]
        ✔ should fail if invalid channel
        ✔ should fail for room type v (1058ms)
        ✔ should succeed when searching by roomId
        ✔ should succeed when searching by roomId even requested with count and offset params (43ms)
        - should succeed when searching by roomName
        - should succeed when searching by roomName even requested with count and offset params
         (node:22035) [DEP0044] DeprecationWarning: The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.
         (Use `node --trace-deprecation ...` to show where the warning was created)
        ✔ should not return thumbnails (394ms)
        ✔ should not return hidden files (311ms)
        ✔ should properly filter files by name or typeGroup (445ms)
      /im.messages
        ✔ should return all DM messages that were sent to yourself using your username (104ms)
        ✔ should sort by ts by default
        ✔ should allow custom sorting (68ms)
        ✔ should return an error when trying to access a DM that does not belong to the current user
        ✔ should return messages that mention a single user
        ✔ should return messages that mention multiple users
        ✔ should return messages that are starred by a specific user
        ✔ should return messages that are pinned
      /im.messages.others
        ✔ should fail when the endpoint is disabled and the user has permissions (254ms)
        ✔ should fail when the endpoint is disabled and the user doesnt have permission (395ms)
        ✔ should fail when the endpoint is enabled but the user doesnt have permission (383ms)
        ✔ should succeed when the endpoint is enabled and user has permission (407ms)
      fname property
        ✔ should have fname property
        ✔ should update user's name (83ms)
        ✔ should have fname property updated
      /im.members
        ✔ should return and array with two members (44ms)
        ✔ should return and array with one member
        ✔ should return and array with one member queried by status
      /im.create
        ✔ creates a DM between two other parties (including self) (40ms)
        ✔ creates a DM between two other parties (excluding self) (51ms)
        ✔ should create a self-DM
        should create dm with correct notification preferences
          ✔ should save user preferences
          ✔ should create a DM (44ms)
          ✔ should return the right user notification preferences in the dm
        Rooms fullName
          ✔ should be own user's name for self DM
          ✔ should be other user's name concatenated for multiple users's DM for every user (44ms)
          ✔ should be other user's name for DM for both users
      /im.delete
        ✔ /im.create
        ✔ /im.delete (71ms)
        ✔ /im.open
        when authenticated as a non-admin user
          ✔ /im.create
          ✔ /im.delete
    
    
    59 passing (20s)
    2 pending
    

Endpoints:

Looking forward to your feedback! 🚀