Skip to content

Fix API Routing and Add Automated Testing#134

Open
uelkerd wants to merge 63 commits into
mainfrom
fix-api-routing
Open

Fix API Routing and Add Automated Testing#134
uelkerd wants to merge 63 commits into
mainfrom
fix-api-routing

Conversation

@uelkerd
Copy link
Copy Markdown
Owner

@uelkerd uelkerd commented Sep 4, 2025

This PR addresses Flask-RESTX routing issues and implements comprehensive automated testing.

Changes Made

Routing Fixes

  • Corrected endpoint registration in Flask-RESTX
  • Fixed namespace conflicts and URL path issues
  • Updated API documentation to reflect routing changes

Automated Testing Implementation

  • Added unit tests for API routing functionality
  • Created integration tests for endpoint validation
  • Implemented test coverage for routing fixes
  • Added debugging utilities for API testing

Files Modified

  • deployment/cloud-run/secure_api_server.py: Updated routing logic
  • deployment/cloud-run/test_routing_debug.py: Enhanced debugging
  • deployment/cloud-run/test_routing_minimal.py: Minimal test cases
  • deployment/cloud-run/test_swagger_debug.py: Swagger integration tests
  • deployment/cloud-run/test_debug_server.py: New debugging server (added)
  • tests/unit/test_api_routing.py: New unit tests (added)
  • tests/unit/test_routing_fixes.py: New routing tests (added)

Testing

All changes have been tested locally and automated tests pass. The API now correctly handles routing without conflicts.

Impact

These changes improve API reliability and maintainability by fixing routing issues and adding robust testing coverage.

Summary by Sourcery

Fix API routing issues by reordering root endpoint registration, removing leading slashes from namespaces, and bolstering logging, and introduce comprehensive automated tests (unit, integration, and debug scripts) to validate endpoint routes and functionality.

New Features:

  • Add unit and integration tests covering API routing, health, predict, and admin endpoints
  • Introduce a debug test server and debugging utilities to troubleshoot Flask-RESTX routing and Swagger integration

Bug Fixes:

  • Ensure root endpoint is registered before Flask-RESTX initialization to avoid conflicts
  • Remove leading slashes from namespace definitions to prevent double-slash URL issues
  • Correct namespace registration and error handler setup in secure_api_server to fix routing and Swagger errors

Enhancements:

  • Increase logging verbosity to DEBUG and add detailed logs for initialization, route registration, and error handler registration
  • Wrap API initialization and error handler registration in try/catch blocks with success/failure logging to improve troubleshooting

Tests:

  • Add new test suite under tests/unit for API routing, routing fixes, and endpoint validation
  • Add routing debug, minimal, and Swagger-specific test scripts under deployment/cloud-run to verify endpoint setup and namespace behavior

Summary by CodeRabbit

  • New Features

    • Added NLP emotion analysis endpoints for single and batch text.
    • Toggle API docs via environment flag; Swagger available at /docs when enabled.
    • Metrics endpoint enhanced with richer server and model stats (admin key required).
  • Improvements

    • Clearer error responses and standardized logging with request tracing/timing headers.
    • Consistent routing with simplified namespace paths (/api, /admin).
    • Stronger input validation and security checks.
  • Bug Fixes

    • Resolved routing edge cases (no double slashes, stable root registration).
    • Safer docs file handling with stricter path validation.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-quality enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants