v1.3.6: Enhanced Swagger UI Detection & DOM Fallback
π§ Enhanced Swagger UI Detection - Multi-Pattern Access & DOM Fallback
Major improvement: Comprehensive Swagger UI detection with multiple access patterns and DOM fallback methods.
β¨ Enhanced Features
- π Multi-Pattern UI Detection - Checks window.ui, window.swaggerUi, window.SwaggerUIBundle
- π― Dynamic Object Discovery - Scans all window objects for Swagger-related instances
- π Environment Diagnostics - Detailed logging of Swagger scripts and DOM elements
- π‘οΈ DOM Fallback Method - Manual DOM manipulation when API access fails
- β±οΈ Extended Retry Logic - 30 attempts over 15 seconds for slower environments
π§ Technical Improvements
- Smart UI Detection:
// Multiple detection patterns if (window.ui && typeof window.ui.preauthorizeApiKey === 'function') { uiObject = window.ui; } else if (window.swaggerUi && typeof window.swaggerUi.preauthorizeApiKey === 'function') { uiObject = window.swaggerUi; } else { // Dynamic scanning for any Swagger UI instances const possibleUIs = Object.keys(window).filter(key => key.toLowerCase().includes('swagger') || key.toLowerCase().includes('ui') ); }
- DOM Fallback Strategy:
// Direct DOM manipulation as last resort const authInput = document.querySelector('input[placeholder*="Bearer"]'); if (authInput) { authInput.value = `Bearer ${token}`; authInput.dispatchEvent(new Event('input', { bubbles: true })); }
- Enhanced Debugging: Comprehensive environment diagnostics and fallback reporting
π― What This Solves
- Universal Compatibility: Works with different Swagger UI versions and configurations
- Custom Implementations: Handles non-standard Swagger UI setups
- Diagnostic Information: Clear troubleshooting data for development environments
- Graceful Degradation: Multiple fallback methods ensure functionality
π‘ Debugging Output
Now provides detailed diagnostic information:
π Scanning for Swagger UI objects...
window.ui: undefined
window.swaggerUi: undefined
window.SwaggerUIBundle: function
π Swagger scripts found: 2
π¨ Swagger DOM elements found: 5
π Possible UI objects: ['SwaggerUIBundle', 'ui']
This specifically addresses the persistent window.ui undefined issue you encountered by implementing comprehensive detection and fallback strategies.
π¦ Installation
pip install --upgrade drf-spectacular-auth==1.3.6