← Back to all products

OpenAPI Spec Generator

$10

Generate OpenAPI 3.0 specifications from Python function signatures and docstrings.

📁 10 files
JSONMarkdownPython

📄 Product Preview

Try the interactive reader and demo tools below, or get the full product with all content unlocked.

📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample

📁 File Structure 10 files

openapi-spec-generator/ ├── LICENSE ├── README.md ├── examples/ │ ├── generated_spec.json │ └── sample_api.py ├── free-sample.zip ├── guide/ │ ├── 01_openapi-spec-generator.md │ ├── 02_features.md │ └── 03_quick-start.md ├── index.html └── src/ └── main.py

📖 Documentation Preview README excerpt

OpenAPI Spec Generator

Generate OpenAPI 3.0 specifications from Python function signatures and docstrings. Zero dependencies.

Part of the API Launchpad toolkit by [CodeVault](https://codevault.dev).

Features

  • Function introspection: extracts parameters from type hints and signatures
  • Docstring parsing: Google-style docstrings → parameter descriptions
  • Type mapping: Python types → JSON Schema (str, int, float, bool, list, dict)
  • Module scanning: auto-discover endpoints from function naming conventions
  • Dual output: JSON or YAML (built-in YAML converter, no PyYAML needed)
  • Request body inference: POST/PUT/PATCH functions automatically get request body schemas
  • Zero dependencies — runs on Python stdlib only

Quick Start


# Generate a demo spec
python3 src/main.py --demo

# Generate spec from a Python module
python3 src/main.py --module my_api.py --title "My API" --output spec.json

# Output as YAML
python3 src/main.py --module my_api.py --format yaml --output spec.yaml

Using as a Library


from main import OpenAPIGenerator

gen = OpenAPIGenerator(
    title="Acme Corp API",
    version="2.0.0",
    description="The Acme Corp public API",
    server_url="https://api.docs.example.com/v2",
)

# Register endpoints from your functions
def list_users(limit: int = 10, offset: int = 0) -> list:
    """List all users with pagination.

    Args:
        limit: Maximum number of users to return
        offset: Number of users to skip
    """
    pass

def create_user(name: str, email: str, role: str = "user") -> dict:
    """Create a new user account.

    Args:
        name: User's full name
        email: User's email address
        role: User role (user, admin)
    """
    pass

*... continues with setup instructions, usage examples, and more.*

📄 Code Sample .py preview

examples/sample_api.py""" Sample API Module — OpenAPI Spec Generator Example ==================================================== This file demonstrates how to annotate your Python functions so the OpenAPI Spec Generator can introspect them and produce a valid OpenAPI 3.0 specification. Usage: python main.py --module sample_api --output spec.json --format json python main.py --module sample_api --output spec.yaml --format yaml The generator reads: - Function names → operation IDs - Docstrings → descriptions, parameter docs, response docs - Type hints → JSON Schema types - Decorators/metadata → HTTP method and path info """ from typing import Optional # --------------------------------------------------------------------------- # The generator looks for a module-level __api_info__ dict for metadata # --------------------------------------------------------------------------- __api_info__ = { "title": "Acme Corp User Service", "version": "2.1.0", "description": "User management API for Acme Corp's internal platform.", "base_url": "https://api.example.com/v2", } # --------------------------------------------------------------------------- # Route metadata: attach HTTP method and path to each function # --------------------------------------------------------------------------- def list_users( page: int = 1, per_page: int = 20, sort_by: str = "created_at",
Buy Now — $10 Back to Products