cuatrolabs-scm-ms / tests /test_swagger_fix.py
MukeshKapoor25's picture
refactor(database): consolidate shared database base and fix foreign key schema references
cd357c6
#!/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)