{ "module": "openapi_first.codegen", "content": { "path": "openapi_first.codegen", "docstring": "# Summary\n\nCore logic for generating Python source code from OpenAPI specifications.\n\nThis module provides reusable utilities for code generation, specifically\ngenerating Pydantic models and route handler stubs from OpenAPI 3.x schema\ndefinitions.", "objects": { "Path": { "name": "Path", "kind": "alias", "path": "openapi_first.codegen.Path", "signature": "", "docstring": null }, "InputFileType": { "name": "InputFileType", "kind": "alias", "path": "openapi_first.codegen.InputFileType", "signature": "", "docstring": null }, "PythonVersion": { "name": "PythonVersion", "kind": "alias", "path": "openapi_first.codegen.PythonVersion", "signature": "", "docstring": null }, "generate": { "name": "generate", "kind": "alias", "path": "openapi_first.codegen.generate", "signature": "", "docstring": null }, "generate_routes": { "name": "generate_routes", "kind": "function", "path": "openapi_first.codegen.generate_routes", "signature": "", "docstring": "Generate route handler stubs from an OpenAPI specification.\n\nCreates one ``.py`` file per resource in *output_dir*.\nResources are derived from the first path segment (e.g. ``/pets``\nand ``/pets/{id}`` both group under ``pets``).\n\nArgs:\n spec_path (Path):\n Path to the OpenAPI specification file (YAML or JSON).\n output_dir (Path):\n Directory where the generated route files are written.\n Created automatically if it does not exist.\n use_models (bool, optional):\n If ``True``, import Pydantic models from *models_module*\n for request-body schemas referenced via ``$ref``.\n models_module (str, optional):\n Dotted Python module path from which to import models\n (e.g. ``\"models\"``, ``\"app.models\"``).\n\nReturns:\n list[Path]:\n Absolute paths of every generated route file.\n\nRaises:\n OpenAPISpecLoadError:\n If the spec cannot be loaded or validated.\n ValueError:\n If any operation is missing ``operationId``." }, "generate_models": { "name": "generate_models", "kind": "function", "path": "openapi_first.codegen.generate_models", "signature": "", "docstring": "Generate Pydantic models from an OpenAPI specification.\n\nArgs:\n spec_path (Path):\n Path to the OpenAPI specification file (YAML or JSON).\n output_path (Path):\n Path where the generated Python code should be written.\n pydantic_version (int, optional):\n The Pydantic version to target (1 or 2). Defaults to 2.\n\nNotes:\n **Reusability:**\n This function is designed to be used by the CLI and can be\n exposed as an MCP tool without modification." } } } }