Skip to main content

---

title: "Generate Openapi" component_type: script version: "1.0.0" audience: contributor status: stable summary: "CODITECT OpenAPI Specification Generator ========================================" keywords: ['api', 'generate', 'generation', 'openapi', 'security'] tokens: ~500 created: 2025-12-22 updated: 2025-12-22 script_name: "generate_openapi.py" language: python executable: true usage: "python3 scripts/generate_openapi.py [options]" python_version: "3.10+" dependencies: [] modifies_files: false network_access: false requires_auth: false

CODITECT OpenAPI Specification Generator

STATUS: STUB - Not yet implemented VERSION: 0.1.0 (placeholder) AUTHOR: CODITECT Core Team

DESCRIPTION: Generates OpenAPI 3.x specifications from code annotations, docstrings, and existing API definitions. Supports multiple frameworks (FastAPI, Flask, Express, Actix) with automatic schema extraction.

PURPOSE: - Extract API definitions from code (routes, handlers, models) - Generate OpenAPI 3.0/3.1 compliant specifications - Merge multiple API sources into unified spec - Validate specs against OpenAPI schema - Generate client SDKs from specs

EXPECTED INPUTS: --source : Source type (fastapi, flask, express, actix, manual) --paths : Paths to scan for API definitions --output : Output file path (default: openapi.json) --format : Output format (json, yaml) --version : OpenAPI version (3.0.3, 3.1.0) --title : API title --api-version : API version string --servers : Server URLs (comma-separated) --merge : Additional spec files to merge

EXPECTED OUTPUTS: - openapi.json/yaml conforming to OpenAPI 3.x with: - info (title, version, description) - servers (URLs, descriptions) - paths (endpoints with operations) - components (schemas, security, parameters) - tags (endpoint grouping) - security (authentication schemes)

DEPENDENCIES: - pyyaml - YAML support - jsonschema - spec validation - apispec (optional) - framework integrations - openapi-spec-validator - spec validation

IMPLEMENTATION REQUIREMENTS: 1. AST parsing for route extraction (Python, JS, Rust) 2. Docstring/comment parsing for descriptions 3. Type hint extraction for schema generation 4. Request/response model inference 5. Security scheme detection 6. Multiple framework support 7. Incremental generation (only changed files) 8. Spec merging with conflict resolution 9. Validation against OpenAPI schema 10. SDK generation integration (openapi-generator)

FRAMEWORK SUPPORT: Python: FastAPI (native), Flask (apispec), Django REST JavaScript: Express (swagger-jsdoc), Fastify, NestJS Rust: Actix-web (paperclip), Axum Go: Gin (swag), Echo

USAGE EXAMPLES: # Generate from FastAPI app python scripts/generate_openapi.py
--source fastapi
--paths src/api/
--output docs/api/openapi.json

# Merge multiple specs
python scripts/generate_openapi.py \
--source manual \
--merge api-v1.yaml,api-v2.yaml \
--output openapi-combined.yaml

# With custom metadata
python scripts/generate_openapi.py \
--source flask \
--title "CODITECT API" \
--api-version "2.0.0" \
--servers "https://api.coditect.ai,https://staging.coditect.ai"

RELATED COMMANDS: - /doc-generate : Documentation generation - /api-documentation : API docs skill

SEE ALSO: - commands/doc-generate.md - docs/api/API-DOCUMENTATION-GUIDE.md

File: generate_openapi.py

Functions

main()

No description

Usage

python generate_openapi.py