chore: migrate rooms.createDiscussion endpoint to new API format with AJV validation

Closed
HA
6mo ago
+86-54

Proposed changes

This PR migrates the rooms.createDiscussion endpoint from the deprecated addRoute pattern to the new API.v1.post format.
AJV schema validation has been introduced for the request body and response, replacing the existing manual validation logic and aligning the endpoint with the OpenAPI-based API structure.


Details of changes

  • Migrated rooms.createDiscussion to API.v1.post
  • Added AJV validation for:
    • Request body (prid, t_name, optional fields like pmid, users, encrypted, topic)
    • Response ({ discussion: object, success: true })
  • Replaced manual validation logic (if (!prid), if (!t_name), etc.) with schema-based validation
  • Preserved existing business logic:
    • Discussion creation using createDiscussion
    • Air-gapped restrictions validation
    • Filtering of users array
  • Updated typings using ExtractRoutesFromAPI
  • Removed deprecated addRoute usage

Issue(s)

N/A (part of OpenAPI migration effort)


Steps to test or reproduce

  1. Send a POST request to /api/v1/rooms.createDiscussion with:
    • Required fields: prid, t_name
    • Optional fields: pmid, reply, users, encrypted, topic
  2. Verify response:
    • { success: true, discussion: { ... } }
  3. Ensure validation fails for:
    • Missing required fields (prid, t_name)
    • Invalid types (e.g., non-array users, non-boolean encrypted)

Further comments

This endpoint previously relied on manual validation (as noted in the existing TODO comment). This change replaces it with AJV-based validation, improving consistency with the new API structure and enabling better schema-driven validation.
No functional changes were introduced beyond validation standardization.

Summary by CodeRabbit

  • Refactor
    • Enhanced request validation and type safety for the discussion creation API endpoint to ensure proper data handling and improved reliability.