-
Notifications
You must be signed in to change notification settings - Fork 268
Fix API silent failures and add OpenAPI 3.0 spec with Swagger UI #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for vllm-semantic-router ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- Add validateTaskType helper function to validate task_type parameter - Reject invalid task_type values with 400 error and helpful message - Add GET /api/v1 endpoint for API discovery - Return comprehensive API overview with endpoints, task_types, and links - Add tests for invalid task_type values (jailbreak, invalid_type) - Add tests for valid task_types (intent, pii, security, all) - Add test for API overview endpoint Co-authored-by: rootfs <[email protected]>
👥 vLLM Semantic Team NotificationThe following members have been identified for the changed files in this PR and have been automatically assigned: 📁
|
|
@copilot can you use openapi generator instead of hardcode, so we can generate the spec for future api expansions. |
- Replace hardcoded endpoint list with endpointRegistry - Replace hardcoded task types with taskTypeRegistry - Generate API documentation dynamically from registries - Add filtering logic for system prompt endpoints - Add test for system prompt endpoint filtering - Enables future OpenAPI spec generation from registry - Makes API documentation easier to maintain and extend Co-authored-by: rootfs <[email protected]>
Refactored to use a centralized registry pattern in commit 34001e2. Instead of hardcoding endpoints in the handler, I created:
This approach:
The registry pattern allows future enhancements like generating full OpenAPI 3.0 specs at |
|
@copilot add full OpenAPI 3.0 specs at /openapi.json and serving Swagger UI at /docs |
- Implement OpenAPI 3.0 specification structures - Add generateOpenAPISpec() to dynamically generate spec from registry - Add /openapi.json endpoint serving OpenAPI 3.0 spec - Add /docs endpoint serving interactive Swagger UI - Update endpoint registry to include new documentation endpoints - Add openapi_spec and swagger_ui links to API overview - Automatically filter system prompt endpoints in spec based on config - Add comprehensive tests for OpenAPI and Swagger UI endpoints - Tests verify spec structure, filtering, and UI rendering Co-authored-by: rootfs <[email protected]>
Implemented in commit bb6f7d2. Added two new endpoints:
Both endpoints are generated from the centralized registry, ensuring documentation always matches the actual API. The spec can be used to generate client SDKs with tools like openapi-generator or swagger-codegen. Access the interactive docs at |
…m-project#326) * Initial plan * Add task_type validation and API discovery endpoint - Add validateTaskType helper function to validate task_type parameter - Reject invalid task_type values with 400 error and helpful message - Add GET /api/v1 endpoint for API discovery - Return comprehensive API overview with endpoints, task_types, and links - Add tests for invalid task_type values (jailbreak, invalid_type) - Add tests for valid task_types (intent, pii, security, all) - Add test for API overview endpoint Co-authored-by: rootfs <[email protected]> * Refactor API discovery to use centralized registry pattern - Replace hardcoded endpoint list with endpointRegistry - Replace hardcoded task types with taskTypeRegistry - Generate API documentation dynamically from registries - Add filtering logic for system prompt endpoints - Add test for system prompt endpoint filtering - Enables future OpenAPI spec generation from registry - Makes API documentation easier to maintain and extend Co-authored-by: rootfs <[email protected]> * Add OpenAPI 3.0 spec generation and Swagger UI - Implement OpenAPI 3.0 specification structures - Add generateOpenAPISpec() to dynamically generate spec from registry - Add /openapi.json endpoint serving OpenAPI 3.0 spec - Add /docs endpoint serving interactive Swagger UI - Update endpoint registry to include new documentation endpoints - Add openapi_spec and swagger_ui links to API overview - Automatically filter system prompt endpoints in spec based on config - Add comprehensive tests for OpenAPI and Swagger UI endpoints - Tests verify spec structure, filtering, and UI rendering Co-authored-by: rootfs <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: rootfs <[email protected]> Signed-off-by: liuhy <[email protected]>
…m-project#326) * Initial plan * Add task_type validation and API discovery endpoint - Add validateTaskType helper function to validate task_type parameter - Reject invalid task_type values with 400 error and helpful message - Add GET /api/v1 endpoint for API discovery - Return comprehensive API overview with endpoints, task_types, and links - Add tests for invalid task_type values (jailbreak, invalid_type) - Add tests for valid task_types (intent, pii, security, all) - Add test for API overview endpoint Co-authored-by: rootfs <[email protected]> * Refactor API discovery to use centralized registry pattern - Replace hardcoded endpoint list with endpointRegistry - Replace hardcoded task types with taskTypeRegistry - Generate API documentation dynamically from registries - Add filtering logic for system prompt endpoints - Add test for system prompt endpoint filtering - Enables future OpenAPI spec generation from registry - Makes API documentation easier to maintain and extend Co-authored-by: rootfs <[email protected]> * Add OpenAPI 3.0 spec generation and Swagger UI - Implement OpenAPI 3.0 specification structures - Add generateOpenAPISpec() to dynamically generate spec from registry - Add /openapi.json endpoint serving OpenAPI 3.0 spec - Add /docs endpoint serving interactive Swagger UI - Update endpoint registry to include new documentation endpoints - Add openapi_spec and swagger_ui links to API overview - Automatically filter system prompt endpoints in spec based on config - Add comprehensive tests for OpenAPI and Swagger UI endpoints - Tests verify spec structure, filtering, and UI rendering Co-authored-by: rootfs <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: rootfs <[email protected]> Signed-off-by: liuhy <[email protected]>
…m-project#326) * Initial plan * Add task_type validation and API discovery endpoint - Add validateTaskType helper function to validate task_type parameter - Reject invalid task_type values with 400 error and helpful message - Add GET /api/v1 endpoint for API discovery - Return comprehensive API overview with endpoints, task_types, and links - Add tests for invalid task_type values (jailbreak, invalid_type) - Add tests for valid task_types (intent, pii, security, all) - Add test for API overview endpoint Co-authored-by: rootfs <[email protected]> * Refactor API discovery to use centralized registry pattern - Replace hardcoded endpoint list with endpointRegistry - Replace hardcoded task types with taskTypeRegistry - Generate API documentation dynamically from registries - Add filtering logic for system prompt endpoints - Add test for system prompt endpoint filtering - Enables future OpenAPI spec generation from registry - Makes API documentation easier to maintain and extend Co-authored-by: rootfs <[email protected]> * Add OpenAPI 3.0 spec generation and Swagger UI - Implement OpenAPI 3.0 specification structures - Add generateOpenAPISpec() to dynamically generate spec from registry - Add /openapi.json endpoint serving OpenAPI 3.0 spec - Add /docs endpoint serving interactive Swagger UI - Update endpoint registry to include new documentation endpoints - Add openapi_spec and swagger_ui links to API overview - Automatically filter system prompt endpoints in spec based on config - Add comprehensive tests for OpenAPI and Swagger UI endpoints - Tests verify spec structure, filtering, and UI rendering Co-authored-by: rootfs <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: rootfs <[email protected]> Signed-off-by: liuhy <[email protected]>
…m-project#326) * Initial plan * Add task_type validation and API discovery endpoint - Add validateTaskType helper function to validate task_type parameter - Reject invalid task_type values with 400 error and helpful message - Add GET /api/v1 endpoint for API discovery - Return comprehensive API overview with endpoints, task_types, and links - Add tests for invalid task_type values (jailbreak, invalid_type) - Add tests for valid task_types (intent, pii, security, all) - Add test for API overview endpoint Co-authored-by: rootfs <[email protected]> * Refactor API discovery to use centralized registry pattern - Replace hardcoded endpoint list with endpointRegistry - Replace hardcoded task types with taskTypeRegistry - Generate API documentation dynamically from registries - Add filtering logic for system prompt endpoints - Add test for system prompt endpoint filtering - Enables future OpenAPI spec generation from registry - Makes API documentation easier to maintain and extend Co-authored-by: rootfs <[email protected]> * Add OpenAPI 3.0 spec generation and Swagger UI - Implement OpenAPI 3.0 specification structures - Add generateOpenAPISpec() to dynamically generate spec from registry - Add /openapi.json endpoint serving OpenAPI 3.0 spec - Add /docs endpoint serving interactive Swagger UI - Update endpoint registry to include new documentation endpoints - Add openapi_spec and swagger_ui links to API overview - Automatically filter system prompt endpoints in spec based on config - Add comprehensive tests for OpenAPI and Swagger UI endpoints - Tests verify spec structure, filtering, and UI rendering Co-authored-by: rootfs <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: rootfs <[email protected]> Signed-off-by: liuhy <[email protected]>

