chore: Convert some apis to openAPI

GG
7mo ago
+3647-1732

This pull request refactors several API endpoint implementations to improve validation, error handling, and OpenAPI schema consistency. The main changes involve migrating from legacy route registration to new API.v1.get and API.v1.post methods, adding explicit response schemas, and updating parameter validation. These updates enhance reliability, ensure stricter contract enforcement, and make API responses easier to document and consume.

API Schema and Validation Improvements

  • Migrated legacy API.v1.addRoute calls to new API.v1.get and API.v1.post methods across multiple files, enabling explicit response schemas and improved parameter validation for endpoints such as assets, autotranslate, banners, and calendar-events. [1] [2] [3] [4]
  • Added AJV-based response schemas for success and error responses, including type-safe definitions for returned data, and standardized error handling (400, 401, 403) for all affected endpoints. [1] [2] [3] [4] [5]

Parameter Handling and Type Improvements

  • Updated parameter validation to use query and body fields instead of legacy validateParams, improving clarity and correctness of input handling. [1] [2] [3] [4]
  • Refined type checks, such as using Record<string, unknown> instead of object for response bodies, and ensuring nullable fields are handled correctly. [1] [2] [3]

Consistency and Error Handling

  • Standardized response structure for success and error cases, including consistent use of { success: true } and explicit schemas for returned objects or arrays. [1] [2] [3]
  • Improved error handling by checking user permissions and ownership before allowing modifications or deletions, and throwing errors when invalid conditions are detected. [1] [2]

OpenAPI and Core Typings Integration

  • Integrated core typings (e.g., IBanner, ICalendarEvent, ISupportedLanguage) into response schemas for better OpenAPI documentation and type safety. [1] [2] [3] [4]

Cleanup and Modernization

  • Removed redundant code and legacy route registration, consolidating endpoint definitions and improving maintainability. [1] [2] [3] [4]

These changes collectively make the API more robust, easier to maintain, and friendlier for clients and documentation tools.

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Task: ARCH-2050

Summary by CodeRabbit

Release Notes

  • New Features

    • Added autotranslate message translation and settings management endpoints
    • Added e2e user key management endpoint
    • Added cloud checkout URL endpoint
  • Improvements

    • Enhanced API validation with stricter schema enforcement across multiple endpoints
    • Improved error messages with more detailed path information
    • Standardized API responses with consistent success indicators
    • Refined directory search results to include optimized user and channel data
  • Documentation

    • Added comprehensive API migration guide for developers