Files
openapi-first/openapi_first/codegen.py
Vishesh 'ironeagle' Bangotra 621f10409e chore(release): 0.0.7
Squash-merge lib-standardisation: adopt repo standards across packaging,
tooling, docs, and CI.

- standardize pyproject.toml (canonical packaging, lint config, extras, GSDFC pydoclint)
- add py.typed marker, modernize type hints and Google-style docstrings
- nest generated docs under docs/lib and docs/mcp; add hand-written wiki
- adopt standard Type A PyPI CI pipeline (tag==version guard + quality gate)
- promote generated CHANGELOG.md; bump version to 0.0.7
2026-10-17 02:16:49 +05:30

55 lines
1.4 KiB
Python

"""
# Summary
Core logic for generating Python source code from OpenAPI specifications.
This module provides reusable utilities for code generation, specifically
generating Pydantic models and route handler stubs from OpenAPI 3.x schema
definitions.
"""
from pathlib import Path
from datamodel_code_generator import (
InputFileType,
PythonVersion,
generate,
)
from .codegen_routes import generate_routes
def generate_models(
spec_path: Path,
output_path: Path,
pydantic_version: int = 2,
) -> None:
"""
Generate Pydantic models from an OpenAPI specification.
Args:
spec_path (Path):
Path to the OpenAPI specification file (YAML or JSON).
output_path (Path):
Path where the generated Python code should be written.
pydantic_version (int, optional):
The Pydantic version to target (1 or 2). Defaults to 2.
Notes:
**Reusability:**
This function is designed to be used by the CLI and can be
exposed as an MCP tool without modification.
"""
generate(
input_=spec_path,
input_file_type=InputFileType.OpenAPI,
output=output_path,
target_python_version=PythonVersion.PY_310,
use_schema_description=True,
use_standard_collections=True,
use_union_operator=True,
)
__all__ = ["generate_models", "generate_routes"]