Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify that the Swagger/OpenAPI issue is fixed. | |
| """ | |
| import json | |
| from fastapi import FastAPI | |
| def test_openapi_generation(): | |
| """Test that OpenAPI schema can be generated without errors""" | |
| print("π§ͺ Testing OpenAPI Schema Generation") | |
| print("=" * 50) | |
| try: | |
| # Import the main FastAPI app | |
| from app.main import app | |
| print("β FastAPI app imported successfully") | |
| # Generate OpenAPI schema | |
| schema = app.openapi() | |
| print("β OpenAPI schema generated successfully") | |
| print(f" - Schema version: {schema.get('openapi', 'unknown')}") | |
| print(f" - API title: {schema.get('info', {}).get('title', 'unknown')}") | |
| print(f" - Number of endpoints: {len(schema.get('paths', {}))}") | |
| # Check if employee endpoints are present | |
| paths = schema.get('paths', {}) | |
| employee_endpoints = [path for path in paths.keys() if '/employees' in path] | |
| print(f" - Employee endpoints: {len(employee_endpoints)}") | |
| # Check if the new is_system_user field is in the schema | |
| components = schema.get('components', {}) | |
| schemas = components.get('schemas', {}) | |
| if 'EmployeeCreate' in schemas: | |
| employee_create_props = schemas['EmployeeCreate'].get('properties', {}) | |
| if 'is_system_user' in employee_create_props: | |
| print("β is_system_user field found in EmployeeCreate schema") | |
| else: | |
| print("β is_system_user field NOT found in EmployeeCreate schema") | |
| if 'EmployeeResponse' in schemas: | |
| employee_response_props = schemas['EmployeeResponse'].get('properties', {}) | |
| if 'is_system_user' in employee_response_props: | |
| print("β is_system_user field found in EmployeeResponse schema") | |
| else: | |
| print("β is_system_user field NOT found in EmployeeResponse schema") | |
| # Test warehouse schema fix | |
| if 'WarehouseResponse' in schemas: | |
| warehouse_example = schemas['WarehouseResponse'].get('example', {}) | |
| capabilities = warehouse_example.get('capabilities', {}) | |
| if capabilities: | |
| print("β Warehouse capabilities example found") | |
| # Check if boolean values are proper Python booleans | |
| can_receive = capabilities.get('can_receive') | |
| if isinstance(can_receive, bool): | |
| print("β Warehouse capabilities use proper boolean values") | |
| else: | |
| print(f"β Warehouse capabilities use invalid type: {type(can_receive)}") | |
| print("\nπ All tests passed! Swagger/OpenAPI should work correctly now.") | |
| return True | |
| except Exception as e: | |
| print(f"β Error: {str(e)}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| if __name__ == "__main__": | |
| success = test_openapi_generation() | |
| exit(0 if success else 1) |