Skip to content

v1.3.6: Enhanced Swagger UI Detection & DOM Fallback

Choose a tag to compare

@CodeMath CodeMath released this 31 Aug 14:53
· 15 commits to main since this release

πŸ”§ 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

πŸ”— Links