chore: migrate rooms.createDiscussion endpoint to new API format with AJV validation
Closed
HA
6mo ago+86+86+01234567890123456789-54-54-01234567890123456789
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.createDiscussiontoAPI.v1.post - Added AJV validation for:
- Request body (
prid,t_name, optional fields likepmid,users,encrypted,topic) - Response (
{ discussion: object, success: true })
- Request body (
- 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
- Discussion creation using
- Updated typings using
ExtractRoutesFromAPI - Removed deprecated
addRouteusage
Issue(s)
N/A (part of OpenAPI migration effort)
Steps to test or reproduce
- Send a POST request to
/api/v1/rooms.createDiscussionwith:- Required fields:
prid,t_name - Optional fields:
pmid,reply,users,encrypted,topic
- Required fields:
- Verify response:
{ success: true, discussion: { ... } }
- Ensure validation fails for:
- Missing required fields (
prid,t_name) - Invalid types (e.g., non-array
users, non-booleanencrypted)
- Missing required fields (
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.