Problem
The Classification API had two critical usability issues that led to user confusion:
1. Silent Failures with Invalid
task_typeValuesInvalid
task_typeparameters silently defaulted to intent classification instead of returning an error:This caused real-world confusion when testing jailbreak detection - users assumed
task_type: "jailbreak"would work, but it silently used intent classification instead. The correct parameter istask_type: "security".2. No API Discoverability
There was no way to discover API capabilities without reading source code:
Solution
Input Validation
Added
validateTaskType()function that validates thetask_typeparameter against supported values:intent,pii,security,all. Invalid values now return HTTP 400 with a clear error message:API Discovery Endpoint with Registry Pattern
Added
GET /api/v1endpoint that provides comprehensive API documentation, implemented using a centralized registry pattern for maintainability:Registry-based implementation:
endpointRegistry- centralized registry of all endpoint metadatataskTypeRegistry- centralized registry of all task typesOpenAPI 3.0 Specification and Swagger UI
Added full OpenAPI 3.0 specification and interactive Swagger UI documentation:
GET /openapi.json- OpenAPI 3.0 SpecificationGET /docs- Interactive Swagger UIChanges
validateTaskType()helper function for input validationhandleBatchClassification()before processing requestsGET /api/v1API discovery endpoint withhandleAPIOverview()handlerendpointRegistryandtaskTypeRegistryfor maintainable API documentationgenerateOpenAPISpec()functionGET /openapi.jsonendpoint serving dynamically generated OpenAPI 3.0 specificationGET /docsendpoint serving interactive Swagger UIAPIOverviewResponse,EndpointInfo,TaskTypeInfo,EndpointMetadata,OpenAPISpec,OpenAPIOperation, etc.Testing
All tests pass successfully:
jailbreak,invalid_type) return HTTP 400 with helpful errorsintent,pii,security,all) are acceptedtask_typedefaults tointent(backward compatible)Backward Compatibility
No breaking changes:
task_typestill defaults to "intent"Impact
Fixes the confusion around jailbreak detection - users now get a clear error pointing them to use
task_type: "security"instead of guessing parameter names.Fixes #321
Original prompt
This section details on the original issue you should resolve
<issue_title>API Discoverability and Silent Failure Issues</issue_title>
<issue_description>The Classification API lacks standard discovery mechanisms and silently accepts invalid parameters, leading to user confusion and incorrect usage.
🔍 API Discoverability Problems
❌ No Standard Discovery Endpoints
❌ No API Documentation Available
🤫 Silent Failure Issues
Critical Problem: Invalid
task_typeValues Silently Default to Intent ClassificationWhat Happens:
All return HTTP 200 with identical responses:
{ "results": [{"category": "psychology", "confidence": 0.995}], "total_count": 1 }Root Cause in Code
Lines 634-635 and 672-673 in
server.go:🎯 Real-World Impact
This caused confusion when testing jailbreak detection:
task_type: "jailbreak"should work for jailbreak detectiontask_type: "security"is the correct parameter🛠️ Proposed Solutions
1. Input Validation
Expected Error Response (400 Bad Request):
{ "error": { "code": "INVALID_TASK_TYPE", "message": "Invalid task_type 'jailbreak'. Supported values: ['intent', 'pii', 'security', 'all']", "supported_values": ["intent", "pii", "security", "all"] } }2. API Discovery Endpoints
3. Self-Documenting API Responses
{ "results": [...], "metadata": { "task_type_used": "security", "available_task_types": ["intent", "pii", "security", "all"], "endpoint_docs": "/docs" } }4. Enhanced Error Messages
For missing/invalid parameters, provide helpful guidance:
{ "error": { "message": "Invalid request", "details": "...", "documentation": "http://localhost:8080/docs", "examples": { "jailbreak_detection": "Use task_type: 'security' for jailbreak detection", "intent_classification": "Use task_type: 'intent' or omit for intent classification" } } }📊 Current API Endpoints (Discovered from Source)
For reference, here are the actual available endpoints:
Valid
task_typevalues for batch endpoint:"intent"- Intent/category classification (default)"pii"- PII detection"security"- Jailbreak/security detection"all"- All classification types🎯 Benefits of Fixing This
This issue affects A...
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.