#!/usr/bin/env python3 """ Simple OpenAPI schema generator for FastAPI. This generates only the JSON schema file that can be used with openapi-typescript. """ import json import sys from pathlib import Path def generate_schema(): """Generate OpenAPI schema from the FastAPI app""" try: # Add shared module to path for Docker environment shared_path = "/shared" if shared_path not in sys.path: sys.path.insert(0, shared_path) # Import the FastAPI app from main import app # Get the OpenAPI schema schema = app.openapi() # Write the schema to a JSON file that can be accessed from outside container schema_file = Path("/client/openapi-schema.json") with open(schema_file, 'w', encoding='utf-8') as f: json.dump(schema, f, indent=2, ensure_ascii=False) print(f"✅ OpenAPI schema generated successfully at: {schema_file}") print(f"Schema contains {len(schema.get('components', {}).get('schemas', {}))} component schemas") return True except Exception as e: print(f"❌ Error generating OpenAPI schema: {e}") import traceback traceback.print_exc() return False if __name__ == "__main__": success = generate_schema() sys.exit(0 if success else 1)