Compare commits
37 Commits
0.0.3
...
6e3939d68c
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e3939d68c | |||
| 658a98cf19 | |||
| 0efe68b052 | |||
| c95de5a6e9 | |||
| b3f3068f8d | |||
| 7d075b3904 | |||
| 28c6d9e964 | |||
| 628c3e97f5 | |||
| 4bf358734a | |||
| f5b3c2bb11 | |||
| 3da419fed5 | |||
| a417563ab5 | |||
| 1940e33bc7 | |||
| 5da0a688a8 | |||
| f1a7a556fd | |||
| 4a7a76e330 | |||
| 083fb6923d | |||
| 69b795f9ca | |||
| 61de233745 | |||
| d912053368 | |||
| 0f591b666b | |||
| 808ffa8fed | |||
| 1e1d7fcde9 | |||
| d4b64d630a | |||
| 85aac955ac | |||
| 8299445b68 | |||
| eb845c5bf4 | |||
| 514f6e5f7c | |||
| 1c48f58578 | |||
| 80f8defcc2 | |||
| f03e250763 | |||
| 37b892f695 | |||
| 14ed19d2d5 | |||
| 6bafa435f1 | |||
| 29c1579f40 | |||
| a3c063b569 | |||
| 72b5be6976 |
22
.drone.yml
22
.drone.yml
@@ -32,6 +32,26 @@ steps:
|
|||||||
echo "🆕 New version detected: $PACKAGE_NAME==$VERSION"
|
echo "🆕 New version detected: $PACKAGE_NAME==$VERSION"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
- name: quality-gate
|
||||||
|
image: python:3.13-slim
|
||||||
|
environment:
|
||||||
|
PIP_REPO_URL:
|
||||||
|
from_secret: PIP_REPO_URL
|
||||||
|
PIP_USERNAME:
|
||||||
|
from_secret: PIP_USERNAME
|
||||||
|
PIP_PASSWORD:
|
||||||
|
from_secret: PIP_PASSWORD
|
||||||
|
commands:
|
||||||
|
- pip install --upgrade pip build
|
||||||
|
- |
|
||||||
|
AUTH_URL="https://${PIP_USERNAME}:${PIP_PASSWORD}@$(echo "${PIP_REPO_URL#*://}" | sed 's:/*$::')/simple"
|
||||||
|
pip install --index-url "$AUTH_URL" --extra-index-url https://pypi.org/simple/ -U ".[dev]"
|
||||||
|
- echo "🛡️ Running quality gate..."
|
||||||
|
- python -m black --check .
|
||||||
|
- python -m ruff check .
|
||||||
|
- python -m mypy
|
||||||
|
- python -m pytest
|
||||||
|
|
||||||
- name: build-package
|
- name: build-package
|
||||||
image: python:3.13-slim
|
image: python:3.13-slim
|
||||||
commands:
|
commands:
|
||||||
@@ -126,4 +146,4 @@ steps:
|
|||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- custom
|
- custom
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -38,3 +38,4 @@ Thumbs.db
|
|||||||
*.swo
|
*.swo
|
||||||
*~
|
*~
|
||||||
*.tmp
|
*.tmp
|
||||||
|
site
|
||||||
|
|||||||
21
CHANGELOG.md
Normal file
21
CHANGELOG.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `py.typed` marker for PEP 561 type information.
|
||||||
|
- `.drone.yml` CI with a quality-gate step (black, ruff, mypy, pytest).
|
||||||
|
- Canonical `docforge.nav.yml`, generated `mkdocs.yml` and `mcp_docs/` via doc-forge.
|
||||||
|
- MIT `LICENSE`.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Standardized `pyproject.toml` (canonical packaging, lint tool config, extras).
|
||||||
|
- `templates/` excluded from black/ruff scans.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Stub fixes for typed API surfaces.
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Aetoskia Platform
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
96
README.md
Normal file
96
README.md
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
# openapi_first
|
||||||
|
|
||||||
|
# Summary
|
||||||
|
|
||||||
|
FastAPI OpenAPI First — strict OpenAPI-first application bootstrap for FastAPI.
|
||||||
|
|
||||||
|
FastAPI OpenAPI First is a **contract-first infrastructure library** that
|
||||||
|
enforces OpenAPI as the single source of truth for FastAPI services.
|
||||||
|
|
||||||
|
The library removes decorator-driven routing and replaces it with
|
||||||
|
deterministic, spec-driven application assembly. Every HTTP route,
|
||||||
|
method, and operation is defined in OpenAPI first and bound to Python
|
||||||
|
handlers explicitly via `operationId`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
|
||||||
|
Install using pip:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install openapi-first
|
||||||
|
```
|
||||||
|
|
||||||
|
Or with Poetry:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
poetry add openapi-first
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Quick Start
|
||||||
|
|
||||||
|
Minimal OpenAPI-first FastAPI application:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_first import app
|
||||||
|
import my_service.routes as routes
|
||||||
|
|
||||||
|
api = app.OpenAPIFirstApp(
|
||||||
|
openapi_path="openapi.yaml",
|
||||||
|
routes_module=routes,
|
||||||
|
title="My Service",
|
||||||
|
version="1.0.0",
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
OperationId-driven HTTP client:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from openapi_first.loader import load_openapi
|
||||||
|
from openapi_first.client import OpenAPIClient
|
||||||
|
|
||||||
|
spec = load_openapi("openapi.yaml")
|
||||||
|
client = OpenAPIClient(spec)
|
||||||
|
|
||||||
|
response = client.get_health()
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Architecture
|
||||||
|
|
||||||
|
The library is structured around four core responsibilities:
|
||||||
|
|
||||||
|
- `loader`: Load and validate OpenAPI 3.x specifications (JSON/YAML).
|
||||||
|
- `binder`: Bind OpenAPI operations to FastAPI routes via `operationId`.
|
||||||
|
- `app`: OpenAPI-first FastAPI application bootstrap.
|
||||||
|
- `client`: OpenAPI-first HTTP client driven by the same specification.
|
||||||
|
- `errors`: Explicit error hierarchy for contract violations.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Public API
|
||||||
|
|
||||||
|
The supported public API consists of the following top-level modules:
|
||||||
|
|
||||||
|
- `openapi_first.app`
|
||||||
|
- `openapi_first.binder`
|
||||||
|
- `openapi_first.loader`
|
||||||
|
- `openapi_first.client`
|
||||||
|
- `openapi_first.errors`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Design Guarantees
|
||||||
|
|
||||||
|
- OpenAPI is the single source of truth.
|
||||||
|
- No undocumented routes can exist.
|
||||||
|
- No OpenAPI operation can exist without a handler or client callable.
|
||||||
|
- All contract violations fail at application startup or client creation.
|
||||||
|
- No hidden FastAPI magic or implicit behavior.
|
||||||
|
- Deterministic, testable application assembly.
|
||||||
|
|
||||||
|
---
|
||||||
13
docforge.nav.yml
Normal file
13
docforge.nav.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
home: lib/index.md
|
||||||
|
groups:
|
||||||
|
Application Bootstrap:
|
||||||
|
- lib/app.md
|
||||||
|
- lib/binder.md
|
||||||
|
Core Utilities:
|
||||||
|
- lib/loader.md
|
||||||
|
- lib/errors.md
|
||||||
|
OpenAPI Client:
|
||||||
|
- lib/client.md
|
||||||
|
icon:
|
||||||
|
logo: material/api
|
||||||
|
repo: fontawesome/brands/github
|
||||||
3
docs/lib/codegen.md
Normal file
3
docs/lib/codegen.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Codegen
|
||||||
|
|
||||||
|
::: openapi_first.codegen
|
||||||
3
docs/lib/codegen_routes.md
Normal file
3
docs/lib/codegen_routes.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Codegen Routes
|
||||||
|
|
||||||
|
::: openapi_first.codegen_routes
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
# Openapi First
|
# openapi_first
|
||||||
|
|
||||||
::: openapi_first
|
::: openapi_first
|
||||||
3
docs/lib/security.md
Normal file
3
docs/lib/security.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Security
|
||||||
|
|
||||||
|
::: openapi_first.security
|
||||||
3
docs/lib/templates/crud_app/data.md
Normal file
3
docs/lib/templates/crud_app/data.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Data
|
||||||
|
|
||||||
|
::: openapi_first.templates.crud_app.data
|
||||||
3
docs/lib/templates/crud_app/index.md
Normal file
3
docs/lib/templates/crud_app/index.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Crud App
|
||||||
|
|
||||||
|
::: openapi_first.templates.crud_app
|
||||||
3
docs/lib/templates/crud_app/main.md
Normal file
3
docs/lib/templates/crud_app/main.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Main
|
||||||
|
|
||||||
|
::: openapi_first.templates.crud_app.main
|
||||||
3
docs/lib/templates/crud_app/routes.md
Normal file
3
docs/lib/templates/crud_app/routes.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Routes
|
||||||
|
|
||||||
|
::: openapi_first.templates.crud_app.routes
|
||||||
3
docs/lib/templates/crud_app/test_crud_app.md
Normal file
3
docs/lib/templates/crud_app/test_crud_app.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Test Crud App
|
||||||
|
|
||||||
|
::: openapi_first.templates.crud_app.test_crud_app
|
||||||
3
docs/lib/templates/health_app/index.md
Normal file
3
docs/lib/templates/health_app/index.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Health App
|
||||||
|
|
||||||
|
::: openapi_first.templates.health_app
|
||||||
3
docs/lib/templates/health_app/main.md
Normal file
3
docs/lib/templates/health_app/main.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Main
|
||||||
|
|
||||||
|
::: openapi_first.templates.health_app.main
|
||||||
3
docs/lib/templates/health_app/routes.md
Normal file
3
docs/lib/templates/health_app/routes.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Routes
|
||||||
|
|
||||||
|
::: openapi_first.templates.health_app.routes
|
||||||
3
docs/lib/templates/index.md
Normal file
3
docs/lib/templates/index.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Templates
|
||||||
|
|
||||||
|
::: openapi_first.templates
|
||||||
3
docs/lib/templates/model_app/data.md
Normal file
3
docs/lib/templates/model_app/data.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Data
|
||||||
|
|
||||||
|
::: openapi_first.templates.model_app.data
|
||||||
3
docs/lib/templates/model_app/index.md
Normal file
3
docs/lib/templates/model_app/index.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Model App
|
||||||
|
|
||||||
|
::: openapi_first.templates.model_app
|
||||||
3
docs/lib/templates/model_app/main.md
Normal file
3
docs/lib/templates/model_app/main.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Main
|
||||||
|
|
||||||
|
::: openapi_first.templates.model_app.main
|
||||||
3
docs/lib/templates/model_app/models.md
Normal file
3
docs/lib/templates/model_app/models.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Models
|
||||||
|
|
||||||
|
::: openapi_first.templates.model_app.models
|
||||||
3
docs/lib/templates/model_app/routes.md
Normal file
3
docs/lib/templates/model_app/routes.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Routes
|
||||||
|
|
||||||
|
::: openapi_first.templates.model_app.routes
|
||||||
3
docs/lib/templates/model_app/test_model_app.md
Normal file
3
docs/lib/templates/model_app/test_model_app.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Test Model App
|
||||||
|
|
||||||
|
::: openapi_first.templates.model_app.test_model_app
|
||||||
3
docs/lib/templates/vet_app/data.md
Normal file
3
docs/lib/templates/vet_app/data.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Data
|
||||||
|
|
||||||
|
::: openapi_first.templates.vet_app.data
|
||||||
3
docs/lib/templates/vet_app/index.md
Normal file
3
docs/lib/templates/vet_app/index.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Vet App
|
||||||
|
|
||||||
|
::: openapi_first.templates.vet_app
|
||||||
3
docs/lib/templates/vet_app/main.md
Normal file
3
docs/lib/templates/vet_app/main.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Main
|
||||||
|
|
||||||
|
::: openapi_first.templates.vet_app.main
|
||||||
3
docs/lib/templates/vet_app/models.md
Normal file
3
docs/lib/templates/vet_app/models.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Models
|
||||||
|
|
||||||
|
::: openapi_first.templates.vet_app.models
|
||||||
3
docs/lib/templates/vet_app/routes.md
Normal file
3
docs/lib/templates/vet_app/routes.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Routes
|
||||||
|
|
||||||
|
::: openapi_first.templates.vet_app.routes
|
||||||
3
docs/lib/templates/vet_app/sse.md
Normal file
3
docs/lib/templates/vet_app/sse.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Sse
|
||||||
|
|
||||||
|
::: openapi_first.templates.vet_app.sse
|
||||||
3
docs/lib/templates/vet_app/test_vet_app.md
Normal file
3
docs/lib/templates/vet_app/test_vet_app.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Test Vet App
|
||||||
|
|
||||||
|
::: openapi_first.templates.vet_app.test_vet_app
|
||||||
6
docs/mcp/index.json
Normal file
6
docs/mcp/index.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"project": "openapi_first",
|
||||||
|
"type": "docforge-model",
|
||||||
|
"modules_count": 32,
|
||||||
|
"source": "docforge"
|
||||||
|
}
|
||||||
81
docs/mcp/modules/openapi_first.app.json
Normal file
81
docs/mcp/modules/openapi_first.app.json
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.app",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.app",
|
||||||
|
"docstring": "# Summary\n\nOpenAPI-first application bootstrap for FastAPI.\n\nThis module provides `OpenAPIFirstApp`, a thin but strict abstraction\nthat enforces OpenAPI as the single source of truth for a FastAPI service.\n\nNotes:\n **Core Principles:**\n\n - The OpenAPI specification (JSON or YAML) defines the entire API surface.\n - Every `operationId` in the OpenAPI spec must have a corresponding\n Python handler function.\n - Handlers are plain Python callables (no FastAPI decorators).\n - FastAPI route registration is derived exclusively from the spec.\n - FastAPI's autogenerated OpenAPI schema is fully overridden.\n\n **Responsibilities:**\n\n - Loads and validates an OpenAPI 3.x specification.\n - Dynamically binds HTTP routes to handler functions using `operationId`.\n - Registers routes with FastAPI at application startup.\n - Ensures runtime behavior matches the OpenAPI contract exactly.\n\n **Constraints:**\n\n - This module intentionally does NOT:\n - Generate OpenAPI specs.\n - Generate client code.\n - Introduce a new framework or lifecycle.\n - Alter FastAPI dependency injection semantics.",
|
||||||
|
"objects": {
|
||||||
|
"os": {
|
||||||
|
"name": "os",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.app.os",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('os', 'os')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"re": {
|
||||||
|
"name": "re",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.app.re",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('re', 're')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"FastAPI": {
|
||||||
|
"name": "FastAPI",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.app.FastAPI",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('FastAPI', 'fastapi.FastAPI')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"bind_routes": {
|
||||||
|
"name": "bind_routes",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.app.bind_routes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('bind_routes', 'openapi_first.binder.bind_routes')>",
|
||||||
|
"docstring": "Bind OpenAPI operations to FastAPI routes.\n\nArgs:\n app (fastapi.FastAPI):\n The FastAPI application instance to which routes will be added.\n spec (dict):\n Parsed OpenAPI 3.x specification dictionary.\n routes_module (module):\n Python module containing handler functions. Each handler's name MUST\n exactly match an OpenAPI `operationId`.\n security_deps (dict | None):\n Optional mapping of ``METHOD:/path`` → ``list[Depends(...)]``\n generated from the spec's ``securitySchemes`` and per-operation\n ``security`` fields.\n\nRaises:\n MissingOperationHandler:\n If an ``operationId`` is missing from the spec or if no corresponding\n handler function exists in the routes module.\n\nNotes:\n **Responsibilities:**\n\n - Iterates through the OpenAPI specification paths and methods.\n - Resolves each ``operationId`` to a handler function, and registers\n a corresponding ``APIRoute`` on the FastAPI application.\n - Injects FastAPI ``Depends()`` for each security requirement found\n on the operation or inherited from the top-level ``security`` field.\n\n **Guarantees:**\n\n - Route registration is deterministic and spec-driven. No route\n decorators are required or supported. Handler resolution errors\n surface at application startup."
|
||||||
|
},
|
||||||
|
"load_openapi": {
|
||||||
|
"name": "load_openapi",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.app.load_openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported\n extensions: `.json`, `.yaml`, `.yml`.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI\n schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated\n using a strict OpenAPI schema validator.\n - Any error results in an immediate exception, preventing\n application startup."
|
||||||
|
},
|
||||||
|
"make_security_dependencies": {
|
||||||
|
"name": "make_security_dependencies",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.app.make_security_dependencies",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('make_security_dependencies', 'openapi_first.security.make_security_dependencies')>",
|
||||||
|
"docstring": "Build a mapping of ``METHOD:/path`` → list of ``Depends(...)``.\n\nThe effective security for each operation is resolved by:\n\n1. Using the operation-level ``security`` field if present.\n2. Falling back to the top-level ``security`` field.\n3. An empty list means *no auth required* for that operation."
|
||||||
|
},
|
||||||
|
"parse_security_schemes": {
|
||||||
|
"name": "parse_security_schemes",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.app.parse_security_schemes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('parse_security_schemes', 'openapi_first.security.parse_security_schemes')>",
|
||||||
|
"docstring": "Extract and resolve environment variables in security schemes."
|
||||||
|
},
|
||||||
|
"OpenAPIFirstApp": {
|
||||||
|
"name": "OpenAPIFirstApp",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.app.OpenAPIFirstApp",
|
||||||
|
"signature": "<bound method Class.signature of Class('OpenAPIFirstApp', 67, 150)>",
|
||||||
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses `FastAPI` and replaces manual route\n registration with OpenAPI-driven binding.\n - All routes are derived from the provided OpenAPI specification,\n and each ``operationId`` is mapped to a Python function in the\n supplied routes module.\n - Auth dependencies are auto-injected from the spec's\n ``securitySchemes`` and per-operation ``security`` fields.\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration.\n - No OpenAPI operation can exist without a handler.\n - Swagger UI and ``/openapi.json`` always reflect the provided spec.\n - Handler functions remain framework-agnostic and testable.\n - Auth enforcement is driven entirely by the spec — no manual\n middleware or decorators required.\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
|
"members": {
|
||||||
|
"openapi": {
|
||||||
|
"name": "openapi",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.app.OpenAPIFirstApp.openapi",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Any": {
|
||||||
|
"name": "Any",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.app.Any",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Any', 'typing.Any')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
docs/mcp/modules/openapi_first.binder.json
Normal file
44
docs/mcp/modules/openapi_first.binder.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.binder",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.binder",
|
||||||
|
"docstring": "# Summary\n\nOpenAPI-driven route binding for FastAPI.\n\nThis module is responsible for translating an OpenAPI 3.x specification\ninto concrete FastAPI routes. It enforces a strict one-to-one mapping\nbetween OpenAPI operations and Python handler functions using `operationId`.\n\nNotes:\n **Core Responsibility:**\n\n - Read path + method definitions from an OpenAPI specification.\n - Resolve each `operationId` to a Python callable.\n - Register routes with FastAPI using `APIRoute`.\n - Fail fast when contract violations are detected.\n\n **Design Constraints:**\n\n - All routes MUST be declared in the OpenAPI specification.\n - All OpenAPI operations MUST define an `operationId`.\n - Every `operationId` MUST resolve to a handler function.\n - Handlers are plain Python callables (no decorators required).\n - No implicit route creation or inference is allowed.\n\n **Constraints:**\n\n - This module intentionally does NOT:\n - Perform request or response validation.\n - Generate Pydantic models.\n - Modify FastAPI dependency injection.\n - Interpret OpenAPI semantics beyond routing metadata.",
|
||||||
|
"objects": {
|
||||||
|
"Any": {
|
||||||
|
"name": "Any",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.binder.Any",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Any', 'typing.Any')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"APIRoute": {
|
||||||
|
"name": "APIRoute",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.binder.APIRoute",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('APIRoute', 'fastapi.routing.APIRoute')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"MissingOperationHandler": {
|
||||||
|
"name": "MissingOperationHandler",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.binder.MissingOperationHandler",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('MissingOperationHandler', 'openapi_first.errors.MissingOperationHandler')>",
|
||||||
|
"docstring": "Raised when an OpenAPI operation cannot be resolved to a handler.\n\nNotes:\n **Scenarios:**\n\n - An OpenAPI operation does not define an `operationId`.\n - An `operationId` is defined but no matching function exists in\n the provided routes module.\n\n **Guarantees:**\n\n - This represents a violation of the OpenAPI-first contract and\n indicates that the specification and implementation are out of\n sync."
|
||||||
|
},
|
||||||
|
"bind_routes": {
|
||||||
|
"name": "bind_routes",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.binder.bind_routes",
|
||||||
|
"signature": "<bound method Function.signature of Function('bind_routes', 42, 124)>",
|
||||||
|
"docstring": "Bind OpenAPI operations to FastAPI routes.\n\nArgs:\n app (fastapi.FastAPI):\n The FastAPI application instance to which routes will be added.\n spec (dict):\n Parsed OpenAPI 3.x specification dictionary.\n routes_module (module):\n Python module containing handler functions. Each handler's name MUST\n exactly match an OpenAPI `operationId`.\n security_deps (dict | None):\n Optional mapping of ``METHOD:/path`` → ``list[Depends(...)]``\n generated from the spec's ``securitySchemes`` and per-operation\n ``security`` fields.\n\nRaises:\n MissingOperationHandler:\n If an ``operationId`` is missing from the spec or if no corresponding\n handler function exists in the routes module.\n\nNotes:\n **Responsibilities:**\n\n - Iterates through the OpenAPI specification paths and methods.\n - Resolves each ``operationId`` to a handler function, and registers\n a corresponding ``APIRoute`` on the FastAPI application.\n - Injects FastAPI ``Depends()`` for each security requirement found\n on the operation or inherited from the top-level ``security`` field.\n\n **Guarantees:**\n\n - Route registration is deterministic and spec-driven. No route\n decorators are required or supported. Handler resolution errors\n surface at application startup."
|
||||||
|
},
|
||||||
|
"FastAPI": {
|
||||||
|
"name": "FastAPI",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.binder.FastAPI",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('FastAPI', 'fastapi.FastAPI')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
docs/mcp/modules/openapi_first.cli.json
Normal file
65
docs/mcp/modules/openapi_first.cli.json
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.cli",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.cli",
|
||||||
|
"docstring": "Command-line interface for FastAPI OpenAPI-first scaffolding utilities.\n\n---\n\n## Summary\n\nThis CLI bootstraps OpenAPI-first FastAPI applications from versioned,\nbundled templates packaged with the library.",
|
||||||
|
"objects": {
|
||||||
|
"argparse": {
|
||||||
|
"name": "argparse",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.cli.argparse",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('argparse', 'argparse')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"shutil": {
|
||||||
|
"name": "shutil",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.cli.shutil",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('shutil', 'shutil')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"resources": {
|
||||||
|
"name": "resources",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.cli.resources",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('resources', 'importlib.resources')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Path": {
|
||||||
|
"name": "Path",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.cli.Path",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Path', 'pathlib.Path')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"DEFAULT_TEMPLATE": {
|
||||||
|
"name": "DEFAULT_TEMPLATE",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.cli.DEFAULT_TEMPLATE",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"available_templates": {
|
||||||
|
"name": "available_templates",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.cli.available_templates",
|
||||||
|
"signature": "<bound method Function.signature of Function('available_templates', 20, 33)>",
|
||||||
|
"docstring": "Return a list of available application templates.\n\nReturns:\n list[str]:\n Sorted list of template names found in the internal templates directory."
|
||||||
|
},
|
||||||
|
"copy_template": {
|
||||||
|
"name": "copy_template",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.cli.copy_template",
|
||||||
|
"signature": "<bound method Function.signature of Function('copy_template', 36, 64)>",
|
||||||
|
"docstring": "Copy a bundled OpenAPI-first application template into a directory.\n\nArgs:\n template (str):\n Name of the template to copy.\n target_dir (Path):\n Filesystem path where the template should be copied.\n\nRaises:\n FileNotFoundError:\n If the requested template does not exist."
|
||||||
|
},
|
||||||
|
"main": {
|
||||||
|
"name": "main",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.cli.main",
|
||||||
|
"signature": "<bound method Function.signature of Function('main', 67, 196)>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
88
docs/mcp/modules/openapi_first.client.json
Normal file
88
docs/mcp/modules/openapi_first.client.json
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.client",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.client",
|
||||||
|
"docstring": "# Summary\n\nOpenAPI-first HTTP client for contract-driven services.\n\nThis module provides `OpenAPIClient`, a thin, strict HTTP client that\nderives all callable operations directly from an OpenAPI 3.x specification.\n\nIt is the client counterpart to `OpenAPIFirstApp`.\n\nNotes:\n **Core Principles:**\n\n - The OpenAPI specification is the single source of truth\n - Each operationId becomes a callable Python method\n - No implicit schema mutation or inference\n - No code generation step\n - Minimal abstraction over httpx\n\n **Responsibilities:**\n\n - Parses an OpenAPI 3.x specification\n - Dynamically creates one callable per operationId\n - Enforces presence of servers, paths, and operationId\n - Formats path parameters safely\n - Handles JSON request bodies explicitly\n - Returns raw `httpx.Response` objects\n\n **Constraints:**\n\n - This module intentionally does NOT: Generate client code, validate request/response schemas, deserialize responses, retry requests, implement authentication helpers, or assume non-2xx responses are failures.",
|
||||||
|
"objects": {
|
||||||
|
"Callable": {
|
||||||
|
"name": "Callable",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.client.Callable",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Callable', 'collections.abc.Callable')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Any": {
|
||||||
|
"name": "Any",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.client.Any",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Any', 'typing.Any')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"urljoin": {
|
||||||
|
"name": "urljoin",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.client.urljoin",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('urljoin', 'urllib.parse.urljoin')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"httpx": {
|
||||||
|
"name": "httpx",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.client.httpx",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('httpx', 'httpx')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"OpenAPIFirstError": {
|
||||||
|
"name": "OpenAPIFirstError",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.client.OpenAPIFirstError",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstError', 'openapi_first.errors.OpenAPIFirstError')>",
|
||||||
|
"docstring": "Base exception for all OpenAPI-first enforcement errors.\n\nNotes:\n **Responsibilities:**\n\n - This exception exists to allow callers, test suites, and CI\n pipelines to catch and distinguish OpenAPI contract violations\n from unrelated runtime errors.\n - All exceptions raised by the OpenAPI-first core should inherit\n from this type."
|
||||||
|
},
|
||||||
|
"OpenAPIClientError": {
|
||||||
|
"name": "OpenAPIClientError",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.client.OpenAPIClientError",
|
||||||
|
"signature": "<bound method Class.signature of Class('OpenAPIClientError', 43, 46)>",
|
||||||
|
"docstring": "Raised when an OpenAPI client operation fails."
|
||||||
|
},
|
||||||
|
"OpenAPIClient": {
|
||||||
|
"name": "OpenAPIClient",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.client.OpenAPIClient",
|
||||||
|
"signature": "<bound method Class.signature of Class('OpenAPIClient', 49, 262)>",
|
||||||
|
"docstring": "OpenAPI-first HTTP client (`httpx`-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an\n OpenAPI 3.x specification. Each `operationId` becomes a method\n on the client instance.\n\n **Guarantees:**\n\n - One callable per `operationId`.\n - Explicit parameters (path, query, headers, body).\n - No implicit schema inference or mutation.\n - Returns raw `httpx.Response` objects.\n - No response validation or deserialization.\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
|
"members": {
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.client.OpenAPIClient.spec",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"base_url": {
|
||||||
|
"name": "base_url",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.client.OpenAPIClient.base_url",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.client.OpenAPIClient.client",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"operations": {
|
||||||
|
"name": "operations",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.client.OpenAPIClient.operations",
|
||||||
|
"signature": "<bound method Function.signature of Function('operations', 127, 128)>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
docs/mcp/modules/openapi_first.codegen.json
Normal file
51
docs/mcp/modules/openapi_first.codegen.json
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"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": "<bound method Alias.signature of Alias('Path', 'pathlib.Path')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"InputFileType": {
|
||||||
|
"name": "InputFileType",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.codegen.InputFileType",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('InputFileType', 'datamodel_code_generator.InputFileType')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"PythonVersion": {
|
||||||
|
"name": "PythonVersion",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.codegen.PythonVersion",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('PythonVersion', 'datamodel_code_generator.PythonVersion')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"generate": {
|
||||||
|
"name": "generate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.codegen.generate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('generate', 'datamodel_code_generator.generate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"generate_routes": {
|
||||||
|
"name": "generate_routes",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.codegen.generate_routes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('generate_routes', 'openapi_first.codegen_routes.generate_routes')>",
|
||||||
|
"docstring": "Generate route handler stubs from an OpenAPI specification.\n\nCreates one ``<resource>.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:\n Path to the OpenAPI specification file (YAML or JSON).\n output_dir:\n Directory where the generated route files are written.\n Created automatically if it does not exist.\n use_models:\n If ``True``, import Pydantic models from *models_module*\n for request-body schemas referenced via ``$ref``.\n models_module:\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": "<bound method Function.signature of Function('generate_models', 22, 51)>",
|
||||||
|
"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."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
docs/mcp/modules/openapi_first.codegen_routes.json
Normal file
37
docs/mcp/modules/openapi_first.codegen_routes.json
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.codegen_routes",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.codegen_routes",
|
||||||
|
"docstring": "Route handler code generation from OpenAPI specifications.\n\nThis module generates Python route handler stubs from an OpenAPI 3.x\nspecification. Each resource (derived from the first path segment)\ngets its own file under the output directory. Every OpenAPI operation\nmust define an ``operationId``, which becomes the handler function name.\n\nNotes:\n **Design constraints:**\n\n - ``operationId`` is required on every operation (matching\n ``binder.bind_routes``).\n - Handlers are stubs raising ``NotImplementedError``.\n - Sub-resources (e.g. ``/pets/{id}/photo``) are grouped with their\n parent resource (``pets``).\n - Parameter types and defaults are inferred from the spec.\n - ``response: Response`` is injected for non-200 success codes.",
|
||||||
|
"objects": {
|
||||||
|
"Path": {
|
||||||
|
"name": "Path",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.codegen_routes.Path",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Path', 'pathlib.Path')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Any": {
|
||||||
|
"name": "Any",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.codegen_routes.Any",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Any', 'typing.Any')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"load_openapi": {
|
||||||
|
"name": "load_openapi",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.codegen_routes.load_openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported\n extensions: `.json`, `.yaml`, `.yml`.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI\n schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated\n using a strict OpenAPI schema validator.\n - Any error results in an immediate exception, preventing\n application startup."
|
||||||
|
},
|
||||||
|
"generate_routes": {
|
||||||
|
"name": "generate_routes",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.codegen_routes.generate_routes",
|
||||||
|
"signature": "<bound method Function.signature of Function('generate_routes', 27, 102)>",
|
||||||
|
"docstring": "Generate route handler stubs from an OpenAPI specification.\n\nCreates one ``<resource>.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:\n Path to the OpenAPI specification file (YAML or JSON).\n output_dir:\n Directory where the generated route files are written.\n Created automatically if it does not exist.\n use_models:\n If ``True``, import Pydantic models from *models_module*\n for request-body schemas referenced via ``$ref``.\n models_module:\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``."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
docs/mcp/modules/openapi_first.errors.json
Normal file
23
docs/mcp/modules/openapi_first.errors.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.errors",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.errors",
|
||||||
|
"docstring": "# Summary\n\nExceptions for OpenAPI-first FastAPI applications.\n\nThis module defines a small hierarchy of explicit, intention-revealing\nexceptions used to signal contract violations between an OpenAPI\nspecification and its Python implementation.\n\nNotes:\n **Design Principles:**\n\n - Errors represent programmer mistakes, not runtime conditions.\n - All errors are raised during application startup.\n - Messages are actionable and suitable for CI/CD output.\n - Exceptions are explicit rather than reused from generic built-ins.\n\n These errors should normally cause immediate application failure.",
|
||||||
|
"objects": {
|
||||||
|
"OpenAPIFirstError": {
|
||||||
|
"name": "OpenAPIFirstError",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.errors.OpenAPIFirstError",
|
||||||
|
"signature": "<bound method Class.signature of Class('OpenAPIFirstError', 22, 36)>",
|
||||||
|
"docstring": "Base exception for all OpenAPI-first enforcement errors.\n\nNotes:\n **Responsibilities:**\n\n - This exception exists to allow callers, test suites, and CI\n pipelines to catch and distinguish OpenAPI contract violations\n from unrelated runtime errors.\n - All exceptions raised by the OpenAPI-first core should inherit\n from this type."
|
||||||
|
},
|
||||||
|
"MissingOperationHandler": {
|
||||||
|
"name": "MissingOperationHandler",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.errors.MissingOperationHandler",
|
||||||
|
"signature": "<bound method Class.signature of Class('MissingOperationHandler', 39, 77)>",
|
||||||
|
"docstring": "Raised when an OpenAPI operation cannot be resolved to a handler.\n\nNotes:\n **Scenarios:**\n\n - An OpenAPI operation does not define an `operationId`.\n - An `operationId` is defined but no matching function exists in\n the provided routes module.\n\n **Guarantees:**\n\n - This represents a violation of the OpenAPI-first contract and\n indicates that the specification and implementation are out of\n sync."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2830
docs/mcp/modules/openapi_first.json
Normal file
2830
docs/mcp/modules/openapi_first.json
Normal file
File diff suppressed because it is too large
Load Diff
65
docs/mcp/modules/openapi_first.loader.json
Normal file
65
docs/mcp/modules/openapi_first.loader.json
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.loader",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.loader",
|
||||||
|
"docstring": "# Summary\n\nOpenAPI specification loading and validation utilities.\n\nThis module is responsible for loading an OpenAPI 3.x specification\nfrom disk and validating it before it is used by the application.\n\nIt enforces the principle that an invalid or malformed OpenAPI document\nmust never reach the routing or runtime layers.\n\nNotes:\n **Design Principles:**\n\n - OpenAPI is treated as an authoritative contract.\n - Invalid specifications fail fast at application startup.\n - Supported formats are JSON and YAML.\n - Validation errors are surfaced clearly and early.\n\n **Constraints:**\n\n - This module intentionally does NOT:\n - Modify the OpenAPI document.\n - Infer missing fields.\n - Generate models or code.\n - Perform request/response validation at runtime.",
|
||||||
|
"objects": {
|
||||||
|
"json": {
|
||||||
|
"name": "json",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.loader.json",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('json', 'json')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Path": {
|
||||||
|
"name": "Path",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.loader.Path",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Path', 'pathlib.Path')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Any": {
|
||||||
|
"name": "Any",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.loader.Any",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Any', 'typing.Any')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"yaml": {
|
||||||
|
"name": "yaml",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.loader.yaml",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('yaml', 'yaml')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"validate_spec": {
|
||||||
|
"name": "validate_spec",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.loader.validate_spec",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('validate_spec', 'openapi_spec_validator.validate_spec')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"OpenAPIFirstError": {
|
||||||
|
"name": "OpenAPIFirstError",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.loader.OpenAPIFirstError",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstError', 'openapi_first.errors.OpenAPIFirstError')>",
|
||||||
|
"docstring": "Base exception for all OpenAPI-first enforcement errors.\n\nNotes:\n **Responsibilities:**\n\n - This exception exists to allow callers, test suites, and CI\n pipelines to catch and distinguish OpenAPI contract violations\n from unrelated runtime errors.\n - All exceptions raised by the OpenAPI-first core should inherit\n from this type."
|
||||||
|
},
|
||||||
|
"OpenAPISpecLoadError": {
|
||||||
|
"name": "OpenAPISpecLoadError",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.loader.OpenAPISpecLoadError",
|
||||||
|
"signature": "<bound method Class.signature of Class('OpenAPISpecLoadError', 39, 50)>",
|
||||||
|
"docstring": "Raised when an OpenAPI specification cannot be loaded or validated.\n\nNotes:\n **Guarantees:**\n\n - This error indicates that the OpenAPI document is unreadable,\n malformed, or violates the OpenAPI 3.x specification."
|
||||||
|
},
|
||||||
|
"load_openapi": {
|
||||||
|
"name": "load_openapi",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.loader.load_openapi",
|
||||||
|
"signature": "<bound method Function.signature of Function('load_openapi', 53, 110)>",
|
||||||
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported\n extensions: `.json`, `.yaml`, `.yml`.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI\n schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated\n using a strict OpenAPI schema validator.\n - Any error results in an immediate exception, preventing\n application startup."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
93
docs/mcp/modules/openapi_first.security.json
Normal file
93
docs/mcp/modules/openapi_first.security.json
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.security",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.security",
|
||||||
|
"docstring": "OpenAPI security scheme parsing and auto-generated auth dependencies.\n\nReads `securitySchemes` and per-operation `security` from an OpenAPI spec,\nresolves `{ENV_VAR}` placeholders in `x-` extension fields, and generates\nFastAPI dependencies for token validation (e.g., Bearer JWT introspection).",
|
||||||
|
"objects": {
|
||||||
|
"os": {
|
||||||
|
"name": "os",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.os",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('os', 'os')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"re": {
|
||||||
|
"name": "re",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.re",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('re', 're')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Callable": {
|
||||||
|
"name": "Callable",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.Callable",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Callable', 'collections.abc.Callable')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Any": {
|
||||||
|
"name": "Any",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.Any",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Any', 'typing.Any')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"httpx": {
|
||||||
|
"name": "httpx",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.httpx",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('httpx', 'httpx')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Depends": {
|
||||||
|
"name": "Depends",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.Depends",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Depends', 'fastapi.Depends')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"HTTPException": {
|
||||||
|
"name": "HTTPException",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.HTTPException",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('HTTPException', 'fastapi.HTTPException')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Request": {
|
||||||
|
"name": "Request",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.Request",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Request', 'fastapi.Request')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"HTTPAuthorizationCredentials": {
|
||||||
|
"name": "HTTPAuthorizationCredentials",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.HTTPAuthorizationCredentials",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('HTTPAuthorizationCredentials', 'fastapi.security.HTTPAuthorizationCredentials')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"HTTPBearer": {
|
||||||
|
"name": "HTTPBearer",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.security.HTTPBearer",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('HTTPBearer', 'fastapi.security.HTTPBearer')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"parse_security_schemes": {
|
||||||
|
"name": "parse_security_schemes",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.security.parse_security_schemes",
|
||||||
|
"signature": "<bound method Function.signature of Function('parse_security_schemes', 43, 46)>",
|
||||||
|
"docstring": "Extract and resolve environment variables in security schemes."
|
||||||
|
},
|
||||||
|
"make_security_dependencies": {
|
||||||
|
"name": "make_security_dependencies",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.security.make_security_dependencies",
|
||||||
|
"signature": "<bound method Function.signature of Function('make_security_dependencies', 113, 150)>",
|
||||||
|
"docstring": "Build a mapping of ``METHOD:/path`` → list of ``Depends(...)``.\n\nThe effective security for each operation is resolved by:\n\n1. Using the operation-level ``security`` field if present.\n2. Falling back to the top-level ``security`` field.\n3. An empty list means *no auth required* for that operation."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
docs/mcp/modules/openapi_first.templates.crud_app.data.json
Normal file
51
docs/mcp/modules/openapi_first.templates.crud_app.data.json
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app.data",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.crud_app.data",
|
||||||
|
"docstring": "In-memory mock data store for CRUD example.\n\nThis module intentionally avoids persistence and concurrency guarantees.\nIt is suitable for demos, tests, and scaffolding only.\n\nIt intentionally avoids\n- persistence\n- concurrency guarantees\n- validation\n- error handling\n\nThe implementation is suitable for:\n- demonstrations\n- tests\n- scaffolding and example services\n\nIt is explicitly NOT suitable for production use.\n\nThis module is not part of the ``openapi_first`` library API surface.",
|
||||||
|
"objects": {
|
||||||
|
"Dict": {
|
||||||
|
"name": "Dict",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.Dict",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Dict', 'typing.Dict')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_items": {
|
||||||
|
"name": "list_items",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.list_items",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_items', 36, 48)>",
|
||||||
|
"docstring": "Return all items in the data store.\n\nThis function performs no filtering, pagination, or sorting.\nThe returned collection reflects the current in-memory state.\n\nReturns\n-------\nlist[dict]\n A list of item representations."
|
||||||
|
},
|
||||||
|
"get_item": {
|
||||||
|
"name": "get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_item', 51, 68)>",
|
||||||
|
"docstring": "Retrieve a single item by ID.\n\nThis function assumes the item exists and will raise ``KeyError``\nif the ID is not present in the store.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to retrieve.\n\nReturns\n-------\ndict\n The stored item representation."
|
||||||
|
},
|
||||||
|
"create_item": {
|
||||||
|
"name": "create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_item', 71, 92)>",
|
||||||
|
"docstring": "Create a new item in the data store.\n\nA new integer ID is assigned automatically. No validation is\nperformed on the provided payload.\n\nParameters\n----------\npayload : dict\n Item attributes excluding the ``id`` field.\n\nReturns\n-------\ndict\n The newly created item, including its assigned ID."
|
||||||
|
},
|
||||||
|
"update_item": {
|
||||||
|
"name": "update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_item', 95, 117)>",
|
||||||
|
"docstring": "Replace an existing item in the data store.\n\nThis function overwrites the existing item entirely and does not\nperform partial updates or validation. If the item does not exist,\nit will be created implicitly.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to update.\npayload : dict\n Item attributes excluding the ``id`` field.\n\nReturns\n-------\ndict\n The updated item representation."
|
||||||
|
},
|
||||||
|
"delete_item": {
|
||||||
|
"name": "delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_item', 120, 132)>",
|
||||||
|
"docstring": "Remove an item from the data store.\n\nThis function assumes the item exists and will raise ``KeyError``\nif the ID is not present.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to delete."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
273
docs/mcp/modules/openapi_first.templates.crud_app.json
Normal file
273
docs/mcp/modules/openapi_first.templates.crud_app.json
Normal file
@@ -0,0 +1,273 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.crud_app",
|
||||||
|
"docstring": "OpenAPI-first CRUD application template.\n\nThis package contains a complete, minimal example of an OpenAPI-first\nCRUD service built using the ``openapi_first`` library.\n\nThe application is assembled exclusively from:\n- an OpenAPI specification (``openapi.yaml``)\n- a handler namespace implementing CRUD operations (``routes``)\n- an in-memory mock data store (``data``)\n\nAll HTTP routes, methods, schemas, and operation bindings are defined\nin the OpenAPI specification and enforced at application startup.\nNo decorator-driven routing or implicit framework behavior is used.\n\nThis template demonstrates:\n- operationId-driven server-side route binding\n- explicit HTTP status code control in handlers\n- operationId-driven client usage against the same OpenAPI contract\n- end-to-end validation using in-memory data and tests\n\n----------------------------------------------------------------------\nScaffolding via CLI\n----------------------------------------------------------------------\n\nCreate a new CRUD example service using the bundled template:\n\n openapi-first crud_app\n\nCreate the service in a custom directory:\n\n openapi-first crud_app my-crud-service\n\nList all available application templates:\n\n openapi-first --list\n\nThe CLI copies template files verbatim into the target directory.\nNo code is generated or modified beyond the copied scaffold.\n\n----------------------------------------------------------------------\nClient Usage Example\n----------------------------------------------------------------------\n\nThe same OpenAPI specification used by the server can be used to\nconstruct a strict, operationId-driven HTTP client.\n\nExample client calls for CRUD operations:\n\n from openapi_first.loader import load_openapi\n from openapi_first.client import OpenAPIClient\n\n spec = load_openapi(\"openapi.yaml\")\n client = OpenAPIClient(spec)\n\n # List items\n response = client.list_items()\n\n # Get item by ID\n response = client.get_item(\n path_params={\"item_id\": 1}\n )\n\n # Create item\n response = client.create_item(\n body={\"name\": \"Orange\", \"price\": 0.8}\n )\n\n # Update item\n response = client.update_item(\n path_params={\"item_id\": 1},\n body={\"name\": \"Green Apple\", \"price\": 0.6},\n )\n\n # Delete item\n response = client.delete_item(\n path_params={\"item_id\": 1}\n )\n\nClient guarantees:\n- One callable per OpenAPI ``operationId``\n- No hardcoded URLs or HTTP methods in user code\n- Path and request parameters must match the OpenAPI specification\n- Invalid or incomplete OpenAPI specs fail at client construction time\n\n----------------------------------------------------------------------\nNon-Goals\n----------------------------------------------------------------------\n\nThis template is intentionally minimal and is NOT:\n- production-ready\n- persistent or concurrency-safe\n- a reference architecture for data storage\n\nIt exists solely as a copyable example for learning, testing, and\nbootstrapping OpenAPI-first services.\n\nThis package is not part of the ``openapi_first`` library API surface.",
|
||||||
|
"objects": {
|
||||||
|
"data": {
|
||||||
|
"name": "data",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.crud_app.data",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "In-memory mock data store for CRUD example.\n\nThis module intentionally avoids persistence and concurrency guarantees.\nIt is suitable for demos, tests, and scaffolding only.\n\nIt intentionally avoids\n- persistence\n- concurrency guarantees\n- validation\n- error handling\n\nThe implementation is suitable for:\n- demonstrations\n- tests\n- scaffolding and example services\n\nIt is explicitly NOT suitable for production use.\n\nThis module is not part of the ``openapi_first`` library API surface.",
|
||||||
|
"members": {
|
||||||
|
"Dict": {
|
||||||
|
"name": "Dict",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.Dict",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Dict', 'typing.Dict')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_items": {
|
||||||
|
"name": "list_items",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.list_items",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_items', 36, 48)>",
|
||||||
|
"docstring": "Return all items in the data store.\n\nThis function performs no filtering, pagination, or sorting.\nThe returned collection reflects the current in-memory state.\n\nReturns\n-------\nlist[dict]\n A list of item representations."
|
||||||
|
},
|
||||||
|
"get_item": {
|
||||||
|
"name": "get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_item', 51, 68)>",
|
||||||
|
"docstring": "Retrieve a single item by ID.\n\nThis function assumes the item exists and will raise ``KeyError``\nif the ID is not present in the store.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to retrieve.\n\nReturns\n-------\ndict\n The stored item representation."
|
||||||
|
},
|
||||||
|
"create_item": {
|
||||||
|
"name": "create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_item', 71, 92)>",
|
||||||
|
"docstring": "Create a new item in the data store.\n\nA new integer ID is assigned automatically. No validation is\nperformed on the provided payload.\n\nParameters\n----------\npayload : dict\n Item attributes excluding the ``id`` field.\n\nReturns\n-------\ndict\n The newly created item, including its assigned ID."
|
||||||
|
},
|
||||||
|
"update_item": {
|
||||||
|
"name": "update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_item', 95, 117)>",
|
||||||
|
"docstring": "Replace an existing item in the data store.\n\nThis function overwrites the existing item entirely and does not\nperform partial updates or validation. If the item does not exist,\nit will be created implicitly.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to update.\npayload : dict\n Item attributes excluding the ``id`` field.\n\nReturns\n-------\ndict\n The updated item representation."
|
||||||
|
},
|
||||||
|
"delete_item": {
|
||||||
|
"name": "delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.data.delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_item', 120, 132)>",
|
||||||
|
"docstring": "Remove an item from the data store.\n\nThis function assumes the item exists and will raise ``KeyError``\nif the ID is not present.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to delete."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"main": {
|
||||||
|
"name": "main",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.crud_app.main",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "Application entry point for an OpenAPI-first CRUD example service.\n\nThis module constructs a FastAPI application exclusively from an\nOpenAPI specification and a handler namespace, without using\ndecorator-driven routing.\n\nAll HTTP routes, methods, request/response schemas, and operation\nbindings are defined in the OpenAPI document referenced by\n``openapi_path``. Python callables defined in the ``routes`` module are\nbound to OpenAPI operations strictly via ``operationId``.\n\nThis module contains no routing logic, persistence concerns, or\nframework configuration beyond application assembly.\n\nDesign guarantees:\n- OpenAPI is the single source of truth\n- No undocumented routes can exist\n- Every OpenAPI operationId must resolve to exactly one handler\n- All contract violations fail at application startup\n\nThis file is intended to be used as the ASGI entry point.\n\nExample:\n uvicorn main:app",
|
||||||
|
"members": {
|
||||||
|
"OpenAPIFirstApp": {
|
||||||
|
"name": "OpenAPIFirstApp",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses `FastAPI` and replaces manual route\n registration with OpenAPI-driven binding.\n - All routes are derived from the provided OpenAPI specification,\n and each ``operationId`` is mapped to a Python function in the\n supplied routes module.\n - Auth dependencies are auto-injected from the spec's\n ``securitySchemes`` and per-operation ``security`` fields.\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration.\n - No OpenAPI operation can exist without a handler.\n - Swagger UI and ``/openapi.json`` always reflect the provided spec.\n - Handler functions remain framework-agnostic and testable.\n - Auth enforcement is driven entirely by the spec — no manual\n middleware or decorators required.\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
|
"members": {
|
||||||
|
"openapi": {
|
||||||
|
"name": "openapi",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp.openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('openapi', 'openapi_first.app.OpenAPIFirstApp.openapi')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.main.routes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('routes', 'routes')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.main.app",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "CRUD route handlers bound via OpenAPI operationId.\n\nThese handlers explicitly control HTTP status codes to ensure\nruntime behavior matches the OpenAPI contract.\n\nThis module defines OpenAPI-bound operation handlers for a simple CRUD\nservice. Functions in this module are bound to HTTP routes exclusively\nvia OpenAPI ``operationId`` values.\n\nHandlers explicitly control HTTP response status codes to ensure runtime\nbehavior matches the OpenAPI contract. Error conditions are translated\ninto explicit HTTP responses rather than relying on implicit framework\nbehavior.\n\nNo routing decorators or path definitions appear in this module. All\nrouting, HTTP methods, and schemas are defined in the OpenAPI\nspecification.",
|
||||||
|
"members": {
|
||||||
|
"Response": {
|
||||||
|
"name": "Response",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.Response",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Response', 'fastapi.Response')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"HTTPException": {
|
||||||
|
"name": "HTTPException",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.HTTPException",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('HTTPException', 'fastapi.HTTPException')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_items": {
|
||||||
|
"name": "list_items",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.list_items",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_items', 32, 44)>",
|
||||||
|
"docstring": "List all items.\n\nImplements the OpenAPI operation identified by\n``operationId: list_items``.\n\nReturns\n-------\nlist[dict]\n A list of item representations."
|
||||||
|
},
|
||||||
|
"get_item": {
|
||||||
|
"name": "get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_item', 47, 72)>",
|
||||||
|
"docstring": "Retrieve a single item by ID.\n\nImplements the OpenAPI operation identified by\n``operationId: get_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to retrieve.\n\nReturns\n-------\ndict\n The requested item.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
},
|
||||||
|
"create_item": {
|
||||||
|
"name": "create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_item', 75, 96)>",
|
||||||
|
"docstring": "Create a new item.\n\nImplements the OpenAPI operation identified by\n``operationId: create_item``.\n\nParameters\n----------\npayload : dict\n Item attributes excluding the ``id`` field.\nresponse : fastapi.Response\n Response object used to set the HTTP status code.\n\nReturns\n-------\ndict\n The newly created item."
|
||||||
|
},
|
||||||
|
"update_item": {
|
||||||
|
"name": "update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_item', 99, 126)>",
|
||||||
|
"docstring": "Update an existing item.\n\nImplements the OpenAPI operation identified by\n``operationId: update_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to update.\npayload : dict\n Item attributes excluding the ``id`` field.\n\nReturns\n-------\ndict\n The updated item.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
},
|
||||||
|
"delete_item": {
|
||||||
|
"name": "delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_item', 129, 158)>",
|
||||||
|
"docstring": "Delete an existing item.\n\nImplements the OpenAPI operation identified by\n``operationId: delete_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to delete.\nresponse : fastapi.Response\n Response object used to set the HTTP status code.\n\nReturns\n-------\nNone\n No content.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test_crud_app": {
|
||||||
|
"name": "test_crud_app",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "End-to-end tests for the OpenAPI-first CRUD example app.\n\nThese tests validate that all CRUD operations behave correctly\nagainst the in-memory mock data store.\n- OpenAPI specification loading\n- OperationId-driven route binding on the server\n- OperationId-driven client invocation\n- Correct HTTP status codes and response payloads\n\nThe tests exercise all CRUD operations against an in-memory mock data\nstore and assume deterministic behavior within a single process.\n\nThe tests assume:\n- OpenAPI-first route binding\n- In-memory storage (no persistence guarantees)\n- Deterministic behavior in a single process\n- One-to-one correspondence between OpenAPI operationId values and\n server/client callables",
|
||||||
|
"members": {
|
||||||
|
"TestClient": {
|
||||||
|
"name": "TestClient",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.TestClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('TestClient', 'fastapi.testclient.TestClient')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.app",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('app', 'main.app')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"load_openapi": {
|
||||||
|
"name": "load_openapi",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.load_openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported\n extensions: `.json`, `.yaml`, `.yml`.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI\n schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated\n using a strict OpenAPI schema validator.\n - Any error results in an immediate exception, preventing\n application startup."
|
||||||
|
},
|
||||||
|
"OpenAPIClient": {
|
||||||
|
"name": "OpenAPIClient",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
|
"docstring": "OpenAPI-first HTTP client (`httpx`-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an\n OpenAPI 3.x specification. Each `operationId` becomes a method\n on the client instance.\n\n **Guarantees:**\n\n - One callable per `operationId`.\n - Explicit parameters (path, query, headers, body).\n - No implicit schema inference or mutation.\n - Returns raw `httpx.Response` objects.\n - No response validation or deserialization.\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
|
"members": {
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient.spec",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('spec', 'openapi_first.client.OpenAPIClient.spec')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"base_url": {
|
||||||
|
"name": "base_url",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient.base_url",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('base_url', 'openapi_first.client.OpenAPIClient.base_url')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient.client",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('client', 'openapi_first.client.OpenAPIClient.client')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"operations": {
|
||||||
|
"name": "operations",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient.operations",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('operations', 'openapi_first.client.OpenAPIClient.operations')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.client",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.spec",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"test_list_items_initial": {
|
||||||
|
"name": "test_list_items_initial",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_list_items_initial",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_list_items_initial', 38, 49)>",
|
||||||
|
"docstring": "Initial items should be present."
|
||||||
|
},
|
||||||
|
"test_get_item": {
|
||||||
|
"name": "test_get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_get_item', 52, 62)>",
|
||||||
|
"docstring": "Existing item should be retrievable by ID."
|
||||||
|
},
|
||||||
|
"test_create_item": {
|
||||||
|
"name": "test_create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_create_item', 65, 85)>",
|
||||||
|
"docstring": "Creating a new item should return the created entity."
|
||||||
|
},
|
||||||
|
"test_update_item": {
|
||||||
|
"name": "test_update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_update_item', 88, 112)>",
|
||||||
|
"docstring": "Updating an item should replace its values."
|
||||||
|
},
|
||||||
|
"test_delete_item": {
|
||||||
|
"name": "test_delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_delete_item', 115, 125)>",
|
||||||
|
"docstring": "Deleting an item should remove it from the store."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
docs/mcp/modules/openapi_first.templates.crud_app.main.json
Normal file
39
docs/mcp/modules/openapi_first.templates.crud_app.main.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app.main",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.crud_app.main",
|
||||||
|
"docstring": "Application entry point for an OpenAPI-first CRUD example service.\n\nThis module constructs a FastAPI application exclusively from an\nOpenAPI specification and a handler namespace, without using\ndecorator-driven routing.\n\nAll HTTP routes, methods, request/response schemas, and operation\nbindings are defined in the OpenAPI document referenced by\n``openapi_path``. Python callables defined in the ``routes`` module are\nbound to OpenAPI operations strictly via ``operationId``.\n\nThis module contains no routing logic, persistence concerns, or\nframework configuration beyond application assembly.\n\nDesign guarantees:\n- OpenAPI is the single source of truth\n- No undocumented routes can exist\n- Every OpenAPI operationId must resolve to exactly one handler\n- All contract violations fail at application startup\n\nThis file is intended to be used as the ASGI entry point.\n\nExample:\n uvicorn main:app",
|
||||||
|
"objects": {
|
||||||
|
"OpenAPIFirstApp": {
|
||||||
|
"name": "OpenAPIFirstApp",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses `FastAPI` and replaces manual route\n registration with OpenAPI-driven binding.\n - All routes are derived from the provided OpenAPI specification,\n and each ``operationId`` is mapped to a Python function in the\n supplied routes module.\n - Auth dependencies are auto-injected from the spec's\n ``securitySchemes`` and per-operation ``security`` fields.\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration.\n - No OpenAPI operation can exist without a handler.\n - Swagger UI and ``/openapi.json`` always reflect the provided spec.\n - Handler functions remain framework-agnostic and testable.\n - Auth enforcement is driven entirely by the spec — no manual\n middleware or decorators required.\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
|
"members": {
|
||||||
|
"openapi": {
|
||||||
|
"name": "openapi",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp.openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('openapi', 'openapi_first.app.OpenAPIFirstApp.openapi')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.main.routes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('routes', 'routes')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.main.app",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app.routes",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.crud_app.routes",
|
||||||
|
"docstring": "CRUD route handlers bound via OpenAPI operationId.\n\nThese handlers explicitly control HTTP status codes to ensure\nruntime behavior matches the OpenAPI contract.\n\nThis module defines OpenAPI-bound operation handlers for a simple CRUD\nservice. Functions in this module are bound to HTTP routes exclusively\nvia OpenAPI ``operationId`` values.\n\nHandlers explicitly control HTTP response status codes to ensure runtime\nbehavior matches the OpenAPI contract. Error conditions are translated\ninto explicit HTTP responses rather than relying on implicit framework\nbehavior.\n\nNo routing decorators or path definitions appear in this module. All\nrouting, HTTP methods, and schemas are defined in the OpenAPI\nspecification.",
|
||||||
|
"objects": {
|
||||||
|
"Response": {
|
||||||
|
"name": "Response",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.Response",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Response', 'fastapi.Response')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"HTTPException": {
|
||||||
|
"name": "HTTPException",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.HTTPException",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('HTTPException', 'fastapi.HTTPException')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_items": {
|
||||||
|
"name": "list_items",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.list_items",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_items', 32, 44)>",
|
||||||
|
"docstring": "List all items.\n\nImplements the OpenAPI operation identified by\n``operationId: list_items``.\n\nReturns\n-------\nlist[dict]\n A list of item representations."
|
||||||
|
},
|
||||||
|
"get_item": {
|
||||||
|
"name": "get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_item', 47, 72)>",
|
||||||
|
"docstring": "Retrieve a single item by ID.\n\nImplements the OpenAPI operation identified by\n``operationId: get_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to retrieve.\n\nReturns\n-------\ndict\n The requested item.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
},
|
||||||
|
"create_item": {
|
||||||
|
"name": "create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_item', 75, 96)>",
|
||||||
|
"docstring": "Create a new item.\n\nImplements the OpenAPI operation identified by\n``operationId: create_item``.\n\nParameters\n----------\npayload : dict\n Item attributes excluding the ``id`` field.\nresponse : fastapi.Response\n Response object used to set the HTTP status code.\n\nReturns\n-------\ndict\n The newly created item."
|
||||||
|
},
|
||||||
|
"update_item": {
|
||||||
|
"name": "update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_item', 99, 126)>",
|
||||||
|
"docstring": "Update an existing item.\n\nImplements the OpenAPI operation identified by\n``operationId: update_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to update.\npayload : dict\n Item attributes excluding the ``id`` field.\n\nReturns\n-------\ndict\n The updated item.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
},
|
||||||
|
"delete_item": {
|
||||||
|
"name": "delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.routes.delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_item', 129, 158)>",
|
||||||
|
"docstring": "Delete an existing item.\n\nImplements the OpenAPI operation identified by\n``operationId: delete_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to delete.\nresponse : fastapi.Response\n Response object used to set the HTTP status code.\n\nReturns\n-------\nNone\n No content.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app.test_crud_app",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app",
|
||||||
|
"docstring": "End-to-end tests for the OpenAPI-first CRUD example app.\n\nThese tests validate that all CRUD operations behave correctly\nagainst the in-memory mock data store.\n- OpenAPI specification loading\n- OperationId-driven route binding on the server\n- OperationId-driven client invocation\n- Correct HTTP status codes and response payloads\n\nThe tests exercise all CRUD operations against an in-memory mock data\nstore and assume deterministic behavior within a single process.\n\nThe tests assume:\n- OpenAPI-first route binding\n- In-memory storage (no persistence guarantees)\n- Deterministic behavior in a single process\n- One-to-one correspondence between OpenAPI operationId values and\n server/client callables",
|
||||||
|
"objects": {
|
||||||
|
"TestClient": {
|
||||||
|
"name": "TestClient",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.TestClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('TestClient', 'fastapi.testclient.TestClient')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.app",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('app', 'main.app')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"load_openapi": {
|
||||||
|
"name": "load_openapi",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.load_openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported\n extensions: `.json`, `.yaml`, `.yml`.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI\n schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated\n using a strict OpenAPI schema validator.\n - Any error results in an immediate exception, preventing\n application startup."
|
||||||
|
},
|
||||||
|
"OpenAPIClient": {
|
||||||
|
"name": "OpenAPIClient",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
|
"docstring": "OpenAPI-first HTTP client (`httpx`-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an\n OpenAPI 3.x specification. Each `operationId` becomes a method\n on the client instance.\n\n **Guarantees:**\n\n - One callable per `operationId`.\n - Explicit parameters (path, query, headers, body).\n - No implicit schema inference or mutation.\n - Returns raw `httpx.Response` objects.\n - No response validation or deserialization.\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
|
"members": {
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient.spec",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('spec', 'openapi_first.client.OpenAPIClient.spec')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"base_url": {
|
||||||
|
"name": "base_url",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient.base_url",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('base_url', 'openapi_first.client.OpenAPIClient.base_url')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient.client",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('client', 'openapi_first.client.OpenAPIClient.client')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"operations": {
|
||||||
|
"name": "operations",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient.operations",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('operations', 'openapi_first.client.OpenAPIClient.operations')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.client",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.spec",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"test_list_items_initial": {
|
||||||
|
"name": "test_list_items_initial",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_list_items_initial",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_list_items_initial', 38, 49)>",
|
||||||
|
"docstring": "Initial items should be present."
|
||||||
|
},
|
||||||
|
"test_get_item": {
|
||||||
|
"name": "test_get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_get_item', 52, 62)>",
|
||||||
|
"docstring": "Existing item should be retrievable by ID."
|
||||||
|
},
|
||||||
|
"test_create_item": {
|
||||||
|
"name": "test_create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_create_item', 65, 85)>",
|
||||||
|
"docstring": "Creating a new item should return the created entity."
|
||||||
|
},
|
||||||
|
"test_update_item": {
|
||||||
|
"name": "test_update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_update_item', 88, 112)>",
|
||||||
|
"docstring": "Updating an item should replace its values."
|
||||||
|
},
|
||||||
|
"test_delete_item": {
|
||||||
|
"name": "test_delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.crud_app.test_crud_app.test_delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_delete_item', 115, 125)>",
|
||||||
|
"docstring": "Deleting an item should remove it from the store."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
docs/mcp/modules/openapi_first.templates.health_app.json
Normal file
64
docs/mcp/modules/openapi_first.templates.health_app.json
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.health_app",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.health_app",
|
||||||
|
"docstring": "OpenAPI-first FastAPI application template.\n\nThis package contains a minimal, fully working example of an\nOpenAPI-first FastAPI service built using the ``openapi_first`` library.\n\nThe application is assembled exclusively from:\n- an OpenAPI specification (``openapi.yaml``)\n- a handler namespace (``routes``)\n\nNo routing decorators, implicit behavior, or framework-specific\nconvenience abstractions are used. All HTTP routes, methods, and\noperation bindings are defined in OpenAPI and enforced at application\nstartup.\n\nThis package is intended to be copied as a starting point for new\nservices via the ``openapi-first`` CLI. It is not part of the\n``openapi_first`` library API surface.\n\n----------------------------------------------------------------------\nScaffolding via CLI\n----------------------------------------------------------------------\n\nCreate a new OpenAPI-first health check service using the bundled\ntemplate:\n\n openapi-first health_app\n\nCreate the service in a custom directory:\n\n openapi-first health_app my-health-service\n\nList all available application templates:\n\n openapi-first --list\n\nThe CLI copies template files verbatim into the target directory.\nNo code is generated or modified beyond the copied scaffold.\n\n----------------------------------------------------------------------\nClient Usage Example\n----------------------------------------------------------------------\n\nThe same OpenAPI specification used by the server can be used to\nconstruct a strict, operationId-driven HTTP client.\n\nExample client call for the ``get_health`` operation:\n\n from openapi_first.loader import load_openapi\n from openapi_first.client import OpenAPIClient\n\n spec = load_openapi(\"openapi.yaml\")\n client = OpenAPIClient(spec)\n\n response = client.get_health()\n\n assert response.status_code == 200\n assert response.json() == {\"status\": \"ok\"}\n\nClient guarantees:\n- One callable per OpenAPI ``operationId``\n- No hardcoded URLs or HTTP methods in user code\n- Path and request parameters must match the OpenAPI specification\n- Invalid or incomplete OpenAPI specs fail at client construction time",
|
||||||
|
"objects": {
|
||||||
|
"main": {
|
||||||
|
"name": "main",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.health_app.main",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "Application entry point for an OpenAPI-first FastAPI service.\n\nThis module constructs a FastAPI application exclusively from an\nOpenAPI specification and a handler namespace, without using\ndecorator-driven routing.\n\nAll HTTP routes, methods, and operation bindings are defined in the\nOpenAPI document referenced by ``openapi_path``. Python callables\ndefined in the ``routes`` module are bound to OpenAPI operations\nstrictly via ``operationId``.\n\nThis module contains no routing logic, request handling, or framework\nconfiguration beyond application assembly.\n\nDesign guarantees:\n- OpenAPI is the single source of truth\n- No undocumented routes can exist\n- Every OpenAPI operationId must resolve to exactly one handler\n- All contract violations fail at application startup\n\nThis file is intended to be used as the ASGI entry point.\n\nExample:\n uvicorn main:app",
|
||||||
|
"members": {
|
||||||
|
"OpenAPIFirstApp": {
|
||||||
|
"name": "OpenAPIFirstApp",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses `FastAPI` and replaces manual route\n registration with OpenAPI-driven binding.\n - All routes are derived from the provided OpenAPI specification,\n and each ``operationId`` is mapped to a Python function in the\n supplied routes module.\n - Auth dependencies are auto-injected from the spec's\n ``securitySchemes`` and per-operation ``security`` fields.\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration.\n - No OpenAPI operation can exist without a handler.\n - Swagger UI and ``/openapi.json`` always reflect the provided spec.\n - Handler functions remain framework-agnostic and testable.\n - Auth enforcement is driven entirely by the spec — no manual\n middleware or decorators required.\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
|
"members": {
|
||||||
|
"openapi": {
|
||||||
|
"name": "openapi",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp.openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('openapi', 'openapi_first.app.OpenAPIFirstApp.openapi')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.health_app.main.routes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('routes', 'routes')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.health_app.main.app",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.health_app.routes",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "OpenAPI operation handlers.\n\nThis module defines pure Python callables that implement OpenAPI\noperations for this service. Functions in this module are bound to HTTP\nroutes exclusively via OpenAPI ``operationId`` values.\n\nNo routing decorators, HTTP metadata, or framework-specific logic\nshould appear here. All request/response semantics are defined in the\nOpenAPI specification.\n\nThis module serves solely as an operationId namespace.",
|
||||||
|
"members": {
|
||||||
|
"get_health": {
|
||||||
|
"name": "get_health",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.health_app.routes.get_health",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_health', 16, 32)>",
|
||||||
|
"docstring": "Health check operation handler.\n\nThis function implements the OpenAPI operation identified by\n``operationId: get_health``.\n\nIt contains no routing metadata or framework-specific logic.\nRequest binding, HTTP method, and response semantics are defined\nexclusively by the OpenAPI specification.\n\nReturns\n-------\ndict\n A minimal liveness payload indicating service health."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.health_app.main",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.health_app.main",
|
||||||
|
"docstring": "Application entry point for an OpenAPI-first FastAPI service.\n\nThis module constructs a FastAPI application exclusively from an\nOpenAPI specification and a handler namespace, without using\ndecorator-driven routing.\n\nAll HTTP routes, methods, and operation bindings are defined in the\nOpenAPI document referenced by ``openapi_path``. Python callables\ndefined in the ``routes`` module are bound to OpenAPI operations\nstrictly via ``operationId``.\n\nThis module contains no routing logic, request handling, or framework\nconfiguration beyond application assembly.\n\nDesign guarantees:\n- OpenAPI is the single source of truth\n- No undocumented routes can exist\n- Every OpenAPI operationId must resolve to exactly one handler\n- All contract violations fail at application startup\n\nThis file is intended to be used as the ASGI entry point.\n\nExample:\n uvicorn main:app",
|
||||||
|
"objects": {
|
||||||
|
"OpenAPIFirstApp": {
|
||||||
|
"name": "OpenAPIFirstApp",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses `FastAPI` and replaces manual route\n registration with OpenAPI-driven binding.\n - All routes are derived from the provided OpenAPI specification,\n and each ``operationId`` is mapped to a Python function in the\n supplied routes module.\n - Auth dependencies are auto-injected from the spec's\n ``securitySchemes`` and per-operation ``security`` fields.\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration.\n - No OpenAPI operation can exist without a handler.\n - Swagger UI and ``/openapi.json`` always reflect the provided spec.\n - Handler functions remain framework-agnostic and testable.\n - Auth enforcement is driven entirely by the spec — no manual\n middleware or decorators required.\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
|
"members": {
|
||||||
|
"openapi": {
|
||||||
|
"name": "openapi",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp.openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('openapi', 'openapi_first.app.OpenAPIFirstApp.openapi')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.health_app.main.routes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('routes', 'routes')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.health_app.main.app",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.health_app.routes",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.health_app.routes",
|
||||||
|
"docstring": "OpenAPI operation handlers.\n\nThis module defines pure Python callables that implement OpenAPI\noperations for this service. Functions in this module are bound to HTTP\nroutes exclusively via OpenAPI ``operationId`` values.\n\nNo routing decorators, HTTP metadata, or framework-specific logic\nshould appear here. All request/response semantics are defined in the\nOpenAPI specification.\n\nThis module serves solely as an operationId namespace.",
|
||||||
|
"objects": {
|
||||||
|
"get_health": {
|
||||||
|
"name": "get_health",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.health_app.routes.get_health",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_health', 16, 32)>",
|
||||||
|
"docstring": "Health check operation handler.\n\nThis function implements the OpenAPI operation identified by\n``operationId: get_health``.\n\nIt contains no routing metadata or framework-specific logic.\nRequest binding, HTTP method, and response semantics are defined\nexclusively by the OpenAPI specification.\n\nReturns\n-------\ndict\n A minimal liveness payload indicating service health."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2274
docs/mcp/modules/openapi_first.templates.json
Normal file
2274
docs/mcp/modules/openapi_first.templates.json
Normal file
File diff suppressed because it is too large
Load Diff
65
docs/mcp/modules/openapi_first.templates.model_app.data.json
Normal file
65
docs/mcp/modules/openapi_first.templates.model_app.data.json
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.data",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.model_app.data",
|
||||||
|
"docstring": "In-memory data store using Pydantic models.\n\nThis module is NOT thread-safe and is intended for demos and scaffolds only.\nThis module provides a minimal, process-local data store for the\nmodel-based CRUD example application. It stores and returns domain\nobjects defined using Pydantic models and is intended solely for\ndemonstration and scaffolding purposes.\n\nThe implementation intentionally avoids:\n- persistence\n- concurrency guarantees\n- transactional semantics\n- validation beyond what Pydantic provides\n\nIt is not part of the ``openapi_first`` library API surface.",
|
||||||
|
"objects": {
|
||||||
|
"Dict": {
|
||||||
|
"name": "Dict",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.data.Dict",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Dict', 'typing.Dict')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Item": {
|
||||||
|
"name": "Item",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.data.Item",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Item', 'models.Item')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"ItemCreate": {
|
||||||
|
"name": "ItemCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.data.ItemCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('ItemCreate', 'models.ItemCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_items": {
|
||||||
|
"name": "list_items",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.list_items",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_items', 34, 43)>",
|
||||||
|
"docstring": "Return all items in the data store.\n\nReturns\n-------\nlist[Item]\n A list of item domain objects."
|
||||||
|
},
|
||||||
|
"get_item": {
|
||||||
|
"name": "get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_item', 46, 65)>",
|
||||||
|
"docstring": "Retrieve a single item by ID.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to retrieve.\n\nReturns\n-------\nItem\n The requested item.\n\nRaises\n------\nKeyError\n If the item does not exist."
|
||||||
|
},
|
||||||
|
"create_item": {
|
||||||
|
"name": "create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_item', 68, 89)>",
|
||||||
|
"docstring": "Create a new item in the data store.\n\nA new identifier is assigned automatically. No additional validation\nis performed beyond Pydantic model validation.\n\nParameters\n----------\npayload : ItemCreate\n Data required to create a new item.\n\nReturns\n-------\nItem\n The newly created item."
|
||||||
|
},
|
||||||
|
"update_item": {
|
||||||
|
"name": "update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_item', 92, 120)>",
|
||||||
|
"docstring": "Replace an existing item in the data store.\n\nThis function performs a full replacement of the stored item.\nPartial updates are not supported.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to update.\npayload : ItemCreate\n New item data.\n\nReturns\n-------\nItem\n The updated item.\n\nRaises\n------\nKeyError\n If the item does not exist."
|
||||||
|
},
|
||||||
|
"delete_item": {
|
||||||
|
"name": "delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_item', 123, 137)>",
|
||||||
|
"docstring": "Remove an item from the data store.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to delete.\n\nRaises\n------\nKeyError\n If the item does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
356
docs/mcp/modules/openapi_first.templates.model_app.json
Normal file
356
docs/mcp/modules/openapi_first.templates.model_app.json
Normal file
@@ -0,0 +1,356 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.model_app",
|
||||||
|
"docstring": "OpenAPI-first model-based CRUD application template.\n\nThis package contains a complete, minimal example of an OpenAPI-first\nCRUD service that uses explicit Pydantic domain models for request and\nresponse schemas.\n\nThe application is assembled exclusively from:\n- an OpenAPI specification (``openapi.yaml``)\n- a handler namespace implementing CRUD operations (``routes``)\n- Pydantic domain models (``models``)\n- an in-memory mock data store (``data``)\n\nAll HTTP routes, methods, schemas, and operation bindings are defined\nin the OpenAPI specification and enforced at application startup.\nNo decorator-driven routing or implicit framework behavior is used.\n\nThis template demonstrates:\n- operationId-driven server-side route binding\n- explicit request and response modeling with Pydantic\n- explicit HTTP status code control in handlers\n- operationId-driven client usage against the same OpenAPI contract\n- end-to-end validation using in-memory data and tests\n\n----------------------------------------------------------------------\nScaffolding via CLI\n----------------------------------------------------------------------\n\nCreate a new model-based CRUD example service using the bundled template:\n\n openapi-first model_app\n\nCreate the service in a custom directory:\n\n openapi-first model_app my-model-service\n\nList all available application templates:\n\n openapi-first --list\n\nThe CLI copies template files verbatim into the target directory.\nNo code is generated or modified beyond the copied scaffold.\n\n----------------------------------------------------------------------\nClient Usage Example\n----------------------------------------------------------------------\n\nThe same OpenAPI specification used by the server can be used to\nconstruct a strict, operationId-driven HTTP client.\n\nExample client calls for model-based CRUD operations:\n\n from openapi_first.loader import load_openapi\n from openapi_first.client import OpenAPIClient\n\n spec = load_openapi(\"openapi.yaml\")\n client = OpenAPIClient(spec)\n\n # List items\n response = client.list_items()\n\n # Get item by ID\n response = client.get_item(\n path_params={\"item_id\": 1}\n )\n\n # Create item\n response = client.create_item(\n body={\"name\": \"Orange\", \"price\": 0.8}\n )\n\n # Update item\n response = client.update_item(\n path_params={\"item_id\": 1},\n body={\"name\": \"Green Apple\", \"price\": 0.6},\n )\n\n # Delete item\n response = client.delete_item(\n path_params={\"item_id\": 1}\n )\n\nClient guarantees:\n- One callable per OpenAPI ``operationId``\n- No hardcoded URLs or HTTP methods in user code\n- Request and response payloads conform to Pydantic models\n- Invalid or incomplete OpenAPI specs fail at client construction time\n\n----------------------------------------------------------------------\nNon-Goals\n----------------------------------------------------------------------\n\nThis template is intentionally minimal and is NOT:\n- production-ready\n- persistent or concurrency-safe\n- a reference architecture for data storage\n\nIt exists solely as a copyable example for learning, testing, and\nbootstrapping OpenAPI-first services.\n\nThis package is not part of the ``openapi_first`` library API surface.",
|
||||||
|
"objects": {
|
||||||
|
"data": {
|
||||||
|
"name": "data",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.model_app.data",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "In-memory data store using Pydantic models.\n\nThis module is NOT thread-safe and is intended for demos and scaffolds only.\nThis module provides a minimal, process-local data store for the\nmodel-based CRUD example application. It stores and returns domain\nobjects defined using Pydantic models and is intended solely for\ndemonstration and scaffolding purposes.\n\nThe implementation intentionally avoids:\n- persistence\n- concurrency guarantees\n- transactional semantics\n- validation beyond what Pydantic provides\n\nIt is not part of the ``openapi_first`` library API surface.",
|
||||||
|
"members": {
|
||||||
|
"Dict": {
|
||||||
|
"name": "Dict",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.data.Dict",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Dict', 'typing.Dict')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Item": {
|
||||||
|
"name": "Item",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.data.Item",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Item', 'models.Item')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"ItemCreate": {
|
||||||
|
"name": "ItemCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.data.ItemCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('ItemCreate', 'models.ItemCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_items": {
|
||||||
|
"name": "list_items",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.list_items",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_items', 34, 43)>",
|
||||||
|
"docstring": "Return all items in the data store.\n\nReturns\n-------\nlist[Item]\n A list of item domain objects."
|
||||||
|
},
|
||||||
|
"get_item": {
|
||||||
|
"name": "get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_item', 46, 65)>",
|
||||||
|
"docstring": "Retrieve a single item by ID.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to retrieve.\n\nReturns\n-------\nItem\n The requested item.\n\nRaises\n------\nKeyError\n If the item does not exist."
|
||||||
|
},
|
||||||
|
"create_item": {
|
||||||
|
"name": "create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_item', 68, 89)>",
|
||||||
|
"docstring": "Create a new item in the data store.\n\nA new identifier is assigned automatically. No additional validation\nis performed beyond Pydantic model validation.\n\nParameters\n----------\npayload : ItemCreate\n Data required to create a new item.\n\nReturns\n-------\nItem\n The newly created item."
|
||||||
|
},
|
||||||
|
"update_item": {
|
||||||
|
"name": "update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_item', 92, 120)>",
|
||||||
|
"docstring": "Replace an existing item in the data store.\n\nThis function performs a full replacement of the stored item.\nPartial updates are not supported.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to update.\npayload : ItemCreate\n New item data.\n\nReturns\n-------\nItem\n The updated item.\n\nRaises\n------\nKeyError\n If the item does not exist."
|
||||||
|
},
|
||||||
|
"delete_item": {
|
||||||
|
"name": "delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.data.delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_item', 123, 137)>",
|
||||||
|
"docstring": "Remove an item from the data store.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to delete.\n\nRaises\n------\nKeyError\n If the item does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"main": {
|
||||||
|
"name": "main",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.model_app.main",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "Application entry point for an OpenAPI-first model-based CRUD example service.\n\nThis module constructs a FastAPI application exclusively from an\nOpenAPI specification and a handler namespace, without using\ndecorator-driven routing.\n\nAll HTTP routes, methods, request/response schemas, and operation\nbindings are defined in the OpenAPI document referenced by\n``openapi_path``. Python callables defined in the ``routes`` module are\nbound to OpenAPI operations strictly via ``operationId``.\n\nThis module contains no routing logic, persistence concerns, or\nframework configuration beyond application assembly.\n\nDesign guarantees:\n- OpenAPI is the single source of truth\n- No undocumented routes can exist\n- Every OpenAPI operationId must resolve to exactly one handler\n- All contract violations fail at application startup\n\nThis file is intended to be used as the ASGI entry point.\n\nExample:\n uvicorn main:app",
|
||||||
|
"members": {
|
||||||
|
"OpenAPIFirstApp": {
|
||||||
|
"name": "OpenAPIFirstApp",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses `FastAPI` and replaces manual route\n registration with OpenAPI-driven binding.\n - All routes are derived from the provided OpenAPI specification,\n and each ``operationId`` is mapped to a Python function in the\n supplied routes module.\n - Auth dependencies are auto-injected from the spec's\n ``securitySchemes`` and per-operation ``security`` fields.\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration.\n - No OpenAPI operation can exist without a handler.\n - Swagger UI and ``/openapi.json`` always reflect the provided spec.\n - Handler functions remain framework-agnostic and testable.\n - Auth enforcement is driven entirely by the spec — no manual\n middleware or decorators required.\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
|
"members": {
|
||||||
|
"openapi": {
|
||||||
|
"name": "openapi",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp.openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('openapi', 'openapi_first.app.OpenAPIFirstApp.openapi')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.main.routes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('routes', 'routes')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.main.app",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"models": {
|
||||||
|
"name": "models",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.model_app.models",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "Pydantic domain models for the CRUD example.\n\nThis module defines Pydantic models that represent the domain entities\nused by the service. These models are referenced by the OpenAPI\nspecification for request and response schemas.\n\nThe models are declarative and framework-agnostic. They contain no\npersistence logic, validation beyond type constraints, or business\nbehavior.\n\nThis module is not part of the ``openapi_first`` library API surface.\nIt exists solely to support the example application template.",
|
||||||
|
"members": {
|
||||||
|
"BaseModel": {
|
||||||
|
"name": "BaseModel",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.models.BaseModel",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('BaseModel', 'pydantic.BaseModel')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"ItemBase": {
|
||||||
|
"name": "ItemBase",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.models.ItemBase",
|
||||||
|
"signature": "<bound method Class.signature of Class('ItemBase', 19, 27)>",
|
||||||
|
"docstring": "Base domain model for an item.\n\nDefines fields common to all item representations.",
|
||||||
|
"members": {
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.models.ItemBase.name",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"price": {
|
||||||
|
"name": "price",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.models.ItemBase.price",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ItemCreate": {
|
||||||
|
"name": "ItemCreate",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.models.ItemCreate",
|
||||||
|
"signature": "<bound method Class.signature of Class('ItemCreate', 30, 39)>",
|
||||||
|
"docstring": "Domain model for item creation requests.\n\nThis model is used for request bodies when creating new items.\nIt intentionally excludes the ``id`` field, which is assigned\nby the service."
|
||||||
|
},
|
||||||
|
"Item": {
|
||||||
|
"name": "Item",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.models.Item",
|
||||||
|
"signature": "<bound method Class.signature of Class('Item', 42, 50)>",
|
||||||
|
"docstring": "Domain model for a persisted item.\n\nThis model represents the full item state returned in responses,\nincluding the server-assigned identifier.",
|
||||||
|
"members": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.models.Item.id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.model_app.routes",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "CRUD route handlers bound via OpenAPI operationId.\n\nThis module defines OpenAPI-bound operation handlers for a model-based\nCRUD service. Functions in this module are bound to HTTP routes\nexclusively via OpenAPI ``operationId`` values.\n\nHandlers explicitly control HTTP response status codes to ensure runtime\nbehavior matches the OpenAPI contract. Domain models defined using\nPydantic are used for request and response payloads.\n\nNo routing decorators, path definitions, or implicit framework behavior\nappear in this module. All routing, HTTP methods, and schemas are defined\nin the OpenAPI specification.",
|
||||||
|
"members": {
|
||||||
|
"Response": {
|
||||||
|
"name": "Response",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.Response",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Response', 'fastapi.Response')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"HTTPException": {
|
||||||
|
"name": "HTTPException",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.HTTPException",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('HTTPException', 'fastapi.HTTPException')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"ItemCreate": {
|
||||||
|
"name": "ItemCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.ItemCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('ItemCreate', 'models.ItemCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_items": {
|
||||||
|
"name": "list_items",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.list_items",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_items', 29, 41)>",
|
||||||
|
"docstring": "List all items.\n\nImplements the OpenAPI operation identified by\n``operationId: list_items``.\n\nReturns\n-------\nlist[Item]\n A list of item domain objects."
|
||||||
|
},
|
||||||
|
"get_item": {
|
||||||
|
"name": "get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_item', 44, 69)>",
|
||||||
|
"docstring": "Retrieve a single item by ID.\n\nImplements the OpenAPI operation identified by\n``operationId: get_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to retrieve.\n\nReturns\n-------\nItem\n The requested item.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
},
|
||||||
|
"create_item": {
|
||||||
|
"name": "create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_item', 72, 93)>",
|
||||||
|
"docstring": "Create a new item.\n\nImplements the OpenAPI operation identified by\n``operationId: create_item``.\n\nParameters\n----------\npayload : ItemCreate\n Request body describing the item to create.\nresponse : fastapi.Response\n Response object used to set the HTTP status code.\n\nReturns\n-------\nItem\n The newly created item."
|
||||||
|
},
|
||||||
|
"update_item": {
|
||||||
|
"name": "update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_item', 96, 123)>",
|
||||||
|
"docstring": "Update an existing item.\n\nImplements the OpenAPI operation identified by\n``operationId: update_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to update.\npayload : ItemCreate\n New item data.\n\nReturns\n-------\nItem\n The updated item.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
},
|
||||||
|
"delete_item": {
|
||||||
|
"name": "delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_item', 126, 156)>",
|
||||||
|
"docstring": "Delete an existing item.\n\nImplements the OpenAPI operation identified by\n``operationId: delete_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to delete.\nresponse : fastapi.Response\n Response object used to set the HTTP status code.\n\nReturns\n-------\nNone\n No content.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test_model_app": {
|
||||||
|
"name": "test_model_app",
|
||||||
|
"kind": "module",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": "End-to-end tests for the OpenAPI-first model CRUD example app.\n\nThese tests validate that all CRUD operations behave correctly\nagainst the in-memory mock data store using Pydantic models.\n- OpenAPI specification loading\n- OperationId-driven route binding on the server\n- OperationId-driven client invocation\n- Pydantic model-based request and response handling\n\nAll CRUD operations are exercised against an in-memory mock data store\nbacked by Pydantic domain models.\n\nThe tests assume:\n- OpenAPI-first route binding\n- Pydantic model validation\n- In-memory storage (no persistence guarantees)\n- Deterministic behavior in a single process",
|
||||||
|
"members": {
|
||||||
|
"TestClient": {
|
||||||
|
"name": "TestClient",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.TestClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('TestClient', 'fastapi.testclient.TestClient')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.app",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('app', 'main.app')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"load_openapi": {
|
||||||
|
"name": "load_openapi",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.load_openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported\n extensions: `.json`, `.yaml`, `.yml`.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI\n schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated\n using a strict OpenAPI schema validator.\n - Any error results in an immediate exception, preventing\n application startup."
|
||||||
|
},
|
||||||
|
"OpenAPIClient": {
|
||||||
|
"name": "OpenAPIClient",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
|
"docstring": "OpenAPI-first HTTP client (`httpx`-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an\n OpenAPI 3.x specification. Each `operationId` becomes a method\n on the client instance.\n\n **Guarantees:**\n\n - One callable per `operationId`.\n - Explicit parameters (path, query, headers, body).\n - No implicit schema inference or mutation.\n - Returns raw `httpx.Response` objects.\n - No response validation or deserialization.\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
|
"members": {
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient.spec",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('spec', 'openapi_first.client.OpenAPIClient.spec')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"base_url": {
|
||||||
|
"name": "base_url",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient.base_url",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('base_url', 'openapi_first.client.OpenAPIClient.base_url')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient.client",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('client', 'openapi_first.client.OpenAPIClient.client')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"operations": {
|
||||||
|
"name": "operations",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient.operations",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('operations', 'openapi_first.client.OpenAPIClient.operations')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.client",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.spec",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"test_list_items_initial": {
|
||||||
|
"name": "test_list_items_initial",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_list_items_initial",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_list_items_initial', 37, 48)>",
|
||||||
|
"docstring": "Initial items should be present."
|
||||||
|
},
|
||||||
|
"test_get_item": {
|
||||||
|
"name": "test_get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_get_item', 51, 61)>",
|
||||||
|
"docstring": "Existing item should be retrievable by ID."
|
||||||
|
},
|
||||||
|
"test_create_item": {
|
||||||
|
"name": "test_create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_create_item', 64, 84)>",
|
||||||
|
"docstring": "Creating a new item should return the created entity."
|
||||||
|
},
|
||||||
|
"test_update_item": {
|
||||||
|
"name": "test_update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_update_item', 87, 111)>",
|
||||||
|
"docstring": "Updating an item should replace its values."
|
||||||
|
},
|
||||||
|
"test_delete_item": {
|
||||||
|
"name": "test_delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_delete_item', 114, 124)>",
|
||||||
|
"docstring": "Deleting an item should remove it from the store."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
docs/mcp/modules/openapi_first.templates.model_app.main.json
Normal file
39
docs/mcp/modules/openapi_first.templates.model_app.main.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.main",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.model_app.main",
|
||||||
|
"docstring": "Application entry point for an OpenAPI-first model-based CRUD example service.\n\nThis module constructs a FastAPI application exclusively from an\nOpenAPI specification and a handler namespace, without using\ndecorator-driven routing.\n\nAll HTTP routes, methods, request/response schemas, and operation\nbindings are defined in the OpenAPI document referenced by\n``openapi_path``. Python callables defined in the ``routes`` module are\nbound to OpenAPI operations strictly via ``operationId``.\n\nThis module contains no routing logic, persistence concerns, or\nframework configuration beyond application assembly.\n\nDesign guarantees:\n- OpenAPI is the single source of truth\n- No undocumented routes can exist\n- Every OpenAPI operationId must resolve to exactly one handler\n- All contract violations fail at application startup\n\nThis file is intended to be used as the ASGI entry point.\n\nExample:\n uvicorn main:app",
|
||||||
|
"objects": {
|
||||||
|
"OpenAPIFirstApp": {
|
||||||
|
"name": "OpenAPIFirstApp",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses `FastAPI` and replaces manual route\n registration with OpenAPI-driven binding.\n - All routes are derived from the provided OpenAPI specification,\n and each ``operationId`` is mapped to a Python function in the\n supplied routes module.\n - Auth dependencies are auto-injected from the spec's\n ``securitySchemes`` and per-operation ``security`` fields.\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration.\n - No OpenAPI operation can exist without a handler.\n - Swagger UI and ``/openapi.json`` always reflect the provided spec.\n - Handler functions remain framework-agnostic and testable.\n - Auth enforcement is driven entirely by the spec — no manual\n middleware or decorators required.\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
|
"members": {
|
||||||
|
"openapi": {
|
||||||
|
"name": "openapi",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp.openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('openapi', 'openapi_first.app.OpenAPIFirstApp.openapi')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.main.routes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('routes', 'routes')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.main.app",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.models",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.model_app.models",
|
||||||
|
"docstring": "Pydantic domain models for the CRUD example.\n\nThis module defines Pydantic models that represent the domain entities\nused by the service. These models are referenced by the OpenAPI\nspecification for request and response schemas.\n\nThe models are declarative and framework-agnostic. They contain no\npersistence logic, validation beyond type constraints, or business\nbehavior.\n\nThis module is not part of the ``openapi_first`` library API surface.\nIt exists solely to support the example application template.",
|
||||||
|
"objects": {
|
||||||
|
"BaseModel": {
|
||||||
|
"name": "BaseModel",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.models.BaseModel",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('BaseModel', 'pydantic.BaseModel')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"ItemBase": {
|
||||||
|
"name": "ItemBase",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.models.ItemBase",
|
||||||
|
"signature": "<bound method Class.signature of Class('ItemBase', 19, 27)>",
|
||||||
|
"docstring": "Base domain model for an item.\n\nDefines fields common to all item representations.",
|
||||||
|
"members": {
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.models.ItemBase.name",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"price": {
|
||||||
|
"name": "price",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.models.ItemBase.price",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ItemCreate": {
|
||||||
|
"name": "ItemCreate",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.models.ItemCreate",
|
||||||
|
"signature": "<bound method Class.signature of Class('ItemCreate', 30, 39)>",
|
||||||
|
"docstring": "Domain model for item creation requests.\n\nThis model is used for request bodies when creating new items.\nIt intentionally excludes the ``id`` field, which is assigned\nby the service."
|
||||||
|
},
|
||||||
|
"Item": {
|
||||||
|
"name": "Item",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.models.Item",
|
||||||
|
"signature": "<bound method Class.signature of Class('Item', 42, 50)>",
|
||||||
|
"docstring": "Domain model for a persisted item.\n\nThis model represents the full item state returned in responses,\nincluding the server-assigned identifier.",
|
||||||
|
"members": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.models.Item.id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.routes",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.model_app.routes",
|
||||||
|
"docstring": "CRUD route handlers bound via OpenAPI operationId.\n\nThis module defines OpenAPI-bound operation handlers for a model-based\nCRUD service. Functions in this module are bound to HTTP routes\nexclusively via OpenAPI ``operationId`` values.\n\nHandlers explicitly control HTTP response status codes to ensure runtime\nbehavior matches the OpenAPI contract. Domain models defined using\nPydantic are used for request and response payloads.\n\nNo routing decorators, path definitions, or implicit framework behavior\nappear in this module. All routing, HTTP methods, and schemas are defined\nin the OpenAPI specification.",
|
||||||
|
"objects": {
|
||||||
|
"Response": {
|
||||||
|
"name": "Response",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.Response",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Response', 'fastapi.Response')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"HTTPException": {
|
||||||
|
"name": "HTTPException",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.HTTPException",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('HTTPException', 'fastapi.HTTPException')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"ItemCreate": {
|
||||||
|
"name": "ItemCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.ItemCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('ItemCreate', 'models.ItemCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_items": {
|
||||||
|
"name": "list_items",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.list_items",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_items', 29, 41)>",
|
||||||
|
"docstring": "List all items.\n\nImplements the OpenAPI operation identified by\n``operationId: list_items``.\n\nReturns\n-------\nlist[Item]\n A list of item domain objects."
|
||||||
|
},
|
||||||
|
"get_item": {
|
||||||
|
"name": "get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_item', 44, 69)>",
|
||||||
|
"docstring": "Retrieve a single item by ID.\n\nImplements the OpenAPI operation identified by\n``operationId: get_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to retrieve.\n\nReturns\n-------\nItem\n The requested item.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
},
|
||||||
|
"create_item": {
|
||||||
|
"name": "create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_item', 72, 93)>",
|
||||||
|
"docstring": "Create a new item.\n\nImplements the OpenAPI operation identified by\n``operationId: create_item``.\n\nParameters\n----------\npayload : ItemCreate\n Request body describing the item to create.\nresponse : fastapi.Response\n Response object used to set the HTTP status code.\n\nReturns\n-------\nItem\n The newly created item."
|
||||||
|
},
|
||||||
|
"update_item": {
|
||||||
|
"name": "update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_item', 96, 123)>",
|
||||||
|
"docstring": "Update an existing item.\n\nImplements the OpenAPI operation identified by\n``operationId: update_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to update.\npayload : ItemCreate\n New item data.\n\nReturns\n-------\nItem\n The updated item.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
},
|
||||||
|
"delete_item": {
|
||||||
|
"name": "delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.routes.delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_item', 126, 156)>",
|
||||||
|
"docstring": "Delete an existing item.\n\nImplements the OpenAPI operation identified by\n``operationId: delete_item``.\n\nParameters\n----------\nitem_id : int\n Identifier of the item to delete.\nresponse : fastapi.Response\n Response object used to set the HTTP status code.\n\nReturns\n-------\nNone\n No content.\n\nRaises\n------\nHTTPException\n 404 if the item does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.test_model_app",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app",
|
||||||
|
"docstring": "End-to-end tests for the OpenAPI-first model CRUD example app.\n\nThese tests validate that all CRUD operations behave correctly\nagainst the in-memory mock data store using Pydantic models.\n- OpenAPI specification loading\n- OperationId-driven route binding on the server\n- OperationId-driven client invocation\n- Pydantic model-based request and response handling\n\nAll CRUD operations are exercised against an in-memory mock data store\nbacked by Pydantic domain models.\n\nThe tests assume:\n- OpenAPI-first route binding\n- Pydantic model validation\n- In-memory storage (no persistence guarantees)\n- Deterministic behavior in a single process",
|
||||||
|
"objects": {
|
||||||
|
"TestClient": {
|
||||||
|
"name": "TestClient",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.TestClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('TestClient', 'fastapi.testclient.TestClient')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.app",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('app', 'main.app')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"load_openapi": {
|
||||||
|
"name": "load_openapi",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.load_openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported\n extensions: `.json`, `.yaml`, `.yml`.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI\n schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated\n using a strict OpenAPI schema validator.\n - Any error results in an immediate exception, preventing\n application startup."
|
||||||
|
},
|
||||||
|
"OpenAPIClient": {
|
||||||
|
"name": "OpenAPIClient",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
|
"docstring": "OpenAPI-first HTTP client (`httpx`-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an\n OpenAPI 3.x specification. Each `operationId` becomes a method\n on the client instance.\n\n **Guarantees:**\n\n - One callable per `operationId`.\n - Explicit parameters (path, query, headers, body).\n - No implicit schema inference or mutation.\n - Returns raw `httpx.Response` objects.\n - No response validation or deserialization.\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
|
"members": {
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient.spec",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('spec', 'openapi_first.client.OpenAPIClient.spec')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"base_url": {
|
||||||
|
"name": "base_url",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient.base_url",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('base_url', 'openapi_first.client.OpenAPIClient.base_url')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient.client",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('client', 'openapi_first.client.OpenAPIClient.client')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"operations": {
|
||||||
|
"name": "operations",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient.operations",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('operations', 'openapi_first.client.OpenAPIClient.operations')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.client",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.spec",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"test_list_items_initial": {
|
||||||
|
"name": "test_list_items_initial",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_list_items_initial",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_list_items_initial', 37, 48)>",
|
||||||
|
"docstring": "Initial items should be present."
|
||||||
|
},
|
||||||
|
"test_get_item": {
|
||||||
|
"name": "test_get_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_get_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_get_item', 51, 61)>",
|
||||||
|
"docstring": "Existing item should be retrievable by ID."
|
||||||
|
},
|
||||||
|
"test_create_item": {
|
||||||
|
"name": "test_create_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_create_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_create_item', 64, 84)>",
|
||||||
|
"docstring": "Creating a new item should return the created entity."
|
||||||
|
},
|
||||||
|
"test_update_item": {
|
||||||
|
"name": "test_update_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_update_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_update_item', 87, 111)>",
|
||||||
|
"docstring": "Updating an item should replace its values."
|
||||||
|
},
|
||||||
|
"test_delete_item": {
|
||||||
|
"name": "test_delete_item",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.model_app.test_model_app.test_delete_item",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_delete_item', 114, 124)>",
|
||||||
|
"docstring": "Deleting an item should remove it from the store."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
324
docs/mcp/modules/openapi_first.templates.vet_app.data.json
Normal file
324
docs/mcp/modules/openapi_first.templates.vet_app.data.json
Normal file
@@ -0,0 +1,324 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.data",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.vet_app.data",
|
||||||
|
"docstring": "In-memory data store for the Veterinary Clinic example.\n\nThis module is NOT thread-safe and is intended for demos and scaffolds only.\n\nIt provides minimal, process-local data stores for the five veterinary\nclinic entities. Each store exposes standard CRUD operations backed by\na simple dictionary.\n\nThis module intentionally avoids:\n- persistence\n- concurrency guarantees\n- transactional semantics\n- validation beyond what Pydantic provides\n\nThis module is not part of the ``openapi_first`` library API surface.",
|
||||||
|
"objects": {
|
||||||
|
"date": {
|
||||||
|
"name": "date",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.date",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('date', 'datetime.date')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"datetime": {
|
||||||
|
"name": "datetime",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.datetime",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('datetime', 'datetime.datetime')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"timezone": {
|
||||||
|
"name": "timezone",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.timezone",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('timezone', 'datetime.timezone')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"name": "Parent",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.Parent",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Parent', 'models.Parent')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"ParentCreate": {
|
||||||
|
"name": "ParentCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.ParentCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('ParentCreate', 'models.ParentCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Vet": {
|
||||||
|
"name": "Vet",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.Vet",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Vet', 'models.Vet')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"VetCreate": {
|
||||||
|
"name": "VetCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.VetCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('VetCreate', 'models.VetCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Treatment": {
|
||||||
|
"name": "Treatment",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.Treatment",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Treatment', 'models.Treatment')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"TreatmentCreate": {
|
||||||
|
"name": "TreatmentCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.TreatmentCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('TreatmentCreate', 'models.TreatmentCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Procedure": {
|
||||||
|
"name": "Procedure",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.Procedure",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Procedure', 'models.Procedure')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"BasicNote": {
|
||||||
|
"name": "BasicNote",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.BasicNote",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('BasicNote', 'models.BasicNote')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"HeartRateNote": {
|
||||||
|
"name": "HeartRateNote",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.HeartRateNote",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('HeartRateNote', 'models.HeartRateNote')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"DentalNote": {
|
||||||
|
"name": "DentalNote",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.DentalNote",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('DentalNote', 'models.DentalNote')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"VaccineNote": {
|
||||||
|
"name": "VaccineNote",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.VaccineNote",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('VaccineNote', 'models.VaccineNote')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"PreOpNote": {
|
||||||
|
"name": "PreOpNote",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.PreOpNote",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('PreOpNote', 'models.PreOpNote')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"SurgeryNote": {
|
||||||
|
"name": "SurgeryNote",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.SurgeryNote",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('SurgeryNote', 'models.SurgeryNote')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Pet": {
|
||||||
|
"name": "Pet",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.Pet",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Pet', 'models.Pet')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"PetCreate": {
|
||||||
|
"name": "PetCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.PetCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('PetCreate', 'models.PetCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Appointment": {
|
||||||
|
"name": "Appointment",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.Appointment",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Appointment', 'models.Appointment')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"AppointmentCreate": {
|
||||||
|
"name": "AppointmentCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.AppointmentCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('AppointmentCreate', 'models.AppointmentCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_parents": {
|
||||||
|
"name": "list_parents",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.list_parents",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_parents', 45, 46)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"get_parent": {
|
||||||
|
"name": "get_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.get_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_parent', 49, 50)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"create_parent": {
|
||||||
|
"name": "create_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.create_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_parent', 53, 65)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"update_parent": {
|
||||||
|
"name": "update_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.update_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_parent', 68, 81)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"delete_parent": {
|
||||||
|
"name": "delete_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.delete_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_parent', 84, 85)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_vets": {
|
||||||
|
"name": "list_vets",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.list_vets",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_vets', 96, 97)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"get_vet": {
|
||||||
|
"name": "get_vet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.get_vet",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_vet', 100, 101)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"create_vet": {
|
||||||
|
"name": "create_vet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.create_vet",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_vet', 104, 117)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"update_vet": {
|
||||||
|
"name": "update_vet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.update_vet",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_vet', 120, 134)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"delete_vet": {
|
||||||
|
"name": "delete_vet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.delete_vet",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_vet', 137, 138)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_treatments": {
|
||||||
|
"name": "list_treatments",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.list_treatments",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_treatments', 149, 150)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"get_treatment": {
|
||||||
|
"name": "get_treatment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.get_treatment",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_treatment', 153, 154)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"create_treatment": {
|
||||||
|
"name": "create_treatment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.create_treatment",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_treatment', 157, 168)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"update_treatment": {
|
||||||
|
"name": "update_treatment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.update_treatment",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_treatment', 171, 183)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"delete_treatment": {
|
||||||
|
"name": "delete_treatment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.delete_treatment",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_treatment', 186, 187)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_pets": {
|
||||||
|
"name": "list_pets",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.list_pets",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_pets', 198, 199)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"get_pet": {
|
||||||
|
"name": "get_pet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.get_pet",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_pet', 202, 203)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"create_pet": {
|
||||||
|
"name": "create_pet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.create_pet",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_pet', 206, 223)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"update_pet": {
|
||||||
|
"name": "update_pet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.update_pet",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_pet', 226, 244)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"delete_pet": {
|
||||||
|
"name": "delete_pet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.delete_pet",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_pet', 247, 248)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_appointments": {
|
||||||
|
"name": "list_appointments",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.list_appointments",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_appointments', 259, 260)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"get_appointment": {
|
||||||
|
"name": "get_appointment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.get_appointment",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_appointment', 263, 264)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"create_appointment": {
|
||||||
|
"name": "create_appointment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.create_appointment",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_appointment', 267, 282)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"update_appointment": {
|
||||||
|
"name": "update_appointment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.update_appointment",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_appointment', 285, 301)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"delete_appointment": {
|
||||||
|
"name": "delete_appointment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.data.delete_appointment",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_appointment', 304, 305)>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1572
docs/mcp/modules/openapi_first.templates.vet_app.json
Normal file
1572
docs/mcp/modules/openapi_first.templates.vet_app.json
Normal file
File diff suppressed because it is too large
Load Diff
60
docs/mcp/modules/openapi_first.templates.vet_app.main.json
Normal file
60
docs/mcp/modules/openapi_first.templates.vet_app.main.json
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.main",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.vet_app.main",
|
||||||
|
"docstring": "Application entry point for an OpenAPI-first Veterinary Clinic service.\n\nThis module constructs a FastAPI application exclusively from an\nOpenAPI specification and a handler namespace, without using\ndecorator-driven routing.\n\nAll HTTP routes, methods, request/response schemas, and operation\nbindings are defined in the OpenAPI document referenced by\n``openapi_path``. Python callables defined in the ``routes`` module are\nbound to OpenAPI operations strictly via ``operationId``.\n\nThis module contains no routing logic, persistence concerns, or\nframework configuration beyond application assembly.\n\nDesign guarantees:\n- OpenAPI is the single source of truth\n- No undocumented routes can exist\n- Every OpenAPI operationId must resolve to exactly one handler\n- All contract violations fail at application startup\n\nThis file is intended to be used as the ASGI entry point.\n\nExample:\n uvicorn main:app",
|
||||||
|
"objects": {
|
||||||
|
"asynccontextmanager": {
|
||||||
|
"name": "asynccontextmanager",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.main.asynccontextmanager",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('asynccontextmanager', 'contextlib.asynccontextmanager')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"CORSMiddleware": {
|
||||||
|
"name": "CORSMiddleware",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.main.CORSMiddleware",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('CORSMiddleware', 'starlette.middleware.cors.CORSMiddleware')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"OpenAPIFirstApp": {
|
||||||
|
"name": "OpenAPIFirstApp",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.main.OpenAPIFirstApp",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses `FastAPI` and replaces manual route\n registration with OpenAPI-driven binding.\n - All routes are derived from the provided OpenAPI specification,\n and each ``operationId`` is mapped to a Python function in the\n supplied routes module.\n - Auth dependencies are auto-injected from the spec's\n ``securitySchemes`` and per-operation ``security`` fields.\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration.\n - No OpenAPI operation can exist without a handler.\n - Swagger UI and ``/openapi.json`` always reflect the provided spec.\n - Handler functions remain framework-agnostic and testable.\n - Auth enforcement is driven entirely by the spec — no manual\n middleware or decorators required.\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
|
"members": {
|
||||||
|
"openapi": {
|
||||||
|
"name": "openapi",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.main.OpenAPIFirstApp.openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('openapi', 'openapi_first.app.OpenAPIFirstApp.openapi')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"routes": {
|
||||||
|
"name": "routes",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.main.routes",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('routes', 'routes')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"lifespan": {
|
||||||
|
"name": "lifespan",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.main.lifespan",
|
||||||
|
"signature": "<bound method Function.signature of Function('lifespan', 34, 39)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.main.app",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
681
docs/mcp/modules/openapi_first.templates.vet_app.models.json
Normal file
681
docs/mcp/modules/openapi_first.templates.vet_app.models.json
Normal file
@@ -0,0 +1,681 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.models",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.vet_app.models",
|
||||||
|
"docstring": null,
|
||||||
|
"objects": {
|
||||||
|
"date": {
|
||||||
|
"name": "date",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.date",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('date', 'datetime.date')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"datetime": {
|
||||||
|
"name": "datetime",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.datetime",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('datetime', 'datetime.datetime')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Annotated": {
|
||||||
|
"name": "Annotated",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Annotated",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Annotated', 'typing.Annotated')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Literal": {
|
||||||
|
"name": "Literal",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Literal",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Literal', 'typing.Literal')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"BaseModel": {
|
||||||
|
"name": "BaseModel",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.BaseModel",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('BaseModel', 'pydantic.BaseModel')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Field": {
|
||||||
|
"name": "Field",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Field",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Field', 'pydantic.Field')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Metadata": {
|
||||||
|
"name": "Metadata",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Metadata",
|
||||||
|
"signature": "<bound method Class.signature of Class('Metadata', 6, 8)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"createdOn": {
|
||||||
|
"name": "createdOn",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Metadata.createdOn",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"updatedOn": {
|
||||||
|
"name": "updatedOn",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Metadata.updatedOn",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ParentBase": {
|
||||||
|
"name": "ParentBase",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ParentBase",
|
||||||
|
"signature": "<bound method Class.signature of Class('ParentBase', 11, 15)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ParentBase.name",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"name": "email",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ParentBase.email",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"phone": {
|
||||||
|
"name": "phone",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ParentBase.phone",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"name": "metadata",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ParentBase.metadata",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ParentCreate": {
|
||||||
|
"name": "ParentCreate",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ParentCreate",
|
||||||
|
"signature": "<bound method Class.signature of Class('ParentCreate', 18, 19)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Parent": {
|
||||||
|
"name": "Parent",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Parent",
|
||||||
|
"signature": "<bound method Class.signature of Class('Parent', 22, 23)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Parent.id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"VetBase": {
|
||||||
|
"name": "VetBase",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VetBase",
|
||||||
|
"signature": "<bound method Class.signature of Class('VetBase', 26, 31)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VetBase.name",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"specialty": {
|
||||||
|
"name": "specialty",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VetBase.specialty",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"name": "email",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VetBase.email",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"phone": {
|
||||||
|
"name": "phone",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VetBase.phone",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"name": "metadata",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VetBase.metadata",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"VetCreate": {
|
||||||
|
"name": "VetCreate",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VetCreate",
|
||||||
|
"signature": "<bound method Class.signature of Class('VetCreate', 34, 35)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Vet": {
|
||||||
|
"name": "Vet",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Vet",
|
||||||
|
"signature": "<bound method Class.signature of Class('Vet', 38, 39)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Vet.id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ProcedureNoteBase": {
|
||||||
|
"name": "ProcedureNoteBase",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ProcedureNoteBase",
|
||||||
|
"signature": "<bound method Class.signature of Class('ProcedureNoteBase', 42, 44)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"summary": {
|
||||||
|
"name": "summary",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ProcedureNoteBase.summary",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"details": {
|
||||||
|
"name": "details",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ProcedureNoteBase.details",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"BasicNote": {
|
||||||
|
"name": "BasicNote",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.BasicNote",
|
||||||
|
"signature": "<bound method Class.signature of Class('BasicNote', 47, 48)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"noteType": {
|
||||||
|
"name": "noteType",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.BasicNote.noteType",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"HeartRateNote": {
|
||||||
|
"name": "HeartRateNote",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.HeartRateNote",
|
||||||
|
"signature": "<bound method Class.signature of Class('HeartRateNote', 51, 53)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"noteType": {
|
||||||
|
"name": "noteType",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.HeartRateNote.noteType",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"bpm": {
|
||||||
|
"name": "bpm",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.HeartRateNote.bpm",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"DentalNote": {
|
||||||
|
"name": "DentalNote",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.DentalNote",
|
||||||
|
"signature": "<bound method Class.signature of Class('DentalNote', 56, 59)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"noteType": {
|
||||||
|
"name": "noteType",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.DentalNote.noteType",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"procedureType": {
|
||||||
|
"name": "procedureType",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.DentalNote.procedureType",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"teeth": {
|
||||||
|
"name": "teeth",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.DentalNote.teeth",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"VaccineNote": {
|
||||||
|
"name": "VaccineNote",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VaccineNote",
|
||||||
|
"signature": "<bound method Class.signature of Class('VaccineNote', 62, 65)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"noteType": {
|
||||||
|
"name": "noteType",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VaccineNote.noteType",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"medicine": {
|
||||||
|
"name": "medicine",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VaccineNote.medicine",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"leg": {
|
||||||
|
"name": "leg",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.VaccineNote.leg",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"PreOpNote": {
|
||||||
|
"name": "PreOpNote",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PreOpNote",
|
||||||
|
"signature": "<bound method Class.signature of Class('PreOpNote', 68, 71)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"noteType": {
|
||||||
|
"name": "noteType",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PreOpNote.noteType",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"heartRate": {
|
||||||
|
"name": "heartRate",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PreOpNote.heartRate",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"temperature": {
|
||||||
|
"name": "temperature",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PreOpNote.temperature",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"SurgeryNote": {
|
||||||
|
"name": "SurgeryNote",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.SurgeryNote",
|
||||||
|
"signature": "<bound method Class.signature of Class('SurgeryNote', 74, 77)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"noteType": {
|
||||||
|
"name": "noteType",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.SurgeryNote.noteType",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"surgeryType": {
|
||||||
|
"name": "surgeryType",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.SurgeryNote.surgeryType",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"complications": {
|
||||||
|
"name": "complications",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.SurgeryNote.complications",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ProcedureNotes": {
|
||||||
|
"name": "ProcedureNotes",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.ProcedureNotes",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Procedure": {
|
||||||
|
"name": "Procedure",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Procedure",
|
||||||
|
"signature": "<bound method Class.signature of Class('Procedure', 86, 90)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Procedure.name",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"name": "description",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Procedure.description",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"cost": {
|
||||||
|
"name": "cost",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Procedure.cost",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"notes": {
|
||||||
|
"name": "notes",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Procedure.notes",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"TreatmentBase": {
|
||||||
|
"name": "TreatmentBase",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.TreatmentBase",
|
||||||
|
"signature": "<bound method Class.signature of Class('TreatmentBase', 93, 96)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"label": {
|
||||||
|
"name": "label",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.TreatmentBase.label",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"name": "description",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.TreatmentBase.description",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"name": "metadata",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.TreatmentBase.metadata",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"TreatmentCreate": {
|
||||||
|
"name": "TreatmentCreate",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.TreatmentCreate",
|
||||||
|
"signature": "<bound method Class.signature of Class('TreatmentCreate', 99, 100)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"Treatment": {
|
||||||
|
"name": "Treatment",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Treatment",
|
||||||
|
"signature": "<bound method Class.signature of Class('Treatment', 103, 104)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Treatment.id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"PetBase": {
|
||||||
|
"name": "PetBase",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetBase",
|
||||||
|
"signature": "<bound method Class.signature of Class('PetBase', 107, 114)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetBase.name",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"species": {
|
||||||
|
"name": "species",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetBase.species",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"age": {
|
||||||
|
"name": "age",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetBase.age",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"weight": {
|
||||||
|
"name": "weight",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetBase.weight",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"birthDate": {
|
||||||
|
"name": "birthDate",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetBase.birthDate",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"photo": {
|
||||||
|
"name": "photo",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetBase.photo",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"name": "metadata",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetBase.metadata",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"PetCreate": {
|
||||||
|
"name": "PetCreate",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetCreate",
|
||||||
|
"signature": "<bound method Class.signature of Class('PetCreate', 117, 118)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"parent_ids": {
|
||||||
|
"name": "parent_ids",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.PetCreate.parent_ids",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Pet": {
|
||||||
|
"name": "Pet",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Pet",
|
||||||
|
"signature": "<bound method Class.signature of Class('Pet', 121, 123)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Pet.id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"parents": {
|
||||||
|
"name": "parents",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Pet.parents",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AppointmentBase": {
|
||||||
|
"name": "AppointmentBase",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.AppointmentBase",
|
||||||
|
"signature": "<bound method Class.signature of Class('AppointmentBase', 126, 130)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"date": {
|
||||||
|
"name": "date",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.AppointmentBase.date",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"notes": {
|
||||||
|
"name": "notes",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.AppointmentBase.notes",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"procedures": {
|
||||||
|
"name": "procedures",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.AppointmentBase.procedures",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"name": "metadata",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.AppointmentBase.metadata",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AppointmentCreate": {
|
||||||
|
"name": "AppointmentCreate",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.AppointmentCreate",
|
||||||
|
"signature": "<bound method Class.signature of Class('AppointmentCreate', 133, 136)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"pet_id": {
|
||||||
|
"name": "pet_id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.AppointmentCreate.pet_id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"vet_id": {
|
||||||
|
"name": "vet_id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.AppointmentCreate.vet_id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"treatment_id": {
|
||||||
|
"name": "treatment_id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.AppointmentCreate.treatment_id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Appointment": {
|
||||||
|
"name": "Appointment",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Appointment",
|
||||||
|
"signature": "<bound method Class.signature of Class('Appointment', 139, 143)>",
|
||||||
|
"docstring": null,
|
||||||
|
"members": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Appointment.id",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"pet": {
|
||||||
|
"name": "pet",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Appointment.pet",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"vet": {
|
||||||
|
"name": "vet",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Appointment.vet",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"treatment": {
|
||||||
|
"name": "treatment",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.models.Appointment.treatment",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
275
docs/mcp/modules/openapi_first.templates.vet_app.routes.json
Normal file
275
docs/mcp/modules/openapi_first.templates.vet_app.routes.json
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.routes",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.vet_app.routes",
|
||||||
|
"docstring": "Veterinary Clinic route handlers bound via OpenAPI operationId.\n\nHandlers explicitly control HTTP response status codes to ensure runtime\nbehavior matches the OpenAPI contract. Domain models defined using\nPydantic are used for request and response payloads.\n\nNo routing decorators, path definitions, or implicit framework behavior\nappear in this module. All routing, HTTP methods, and schemas are defined\nin the OpenAPI specification.",
|
||||||
|
"objects": {
|
||||||
|
"Response": {
|
||||||
|
"name": "Response",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.Response",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('Response', 'fastapi.Response')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"HTTPException": {
|
||||||
|
"name": "HTTPException",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.HTTPException",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('HTTPException', 'fastapi.HTTPException')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"UploadFile": {
|
||||||
|
"name": "UploadFile",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.UploadFile",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('UploadFile', 'fastapi.UploadFile')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"StreamingResponse": {
|
||||||
|
"name": "StreamingResponse",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.StreamingResponse",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('StreamingResponse', 'fastapi.responses.StreamingResponse')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"subscribe": {
|
||||||
|
"name": "subscribe",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.subscribe",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('subscribe', 'sse.subscribe')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"unsubscribe": {
|
||||||
|
"name": "unsubscribe",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.unsubscribe",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('unsubscribe', 'sse.unsubscribe')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"ParentCreate": {
|
||||||
|
"name": "ParentCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.ParentCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('ParentCreate', 'models.ParentCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"VetCreate": {
|
||||||
|
"name": "VetCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.VetCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('VetCreate', 'models.VetCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"TreatmentCreate": {
|
||||||
|
"name": "TreatmentCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.TreatmentCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('TreatmentCreate', 'models.TreatmentCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"PetCreate": {
|
||||||
|
"name": "PetCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.PetCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('PetCreate', 'models.PetCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"AppointmentCreate": {
|
||||||
|
"name": "AppointmentCreate",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.AppointmentCreate",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('AppointmentCreate', 'models.AppointmentCreate')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"list_parents": {
|
||||||
|
"name": "list_parents",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.list_parents",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_parents', 60, 76)>",
|
||||||
|
"docstring": "List parents (paginated).\n\nParameters\n----------\nlimit : int\n Maximum number of records to return.\noffset : int\n Number of records to skip.\n\nReturns\n-------\ndict\n Paginated response with ``total`` and ``items``."
|
||||||
|
},
|
||||||
|
"create_parent": {
|
||||||
|
"name": "create_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.create_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_parent', 79, 94)>",
|
||||||
|
"docstring": "Create a parent.\n\nParameters\n----------\npayload : ParentCreate\n Parent data excluding the ``id`` field.\n\nReturns\n-------\nParent\n The newly created parent."
|
||||||
|
},
|
||||||
|
"get_parent": {
|
||||||
|
"name": "get_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.get_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_parent', 97, 118)>",
|
||||||
|
"docstring": "Retrieve a single parent by ID.\n\nParameters\n----------\nid : int\n Identifier of the parent.\n\nReturns\n-------\nParent\n The requested parent.\n\nRaises\n------\nHTTPException\n 404 if the parent does not exist."
|
||||||
|
},
|
||||||
|
"update_parent": {
|
||||||
|
"name": "update_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.update_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_parent', 121, 144)>",
|
||||||
|
"docstring": "Update an existing parent.\n\nParameters\n----------\nid : int\n Identifier of the parent.\npayload : ParentCreate\n Updated parent data.\n\nReturns\n-------\nParent\n The updated parent.\n\nRaises\n------\nHTTPException\n 404 if the parent does not exist."
|
||||||
|
},
|
||||||
|
"delete_parent": {
|
||||||
|
"name": "delete_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.delete_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_parent', 147, 164)>",
|
||||||
|
"docstring": "Delete an existing parent.\n\nParameters\n----------\nid : int\n Identifier of the parent.\n\nRaises\n------\nHTTPException\n 404 if the parent does not exist."
|
||||||
|
},
|
||||||
|
"list_vets": {
|
||||||
|
"name": "list_vets",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.list_vets",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_vets', 172, 175)>",
|
||||||
|
"docstring": "List vets (paginated)."
|
||||||
|
},
|
||||||
|
"create_vet": {
|
||||||
|
"name": "create_vet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.create_vet",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_vet', 178, 182)>",
|
||||||
|
"docstring": "Create a vet."
|
||||||
|
},
|
||||||
|
"get_vet": {
|
||||||
|
"name": "get_vet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.get_vet",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_vet', 185, 190)>",
|
||||||
|
"docstring": "Retrieve a single vet by ID."
|
||||||
|
},
|
||||||
|
"update_vet": {
|
||||||
|
"name": "update_vet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.update_vet",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_vet', 193, 198)>",
|
||||||
|
"docstring": "Update an existing vet."
|
||||||
|
},
|
||||||
|
"delete_vet": {
|
||||||
|
"name": "delete_vet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.delete_vet",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_vet', 201, 207)>",
|
||||||
|
"docstring": "Delete an existing vet."
|
||||||
|
},
|
||||||
|
"list_treatments": {
|
||||||
|
"name": "list_treatments",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.list_treatments",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_treatments', 215, 223)>",
|
||||||
|
"docstring": "List treatments (catalogue).\n\nReturns\n-------\nlist[Treatment]\n A list of treatment domain objects."
|
||||||
|
},
|
||||||
|
"create_treatment": {
|
||||||
|
"name": "create_treatment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.create_treatment",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_treatment', 226, 230)>",
|
||||||
|
"docstring": "Add a treatment (admin only)."
|
||||||
|
},
|
||||||
|
"get_treatment": {
|
||||||
|
"name": "get_treatment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.get_treatment",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_treatment', 233, 238)>",
|
||||||
|
"docstring": "Retrieve a single treatment by ID."
|
||||||
|
},
|
||||||
|
"update_treatment": {
|
||||||
|
"name": "update_treatment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.update_treatment",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_treatment', 241, 246)>",
|
||||||
|
"docstring": "Update an existing treatment."
|
||||||
|
},
|
||||||
|
"delete_treatment": {
|
||||||
|
"name": "delete_treatment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.delete_treatment",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_treatment', 249, 255)>",
|
||||||
|
"docstring": "Delete an existing treatment."
|
||||||
|
},
|
||||||
|
"list_pets": {
|
||||||
|
"name": "list_pets",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.list_pets",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_pets', 263, 266)>",
|
||||||
|
"docstring": "List pets (paginated)."
|
||||||
|
},
|
||||||
|
"create_pet": {
|
||||||
|
"name": "create_pet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.create_pet",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_pet', 269, 273)>",
|
||||||
|
"docstring": "Create a pet."
|
||||||
|
},
|
||||||
|
"get_pet": {
|
||||||
|
"name": "get_pet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.get_pet",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_pet', 276, 281)>",
|
||||||
|
"docstring": "Retrieve a single pet by ID."
|
||||||
|
},
|
||||||
|
"update_pet": {
|
||||||
|
"name": "update_pet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.update_pet",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_pet', 284, 289)>",
|
||||||
|
"docstring": "Update an existing pet."
|
||||||
|
},
|
||||||
|
"delete_pet": {
|
||||||
|
"name": "delete_pet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.delete_pet",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_pet', 292, 298)>",
|
||||||
|
"docstring": "Delete an existing pet."
|
||||||
|
},
|
||||||
|
"upload_pet_photo": {
|
||||||
|
"name": "upload_pet_photo",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.upload_pet_photo",
|
||||||
|
"signature": "<bound method Function.signature of Function('upload_pet_photo', 301, 317)>",
|
||||||
|
"docstring": "Upload a pet photo.\n\nParameters\n----------\nid : int\n Identifier of the pet.\nfile : UploadFile\n Image file to upload.\n\nReturns\n-------\ndict\n A confirmation with the pet ID."
|
||||||
|
},
|
||||||
|
"list_appointments": {
|
||||||
|
"name": "list_appointments",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.list_appointments",
|
||||||
|
"signature": "<bound method Function.signature of Function('list_appointments', 325, 337)>",
|
||||||
|
"docstring": "List appointments (paginated, filterable)."
|
||||||
|
},
|
||||||
|
"create_appointment": {
|
||||||
|
"name": "create_appointment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.create_appointment",
|
||||||
|
"signature": "<bound method Function.signature of Function('create_appointment', 340, 344)>",
|
||||||
|
"docstring": "Create an appointment."
|
||||||
|
},
|
||||||
|
"get_appointment": {
|
||||||
|
"name": "get_appointment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.get_appointment",
|
||||||
|
"signature": "<bound method Function.signature of Function('get_appointment', 347, 352)>",
|
||||||
|
"docstring": "Retrieve a single appointment by ID."
|
||||||
|
},
|
||||||
|
"update_appointment": {
|
||||||
|
"name": "update_appointment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.update_appointment",
|
||||||
|
"signature": "<bound method Function.signature of Function('update_appointment', 355, 360)>",
|
||||||
|
"docstring": "Update an existing appointment."
|
||||||
|
},
|
||||||
|
"delete_appointment": {
|
||||||
|
"name": "delete_appointment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.delete_appointment",
|
||||||
|
"signature": "<bound method Function.signature of Function('delete_appointment', 363, 369)>",
|
||||||
|
"docstring": "Delete an existing appointment."
|
||||||
|
},
|
||||||
|
"stream_actions": {
|
||||||
|
"name": "stream_actions",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.routes.stream_actions",
|
||||||
|
"signature": "<bound method Function.signature of Function('stream_actions', 372, 389)>",
|
||||||
|
"docstring": "Stream animal actions via SSE, scoped to a pet's species."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
docs/mcp/modules/openapi_first.templates.vet_app.sse.json
Normal file
44
docs/mcp/modules/openapi_first.templates.vet_app.sse.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.sse",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.vet_app.sse",
|
||||||
|
"docstring": null,
|
||||||
|
"objects": {
|
||||||
|
"asyncio": {
|
||||||
|
"name": "asyncio",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.sse.asyncio",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('asyncio', 'asyncio')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"random": {
|
||||||
|
"name": "random",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.sse.random",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('random', 'random')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"json": {
|
||||||
|
"name": "json",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.sse.json",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('json', 'json')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"subscribe": {
|
||||||
|
"name": "subscribe",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.sse.subscribe",
|
||||||
|
"signature": "<bound method Function.signature of Function('subscribe', 33, 37)>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"unsubscribe": {
|
||||||
|
"name": "unsubscribe",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.sse.unsubscribe",
|
||||||
|
"signature": "<bound method Function.signature of Function('unsubscribe', 40, 48)>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.test_vet_app",
|
||||||
|
"content": {
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app",
|
||||||
|
"docstring": "End-to-end tests for the OpenAPI-first Veterinary Clinic example app.\n\nThese tests validate that all CRUD operations behave correctly\nagainst the in-memory mock data store using Pydantic models.",
|
||||||
|
"objects": {
|
||||||
|
"TestClient": {
|
||||||
|
"name": "TestClient",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.TestClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('TestClient', 'fastapi.testclient.TestClient')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"app": {
|
||||||
|
"name": "app",
|
||||||
|
"kind": "alias",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.app",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('app', 'main.app')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"load_openapi": {
|
||||||
|
"name": "load_openapi",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.load_openapi",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported\n extensions: `.json`, `.yaml`, `.yml`.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI\n schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated\n using a strict OpenAPI schema validator.\n - Any error results in an immediate exception, preventing\n application startup."
|
||||||
|
},
|
||||||
|
"OpenAPIClient": {
|
||||||
|
"name": "OpenAPIClient",
|
||||||
|
"kind": "class",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.OpenAPIClient",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
|
"docstring": "OpenAPI-first HTTP client (`httpx`-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an\n OpenAPI 3.x specification. Each `operationId` becomes a method\n on the client instance.\n\n **Guarantees:**\n\n - One callable per `operationId`.\n - Explicit parameters (path, query, headers, body).\n - No implicit schema inference or mutation.\n - Returns raw `httpx.Response` objects.\n - No response validation or deserialization.\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
|
"members": {
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.OpenAPIClient.spec",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('spec', 'openapi_first.client.OpenAPIClient.spec')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"base_url": {
|
||||||
|
"name": "base_url",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.OpenAPIClient.base_url",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('base_url', 'openapi_first.client.OpenAPIClient.base_url')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.OpenAPIClient.client",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('client', 'openapi_first.client.OpenAPIClient.client')>",
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"operations": {
|
||||||
|
"name": "operations",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.OpenAPIClient.operations",
|
||||||
|
"signature": "<bound method Alias.signature of Alias('operations', 'openapi_first.client.OpenAPIClient.operations')>",
|
||||||
|
"docstring": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test_client": {
|
||||||
|
"name": "test_client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_client",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"name": "spec",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.spec",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"name": "client",
|
||||||
|
"kind": "attribute",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.client",
|
||||||
|
"signature": null,
|
||||||
|
"docstring": null
|
||||||
|
},
|
||||||
|
"test_list_parents": {
|
||||||
|
"name": "test_list_parents",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_list_parents",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_list_parents', 24, 30)>",
|
||||||
|
"docstring": "List parents returns paginated response."
|
||||||
|
},
|
||||||
|
"test_create_parent": {
|
||||||
|
"name": "test_create_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_create_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_create_parent', 33, 40)>",
|
||||||
|
"docstring": "Creating a parent returns 201 with the created entity."
|
||||||
|
},
|
||||||
|
"test_get_parent": {
|
||||||
|
"name": "test_get_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_get_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_get_parent', 43, 48)>",
|
||||||
|
"docstring": "Get parent by ID returns the entity."
|
||||||
|
},
|
||||||
|
"test_update_parent": {
|
||||||
|
"name": "test_update_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_update_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_update_parent', 51, 57)>",
|
||||||
|
"docstring": "Update parent replaces its values."
|
||||||
|
},
|
||||||
|
"test_delete_parent": {
|
||||||
|
"name": "test_delete_parent",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_delete_parent",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_delete_parent', 60, 64)>",
|
||||||
|
"docstring": "Delete parent returns 204 and removes the entity."
|
||||||
|
},
|
||||||
|
"test_list_vets": {
|
||||||
|
"name": "test_list_vets",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_list_vets",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_list_vets', 67, 73)>",
|
||||||
|
"docstring": "List vets returns paginated response."
|
||||||
|
},
|
||||||
|
"test_create_vet": {
|
||||||
|
"name": "test_create_vet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_create_vet",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_create_vet', 76, 81)>",
|
||||||
|
"docstring": "Creating a vet returns 201."
|
||||||
|
},
|
||||||
|
"test_list_treatments": {
|
||||||
|
"name": "test_list_treatments",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_list_treatments",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_list_treatments', 84, 88)>",
|
||||||
|
"docstring": "List treatments returns an array."
|
||||||
|
},
|
||||||
|
"test_create_treatment": {
|
||||||
|
"name": "test_create_treatment",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_create_treatment",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_create_treatment', 91, 96)>",
|
||||||
|
"docstring": "Creating a treatment returns 201."
|
||||||
|
},
|
||||||
|
"test_create_pet": {
|
||||||
|
"name": "test_create_pet",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_create_pet",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_create_pet', 99, 105)>",
|
||||||
|
"docstring": "Creating a pet links FK references."
|
||||||
|
},
|
||||||
|
"test_upload_pet_photo": {
|
||||||
|
"name": "test_upload_pet_photo",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_upload_pet_photo",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_upload_pet_photo', 108, 115)>",
|
||||||
|
"docstring": "Upload pet photo returns 200."
|
||||||
|
},
|
||||||
|
"test_list_appointments": {
|
||||||
|
"name": "test_list_appointments",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_list_appointments",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_list_appointments', 118, 124)>",
|
||||||
|
"docstring": "List appointments returns paginated response with filter params."
|
||||||
|
},
|
||||||
|
"test_full_appointment_lifecycle": {
|
||||||
|
"name": "test_full_appointment_lifecycle",
|
||||||
|
"kind": "function",
|
||||||
|
"path": "openapi_first.templates.vet_app.test_vet_app.test_full_appointment_lifecycle",
|
||||||
|
"signature": "<bound method Function.signature of Function('test_full_appointment_lifecycle', 127, 151)>",
|
||||||
|
"docstring": "Create a parent, vet, treatment, pet, then an appointment."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
130
docs/mcp/nav.json
Normal file
130
docs/mcp/nav.json
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"module": "openapi_first",
|
||||||
|
"resource": "doc://modules/openapi_first"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.app",
|
||||||
|
"resource": "doc://modules/openapi_first.app"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.binder",
|
||||||
|
"resource": "doc://modules/openapi_first.binder"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.cli",
|
||||||
|
"resource": "doc://modules/openapi_first.cli"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.client",
|
||||||
|
"resource": "doc://modules/openapi_first.client"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.codegen",
|
||||||
|
"resource": "doc://modules/openapi_first.codegen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.codegen_routes",
|
||||||
|
"resource": "doc://modules/openapi_first.codegen_routes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.errors",
|
||||||
|
"resource": "doc://modules/openapi_first.errors"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.loader",
|
||||||
|
"resource": "doc://modules/openapi_first.loader"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.security",
|
||||||
|
"resource": "doc://modules/openapi_first.security"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates",
|
||||||
|
"resource": "doc://modules/openapi_first.templates"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.crud_app"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app.data",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.crud_app.data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app.main",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.crud_app.main"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app.routes",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.crud_app.routes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.crud_app.test_crud_app",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.crud_app.test_crud_app"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.health_app",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.health_app"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.health_app.main",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.health_app.main"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.health_app.routes",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.health_app.routes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.model_app"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.data",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.model_app.data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.main",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.model_app.main"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.models",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.model_app.models"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.routes",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.model_app.routes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.model_app.test_model_app",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.model_app.test_model_app"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.vet_app"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.data",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.vet_app.data"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.main",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.vet_app.main"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.models",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.vet_app.models"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.routes",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.vet_app.routes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.sse",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.vet_app.sse"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"module": "openapi_first.templates.vet_app.test_vet_app",
|
||||||
|
"resource": "doc://modules/openapi_first.templates.vet_app.test_vet_app"
|
||||||
|
}
|
||||||
|
]
|
||||||
159
manage_docs.py
159
manage_docs.py
@@ -1,159 +0,0 @@
|
|||||||
"""
|
|
||||||
MkDocs documentation management CLI.
|
|
||||||
|
|
||||||
This script provides a proper CLI interface to:
|
|
||||||
- Generate MkDocs Markdown files with mkdocstrings directives
|
|
||||||
- Build the documentation site
|
|
||||||
- Serve the documentation site locally
|
|
||||||
|
|
||||||
All operations are performed by calling MkDocs as a Python library
|
|
||||||
(no shell command invocation).
|
|
||||||
|
|
||||||
Requirements:
|
|
||||||
- mkdocs
|
|
||||||
- mkdocs-material
|
|
||||||
- mkdocstrings[python]
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
python manage_docs.py generate
|
|
||||||
python manage_docs.py build
|
|
||||||
python manage_docs.py serve
|
|
||||||
|
|
||||||
Optional flags:
|
|
||||||
--docs-dir PATH Path to docs directory (default: ./docs)
|
|
||||||
--package-root NAME Root Python package name (default: mail_intake)
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from mkdocs.commands import build as mkdocs_build
|
|
||||||
from mkdocs.commands import serve as mkdocs_serve
|
|
||||||
from mkdocs.config import load_config
|
|
||||||
|
|
||||||
|
|
||||||
PROJECT_ROOT = Path(__file__).resolve().parent
|
|
||||||
DEFAULT_DOCS_DIR = PROJECT_ROOT / "docs"
|
|
||||||
DEFAULT_PACKAGE_ROOT = "openapi_first"
|
|
||||||
MKDOCS_YML = PROJECT_ROOT / "mkdocs.yml"
|
|
||||||
|
|
||||||
|
|
||||||
def generate_docs_from_nav(
|
|
||||||
project_root: Path,
|
|
||||||
docs_root: Path,
|
|
||||||
package_root: str,
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Create and populate MkDocs Markdown files with mkdocstrings directives.
|
|
||||||
|
|
||||||
This function:
|
|
||||||
- Walks the Python package structure
|
|
||||||
- Mirrors it under the docs directory
|
|
||||||
- Creates missing .md files
|
|
||||||
- Creates index.md for packages (__init__.py)
|
|
||||||
- Overwrites content with ::: package.module
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
mail_intake/__init__.py -> docs/mail_intake/index.md
|
|
||||||
mail_intake/config.py -> docs/mail_intake/config.md
|
|
||||||
mail_intake/adapters/__init__.py -> docs/mail_intake/adapters/index.md
|
|
||||||
mail_intake/adapters/base.py -> docs/mail_intake/adapters/base.md
|
|
||||||
"""
|
|
||||||
|
|
||||||
package_dir = project_root / package_root
|
|
||||||
if not package_dir.exists():
|
|
||||||
raise FileNotFoundError(f"Package not found: {package_dir}")
|
|
||||||
|
|
||||||
docs_root.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
for py_file in package_dir.rglob("*.py"):
|
|
||||||
rel = py_file.relative_to(project_root)
|
|
||||||
|
|
||||||
if py_file.name == "__init__.py":
|
|
||||||
# Package → index.md
|
|
||||||
module_path = ".".join(rel.parent.parts)
|
|
||||||
md_path = docs_root / rel.parent / "index.md"
|
|
||||||
title = rel.parent.name.replace("_", " ").title()
|
|
||||||
else:
|
|
||||||
# Regular module → <module>.md
|
|
||||||
module_path = ".".join(rel.with_suffix("").parts)
|
|
||||||
md_path = docs_root / rel.with_suffix(".md")
|
|
||||||
title = md_path.stem.replace("_", " ").title()
|
|
||||||
|
|
||||||
md_path.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
content = f"""# {title}
|
|
||||||
|
|
||||||
::: {module_path}
|
|
||||||
"""
|
|
||||||
|
|
||||||
md_path.write_text(content, encoding="utf-8")
|
|
||||||
|
|
||||||
|
|
||||||
def load_mkdocs_config():
|
|
||||||
if not MKDOCS_YML.exists():
|
|
||||||
raise FileNotFoundError("mkdocs.yml not found at project root")
|
|
||||||
return load_config(str(MKDOCS_YML))
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_generate(args: argparse.Namespace) -> None:
|
|
||||||
generate_docs_from_nav(
|
|
||||||
project_root=PROJECT_ROOT,
|
|
||||||
docs_root=args.docs_dir,
|
|
||||||
package_root=args.package_root,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_build(_: argparse.Namespace) -> None:
|
|
||||||
config = load_mkdocs_config()
|
|
||||||
mkdocs_build.build(config)
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_serve(_: argparse.Namespace) -> None:
|
|
||||||
mkdocs_serve.serve(
|
|
||||||
config_file=str(MKDOCS_YML)
|
|
||||||
)
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
prog="manage_docs.py",
|
|
||||||
description="Manage MkDocs documentation for the project",
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--docs-dir",
|
|
||||||
type=Path,
|
|
||||||
default=DEFAULT_DOCS_DIR,
|
|
||||||
help="Path to the docs directory",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--package-root",
|
|
||||||
default=DEFAULT_PACKAGE_ROOT,
|
|
||||||
help="Root Python package name",
|
|
||||||
)
|
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
||||||
|
|
||||||
subparsers.add_parser(
|
|
||||||
"generate",
|
|
||||||
help="Generate Markdown files with mkdocstrings directives",
|
|
||||||
).set_defaults(func=cmd_generate)
|
|
||||||
|
|
||||||
subparsers.add_parser(
|
|
||||||
"build",
|
|
||||||
help="Build the MkDocs site",
|
|
||||||
).set_defaults(func=cmd_build)
|
|
||||||
|
|
||||||
subparsers.add_parser(
|
|
||||||
"serve",
|
|
||||||
help="Serve the MkDocs site locally",
|
|
||||||
).set_defaults(func=cmd_serve)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
args.func(args)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
113
mkdocs.yml
113
mkdocs.yml
@@ -1,51 +1,80 @@
|
|||||||
site_name: Aetoskia Mail Intake
|
|
||||||
site_description: Format-agnostic document reading, parsing, and scraping framework
|
|
||||||
|
|
||||||
theme:
|
theme:
|
||||||
name: material
|
name: material
|
||||||
palette:
|
palette:
|
||||||
- scheme: slate
|
- scheme: slate
|
||||||
primary: deep purple
|
primary: deep purple
|
||||||
accent: cyan
|
accent: cyan
|
||||||
font:
|
font:
|
||||||
text: Inter
|
text: Inter
|
||||||
code: JetBrains Mono
|
code: JetBrains Mono
|
||||||
features:
|
features:
|
||||||
- navigation.tabs
|
- navigation.sections
|
||||||
- navigation.expand
|
- navigation.expand
|
||||||
- navigation.top
|
- navigation.top
|
||||||
- navigation.instant
|
- navigation.instant
|
||||||
- content.code.copy
|
- navigation.tracking
|
||||||
- content.code.annotate
|
- navigation.indexes
|
||||||
|
- content.code.copy
|
||||||
|
- content.code.annotate
|
||||||
|
- content.tabs.link
|
||||||
|
- content.action.edit
|
||||||
|
- search.highlight
|
||||||
|
- search.share
|
||||||
|
- search.suggest
|
||||||
|
icon:
|
||||||
|
logo: material/api
|
||||||
|
repo: fontawesome/brands/github
|
||||||
|
markdown_extensions:
|
||||||
|
- pymdownx.superfences
|
||||||
|
- pymdownx.inlinehilite
|
||||||
|
- pymdownx.snippets
|
||||||
|
- admonition
|
||||||
|
- pymdownx.details
|
||||||
|
- pymdownx.highlight:
|
||||||
|
linenums: true
|
||||||
|
anchor_linenums: true
|
||||||
|
line_spans: __span
|
||||||
|
pygments_lang_class: true
|
||||||
|
- pymdownx.tabbed:
|
||||||
|
alternate_style: true
|
||||||
|
- pymdownx.tasklist:
|
||||||
|
custom_checkbox: true
|
||||||
|
- tables
|
||||||
|
- footnotes
|
||||||
|
- pymdownx.caret
|
||||||
|
- pymdownx.tilde
|
||||||
|
- pymdownx.mark
|
||||||
|
extra_css:
|
||||||
|
- https://unpkg.com/dracula-prism/dist/css/dracula-prism.css
|
||||||
plugins:
|
plugins:
|
||||||
- search
|
- search
|
||||||
- mkdocstrings:
|
- mkdocstrings:
|
||||||
handlers:
|
handlers:
|
||||||
python:
|
python:
|
||||||
paths: ["."]
|
paths:
|
||||||
options:
|
- .
|
||||||
docstring_style: google
|
options:
|
||||||
show_source: false
|
docstring_style: google
|
||||||
show_signature_annotations: true
|
show_source: false
|
||||||
separate_signature: true
|
show_signature_annotations: true
|
||||||
merge_init_into_class: true
|
separate_signature: true
|
||||||
inherited_members: true
|
merge_init_into_class: true
|
||||||
annotations_path: brief
|
inherited_members: true
|
||||||
show_root_heading: true
|
annotations_path: brief
|
||||||
group_by_category: true
|
show_root_heading: true
|
||||||
|
group_by_category: true
|
||||||
|
show_category_heading: true
|
||||||
|
show_object_full_path: false
|
||||||
|
show_symbol_type_heading: true
|
||||||
|
site_name: openapi_first
|
||||||
|
docs_dir: docs
|
||||||
nav:
|
nav:
|
||||||
- Home: openapi_first/index.md
|
- Home: lib/index.md
|
||||||
|
- Application Bootstrap:
|
||||||
- Core:
|
- lib/app.md
|
||||||
- OpenAPI-First App: openapi_first/app.md
|
- lib/binder.md
|
||||||
- Route Binder: openapi_first/binder.md
|
- Core Utilities:
|
||||||
- Spec Loaders: openapi_first/loader.md
|
- lib/loader.md
|
||||||
- Client: openapi_first/client.md
|
- lib/errors.md
|
||||||
|
- OpenAPI Client:
|
||||||
- CLI:
|
- lib/client.md
|
||||||
- Home: openapi_first/cli.md
|
|
||||||
|
|
||||||
- Errors:
|
|
||||||
- Error Hierarchy: openapi_first/errors.md
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
|
# Summary
|
||||||
|
|
||||||
FastAPI OpenAPI First — strict OpenAPI-first application bootstrap for FastAPI.
|
FastAPI OpenAPI First — strict OpenAPI-first application bootstrap for FastAPI.
|
||||||
|
|
||||||
FastAPI OpenAPI First is a **contract-first infrastructure library** that
|
FastAPI OpenAPI First is a **contract-first infrastructure library** that
|
||||||
@@ -7,178 +9,90 @@ enforces OpenAPI as the single source of truth for FastAPI services.
|
|||||||
The library removes decorator-driven routing and replaces it with
|
The library removes decorator-driven routing and replaces it with
|
||||||
deterministic, spec-driven application assembly. Every HTTP route,
|
deterministic, spec-driven application assembly. Every HTTP route,
|
||||||
method, and operation is defined in OpenAPI first and bound to Python
|
method, and operation is defined in OpenAPI first and bound to Python
|
||||||
handlers explicitly via operationId.
|
handlers explicitly via `operationId`.
|
||||||
|
|
||||||
The package is intentionally minimal and layered. Each module has a
|
---
|
||||||
single responsibility and exposes explicit contracts rather than
|
|
||||||
convenience facades.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
# Installation
|
||||||
Architecture Overview
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
The library is structured around four core responsibilities:
|
|
||||||
|
|
||||||
- loader: load and validate OpenAPI 3.x specifications (JSON/YAML)
|
|
||||||
- binder: bind OpenAPI operations to FastAPI routes via operationId
|
|
||||||
- app: OpenAPI-first FastAPI application bootstrap
|
|
||||||
- client: OpenAPI-first HTTP client driven by the same specification
|
|
||||||
- errors: explicit error hierarchy for contract violations
|
|
||||||
|
|
||||||
The package root acts as a **namespace**, not a facade. Consumers are
|
|
||||||
expected to import functionality explicitly from the appropriate module.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Installation
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
Install using pip:
|
Install using pip:
|
||||||
|
|
||||||
pip install openapi-first
|
```bash
|
||||||
|
pip install openapi-first
|
||||||
|
```
|
||||||
|
|
||||||
Or with Poetry:
|
Or with Poetry:
|
||||||
|
|
||||||
poetry add openapi-first
|
```bash
|
||||||
|
poetry add openapi-first
|
||||||
|
```
|
||||||
|
|
||||||
Runtime dependencies are intentionally minimal:
|
---
|
||||||
- fastapi (server-side)
|
|
||||||
- httpx (client-side)
|
|
||||||
- openapi-spec-validator
|
|
||||||
- pyyaml (optional, for YAML specs)
|
|
||||||
|
|
||||||
The ASGI server (e.g., uvicorn) is an application-level dependency and is
|
# Quick Start
|
||||||
not bundled with this library.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Server-Side Usage (OpenAPI → FastAPI)
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
Minimal OpenAPI-first FastAPI application:
|
Minimal OpenAPI-first FastAPI application:
|
||||||
|
|
||||||
from openapi_first import app
|
```python
|
||||||
import my_service.routes as routes
|
from openapi_first import app
|
||||||
|
import my_service.routes as routes
|
||||||
|
|
||||||
api = app.OpenAPIFirstApp(
|
api = app.OpenAPIFirstApp(
|
||||||
openapi_path="openapi.yaml",
|
openapi_path="openapi.yaml",
|
||||||
routes_module=routes,
|
routes_module=routes,
|
||||||
title="My Service",
|
title="My Service",
|
||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
)
|
)
|
||||||
|
```
|
||||||
|
|
||||||
# Run with:
|
OperationId-driven HTTP client:
|
||||||
# uvicorn my_service.main:api
|
|
||||||
|
|
||||||
Handler definitions (no decorators):
|
```python
|
||||||
|
from openapi_first.loader import load_openapi
|
||||||
|
from openapi_first.client import OpenAPIClient
|
||||||
|
|
||||||
def get_health():
|
spec = load_openapi("openapi.yaml")
|
||||||
return {"status": "ok"}
|
client = OpenAPIClient(spec)
|
||||||
|
|
||||||
OpenAPI snippet:
|
response = client.get_health()
|
||||||
|
```
|
||||||
|
|
||||||
paths:
|
---
|
||||||
/health:
|
|
||||||
get:
|
|
||||||
operationId: get_health
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: OK
|
|
||||||
|
|
||||||
The binder guarantees:
|
# Architecture
|
||||||
- Every OpenAPI operationId has exactly one handler
|
|
||||||
- No undocumented routes exist
|
|
||||||
- All mismatches fail at application startup
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
The library is structured around four core responsibilities:
|
||||||
Client-Side Usage (OpenAPI → HTTP Client)
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
The same OpenAPI specification can be used to construct a strict,
|
- `loader`: Load and validate OpenAPI 3.x specifications (JSON/YAML).
|
||||||
operationId-driven HTTP client.
|
- `binder`: Bind OpenAPI operations to FastAPI routes via `operationId`.
|
||||||
|
- `app`: OpenAPI-first FastAPI application bootstrap.
|
||||||
|
- `client`: OpenAPI-first HTTP client driven by the same specification.
|
||||||
|
- `errors`: Explicit error hierarchy for contract violations.
|
||||||
|
|
||||||
Client construction:
|
---
|
||||||
|
|
||||||
from openapi_first.loader import load_openapi
|
# Public API
|
||||||
from openapi_first.client import OpenAPIClient
|
|
||||||
|
|
||||||
spec = load_openapi("openapi.yaml")
|
|
||||||
|
|
||||||
client = OpenAPIClient(spec)
|
|
||||||
|
|
||||||
Calling operations (operationId is the API):
|
|
||||||
|
|
||||||
response = client.get_health()
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json() == {"status": "ok"}
|
|
||||||
|
|
||||||
Path parameters must match the OpenAPI specification exactly:
|
|
||||||
|
|
||||||
response = client.get_item(
|
|
||||||
path_params={"item_id": 1}
|
|
||||||
)
|
|
||||||
|
|
||||||
Request bodies are passed explicitly:
|
|
||||||
|
|
||||||
response = client.create_item(
|
|
||||||
body={"name": "Orange", "price": 0.8}
|
|
||||||
)
|
|
||||||
|
|
||||||
Client guarantees:
|
|
||||||
- One callable per OpenAPI operationId
|
|
||||||
- No hardcoded URLs or HTTP methods in user code
|
|
||||||
- Path and body parameters must match the spec exactly
|
|
||||||
- Invalid or incomplete OpenAPI specs fail at client construction time
|
|
||||||
- No schema inference or mutation is performed
|
|
||||||
|
|
||||||
The client is transport-level only and returns `httpx.Response`
|
|
||||||
objects directly. Response interpretation and validation are left to
|
|
||||||
the consumer or higher-level layers.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Extensibility Model
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
FastAPI OpenAPI First is designed to be extended via **explicit contracts**:
|
|
||||||
|
|
||||||
- Users MAY extend OpenAPI loading behavior (e.g. multi-file specs)
|
|
||||||
by wrapping or replacing `loader.load_openapi`
|
|
||||||
- Users MAY extend route binding behavior by building on top of
|
|
||||||
`binder.bind_routes`
|
|
||||||
- Users MAY layer additional validation (e.g. signature checks)
|
|
||||||
without modifying core modules
|
|
||||||
|
|
||||||
Users SHOULD NOT rely on FastAPI decorators for routing when using this
|
|
||||||
library. Mixing decorator-driven routes with OpenAPI-first routing
|
|
||||||
defeats the contract guarantees and is explicitly unsupported.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Public API Surface
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
The supported public API consists of the following top-level modules:
|
The supported public API consists of the following top-level modules:
|
||||||
|
|
||||||
- openapi_first.app
|
- `openapi_first.app`
|
||||||
- openapi_first.binder
|
- `openapi_first.binder`
|
||||||
- openapi_first.loader
|
- `openapi_first.loader`
|
||||||
- openapi_first.client
|
- `openapi_first.client`
|
||||||
- openapi_first.errors
|
- `openapi_first.errors`
|
||||||
|
|
||||||
Classes and functions should be imported explicitly from these modules.
|
---
|
||||||
No individual symbols are re-exported at the package root.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
# Design Guarantees
|
||||||
Design Guarantees
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
- OpenAPI is the single source of truth
|
- OpenAPI is the single source of truth.
|
||||||
- No undocumented routes can exist
|
- No undocumented routes can exist.
|
||||||
- No OpenAPI operation can exist without a handler or client callable
|
- No OpenAPI operation can exist without a handler or client callable.
|
||||||
- All contract violations fail at application startup or client creation
|
- All contract violations fail at application startup or client creation.
|
||||||
- No hidden FastAPI magic or implicit behavior
|
- No hidden FastAPI magic or implicit behavior.
|
||||||
- Deterministic, testable application assembly
|
- Deterministic, testable application assembly.
|
||||||
- CI-friendly failure modes
|
|
||||||
|
|
||||||
FastAPI OpenAPI First favors correctness, explicitness, and contract
|
---
|
||||||
enforcement over convenience shortcuts.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from . import app
|
from . import app
|
||||||
@@ -186,6 +100,9 @@ from . import binder
|
|||||||
from . import loader
|
from . import loader
|
||||||
from . import client
|
from . import client
|
||||||
from . import errors
|
from . import errors
|
||||||
|
from . import codegen
|
||||||
|
from . import codegen_routes
|
||||||
|
from . import security
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"app",
|
"app",
|
||||||
@@ -193,4 +110,7 @@ __all__ = [
|
|||||||
"loader",
|
"loader",
|
||||||
"client",
|
"client",
|
||||||
"errors",
|
"errors",
|
||||||
|
"codegen",
|
||||||
|
"codegen_routes",
|
||||||
|
"security",
|
||||||
]
|
]
|
||||||
|
|||||||
9
openapi_first/__init__.pyi
Normal file
9
openapi_first/__init__.pyi
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from . import app as app
|
||||||
|
from . import binder as binder
|
||||||
|
from . import client as client
|
||||||
|
from . import codegen as codegen
|
||||||
|
from . import codegen_routes as codegen_routes
|
||||||
|
from . import errors as errors
|
||||||
|
from . import loader as loader
|
||||||
|
|
||||||
|
__all__ = ["app", "binder", "loader", "client", "errors", "codegen", "codegen_routes"]
|
||||||
@@ -1,97 +1,104 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.app
|
# Summary
|
||||||
=========================
|
|
||||||
|
|
||||||
OpenAPI-first application bootstrap for FastAPI.
|
OpenAPI-first application bootstrap for FastAPI.
|
||||||
|
|
||||||
This module provides `OpenAPIFirstApp`, a thin but strict abstraction
|
This module provides `OpenAPIFirstApp`, a thin but strict abstraction
|
||||||
that enforces OpenAPI as the single source of truth for a FastAPI service.
|
that enforces OpenAPI as the single source of truth for a FastAPI service.
|
||||||
|
|
||||||
Core principles
|
Notes:
|
||||||
---------------
|
**Core Principles:**
|
||||||
- The OpenAPI specification (JSON or YAML) defines the entire API surface.
|
|
||||||
- Every operationId in the OpenAPI spec must have a corresponding
|
|
||||||
Python handler function.
|
|
||||||
- Handlers are plain Python callables (no FastAPI decorators).
|
|
||||||
- FastAPI route registration is derived exclusively from the spec.
|
|
||||||
- FastAPI's autogenerated OpenAPI schema is fully overridden.
|
|
||||||
|
|
||||||
What this module does
|
- The OpenAPI specification (JSON or YAML) defines the entire API surface.
|
||||||
---------------------
|
- Every `operationId` in the OpenAPI spec must have a corresponding
|
||||||
- Loads and validates an OpenAPI 3.x specification.
|
Python handler function.
|
||||||
- Dynamically binds HTTP routes to handler functions using operationId.
|
- Handlers are plain Python callables (no FastAPI decorators).
|
||||||
- Registers routes with FastAPI at application startup.
|
- FastAPI route registration is derived exclusively from the spec.
|
||||||
- Ensures runtime behavior matches the OpenAPI contract exactly.
|
- FastAPI's autogenerated OpenAPI schema is fully overridden.
|
||||||
|
|
||||||
What this module does NOT do
|
**Responsibilities:**
|
||||||
----------------------------
|
|
||||||
- It does not generate OpenAPI specs.
|
|
||||||
- It does not generate client code.
|
|
||||||
- It does not introduce a new framework or lifecycle.
|
|
||||||
- It does not alter FastAPI dependency injection semantics.
|
|
||||||
|
|
||||||
Intended usage
|
- Loads and validates an OpenAPI 3.x specification.
|
||||||
--------------
|
- Dynamically binds HTTP routes to handler functions using `operationId`.
|
||||||
This module is intended for teams that want:
|
- Registers routes with FastAPI at application startup.
|
||||||
|
- Ensures runtime behavior matches the OpenAPI contract exactly.
|
||||||
|
|
||||||
- OpenAPI-first API development
|
**Constraints:**
|
||||||
- Strong contract enforcement
|
|
||||||
- Minimal FastAPI boilerplate
|
- This module intentionally does NOT:
|
||||||
- Predictable, CI-friendly failures for spec/implementation drift
|
- Generate OpenAPI specs.
|
||||||
|
- Generate client code.
|
||||||
|
- Introduce a new framework or lifecycle.
|
||||||
|
- Alter FastAPI dependency injection semantics.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
from .loader import load_openapi
|
|
||||||
from .binder import bind_routes
|
from .binder import bind_routes
|
||||||
|
from .loader import load_openapi
|
||||||
|
from .security import make_security_dependencies, parse_security_schemes
|
||||||
|
|
||||||
|
_env_pattern = re.compile(r"\{(\w+)\}")
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_env(value: str) -> str:
|
||||||
|
"""Replace {ENV_VAR} placeholders with values from os.environ."""
|
||||||
|
|
||||||
|
def _replace(m: re.Match) -> str:
|
||||||
|
return os.environ.get(m.group(1), m.group(0))
|
||||||
|
|
||||||
|
return _env_pattern.sub(_replace, value)
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_spec_env_vars(obj):
|
||||||
|
"""Recursively resolve {ENV_VAR} in all string values of the spec."""
|
||||||
|
if isinstance(obj, str):
|
||||||
|
return _resolve_env(obj)
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
return {k: _resolve_spec_env_vars(v) for k, v in obj.items()}
|
||||||
|
if isinstance(obj, list):
|
||||||
|
return [_resolve_spec_env_vars(v) for v in obj]
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
class OpenAPIFirstApp(FastAPI):
|
class OpenAPIFirstApp(FastAPI):
|
||||||
"""
|
"""
|
||||||
FastAPI application enforcing OpenAPI-first design.
|
FastAPI application enforcing OpenAPI-first design.
|
||||||
|
|
||||||
`OpenAPIFirstApp` subclasses FastAPI and replaces manual route
|
Notes:
|
||||||
registration with OpenAPI-driven binding. All routes are derived
|
**Responsibilities:**
|
||||||
from the provided OpenAPI specification, and each operationId is
|
|
||||||
mapped to a Python function in the supplied routes module.
|
|
||||||
|
|
||||||
Parameters
|
- `OpenAPIFirstApp` subclasses `FastAPI` and replaces manual route
|
||||||
----------
|
registration with OpenAPI-driven binding.
|
||||||
openapi_path : str
|
- All routes are derived from the provided OpenAPI specification,
|
||||||
Filesystem path to the OpenAPI 3.x specification file.
|
and each ``operationId`` is mapped to a Python function in the
|
||||||
This specification is treated as the authoritative API contract.
|
supplied routes module.
|
||||||
|
- Auth dependencies are auto-injected from the spec's
|
||||||
|
``securitySchemes`` and per-operation ``security`` fields.
|
||||||
|
|
||||||
routes_module : module
|
**Guarantees:**
|
||||||
Python module containing handler functions whose names correspond
|
|
||||||
exactly to OpenAPI operationId values.
|
|
||||||
|
|
||||||
**fastapi_kwargs
|
- No route can exist without an OpenAPI declaration.
|
||||||
Additional keyword arguments passed directly to `fastapi.FastAPI`
|
- No OpenAPI operation can exist without a handler.
|
||||||
(e.g., title, version, middleware, lifespan handlers).
|
- Swagger UI and ``/openapi.json`` always reflect the provided spec.
|
||||||
|
- Handler functions remain framework-agnostic and testable.
|
||||||
|
- Auth enforcement is driven entirely by the spec — no manual
|
||||||
|
middleware or decorators required.
|
||||||
|
|
||||||
Raises
|
Example:
|
||||||
------
|
```python
|
||||||
OpenAPIFirstError
|
from openapi_first import OpenAPIFirstApp
|
||||||
If the OpenAPI specification is invalid, or if any declared
|
import app.routes as routes
|
||||||
operationId does not have a corresponding handler function.
|
|
||||||
|
|
||||||
Behavior guarantees
|
app = OpenAPIFirstApp(
|
||||||
-------------------
|
openapi_path="app/openapi.json",
|
||||||
- No route can exist without an OpenAPI declaration.
|
routes_module=routes,
|
||||||
- No OpenAPI operation can exist without a handler.
|
title="Example Service",
|
||||||
- Swagger UI and `/openapi.json` always reflect the provided spec.
|
)
|
||||||
- Handler functions remain framework-agnostic and testable.
|
```
|
||||||
|
|
||||||
Example
|
|
||||||
-------
|
|
||||||
>>> from openapi_first import OpenAPIFirstApp
|
|
||||||
>>> import app.routes as routes
|
|
||||||
>>>
|
|
||||||
>>> app = OpenAPIFirstApp(
|
|
||||||
... openapi_path="app/openapi.json",
|
|
||||||
... routes_module=routes,
|
|
||||||
... title="Example Service"
|
|
||||||
... )
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -101,17 +108,42 @@ class OpenAPIFirstApp(FastAPI):
|
|||||||
routes_module,
|
routes_module,
|
||||||
**fastapi_kwargs,
|
**fastapi_kwargs,
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Initialize the application.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
openapi_path (str):
|
||||||
|
Filesystem path to the OpenAPI 3.x specification file. This
|
||||||
|
specification is treated as the authoritative API contract.
|
||||||
|
routes_module (module):
|
||||||
|
Python module containing handler functions whose names correspond
|
||||||
|
exactly to OpenAPI ``operationId`` values.
|
||||||
|
**fastapi_kwargs (Any):
|
||||||
|
Additional keyword arguments passed directly to
|
||||||
|
``fastapi.FastAPI`` (e.g., title, version, middleware, lifespan
|
||||||
|
handlers).
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
OpenAPIFirstError:
|
||||||
|
If the OpenAPI specification is invalid, or if any declared
|
||||||
|
``operationId`` does not have a corresponding handler function.
|
||||||
|
"""
|
||||||
# Initialize FastAPI normally
|
# Initialize FastAPI normally
|
||||||
super().__init__(**fastapi_kwargs)
|
super().__init__(**fastapi_kwargs)
|
||||||
|
|
||||||
# Load and validate OpenAPI specification
|
# Load and validate OpenAPI specification
|
||||||
self._openapi_spec = load_openapi(openapi_path)
|
self._openapi_spec = _resolve_spec_env_vars(load_openapi(openapi_path))
|
||||||
|
|
||||||
# Bind routes strictly from OpenAPI spec
|
# Parse security schemes and build per-route dependencies
|
||||||
|
security_schemes = parse_security_schemes(self._openapi_spec)
|
||||||
|
security_deps = make_security_dependencies(self._openapi_spec, security_schemes)
|
||||||
|
|
||||||
|
# Bind routes strictly from OpenAPI spec (with security deps)
|
||||||
bind_routes(
|
bind_routes(
|
||||||
app=self,
|
app=self,
|
||||||
spec=self._openapi_spec,
|
spec=self._openapi_spec,
|
||||||
routes_module=routes_module,
|
routes_module=routes_module,
|
||||||
|
security_deps=security_deps,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override FastAPI's OpenAPI generation
|
# Override FastAPI's OpenAPI generation
|
||||||
|
|||||||
8
openapi_first/app.pyi
Normal file
8
openapi_first/app.pyi
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
class OpenAPIFirstApp(FastAPI):
|
||||||
|
def __init__(
|
||||||
|
self, *, openapi_path: str, routes_module: Any, **fastapi_kwargs: Any
|
||||||
|
) -> None: ...
|
||||||
@@ -1,80 +1,98 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.binder
|
# Summary
|
||||||
============================
|
|
||||||
|
|
||||||
OpenAPI-driven route binding for FastAPI.
|
OpenAPI-driven route binding for FastAPI.
|
||||||
|
|
||||||
This module is responsible for translating an OpenAPI 3.x specification
|
This module is responsible for translating an OpenAPI 3.x specification
|
||||||
into concrete FastAPI routes. It enforces a strict one-to-one mapping
|
into concrete FastAPI routes. It enforces a strict one-to-one mapping
|
||||||
between OpenAPI operations and Python handler functions using operationId.
|
between OpenAPI operations and Python handler functions using `operationId`.
|
||||||
|
|
||||||
Core responsibility
|
Notes:
|
||||||
-------------------
|
**Core Responsibility:**
|
||||||
- Read path + method definitions from an OpenAPI specification
|
|
||||||
- Resolve each operationId to a Python callable
|
|
||||||
- Register routes with FastAPI using APIRoute
|
|
||||||
- Fail fast when contract violations are detected
|
|
||||||
|
|
||||||
Design constraints
|
- Read path + method definitions from an OpenAPI specification.
|
||||||
------------------
|
- Resolve each `operationId` to a Python callable.
|
||||||
- All routes MUST be declared in the OpenAPI specification.
|
- Register routes with FastAPI using `APIRoute`.
|
||||||
- All OpenAPI operations MUST define an operationId.
|
- Fail fast when contract violations are detected.
|
||||||
- Every operationId MUST resolve to a handler function.
|
|
||||||
- Handlers are plain Python callables (no decorators required).
|
|
||||||
- No implicit route creation or inference is allowed.
|
|
||||||
|
|
||||||
This module intentionally does NOT:
|
**Design Constraints:**
|
||||||
-------------------------------
|
|
||||||
- Perform request or response validation
|
|
||||||
- Generate Pydantic models
|
|
||||||
- Modify FastAPI dependency injection
|
|
||||||
- Interpret OpenAPI semantics beyond routing metadata
|
|
||||||
|
|
||||||
Those concerns belong to other layers or tooling.
|
- All routes MUST be declared in the OpenAPI specification.
|
||||||
|
- All OpenAPI operations MUST define an `operationId`.
|
||||||
|
- Every `operationId` MUST resolve to a handler function.
|
||||||
|
- Handlers are plain Python callables (no decorators required).
|
||||||
|
- No implicit route creation or inference is allowed.
|
||||||
|
|
||||||
|
**Constraints:**
|
||||||
|
|
||||||
|
- This module intentionally does NOT:
|
||||||
|
- Perform request or response validation.
|
||||||
|
- Generate Pydantic models.
|
||||||
|
- Modify FastAPI dependency injection.
|
||||||
|
- Interpret OpenAPI semantics beyond routing metadata.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from fastapi.routing import APIRoute
|
from fastapi.routing import APIRoute
|
||||||
|
|
||||||
from .errors import MissingOperationHandler
|
from .errors import MissingOperationHandler
|
||||||
|
|
||||||
|
|
||||||
def bind_routes(app, spec: dict, routes_module) -> None:
|
def bind_routes(
|
||||||
|
app,
|
||||||
|
spec: dict,
|
||||||
|
routes_module,
|
||||||
|
security_deps: dict[str, list[Any]] | None = None,
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Bind OpenAPI operations to FastAPI routes.
|
Bind OpenAPI operations to FastAPI routes.
|
||||||
|
|
||||||
Iterates through the OpenAPI specification paths and methods,
|
Args:
|
||||||
resolves each operationId to a handler function, and registers
|
app (fastapi.FastAPI):
|
||||||
a corresponding APIRoute on the FastAPI application.
|
The FastAPI application instance to which routes will be added.
|
||||||
|
spec (dict):
|
||||||
|
Parsed OpenAPI 3.x specification dictionary.
|
||||||
|
routes_module (module):
|
||||||
|
Python module containing handler functions. Each handler's name MUST
|
||||||
|
exactly match an OpenAPI `operationId`.
|
||||||
|
security_deps (dict | None):
|
||||||
|
Optional mapping of ``METHOD:/path`` → ``list[Depends(...)]``
|
||||||
|
generated from the spec's ``securitySchemes`` and per-operation
|
||||||
|
``security`` fields.
|
||||||
|
|
||||||
Parameters
|
Raises:
|
||||||
----------
|
MissingOperationHandler:
|
||||||
app : fastapi.FastAPI
|
If an ``operationId`` is missing from the spec or if no corresponding
|
||||||
The FastAPI application instance to which routes will be added.
|
handler function exists in the routes module.
|
||||||
|
|
||||||
spec : dict
|
Notes:
|
||||||
Parsed OpenAPI 3.x specification dictionary.
|
**Responsibilities:**
|
||||||
|
|
||||||
routes_module : module
|
- Iterates through the OpenAPI specification paths and methods.
|
||||||
Python module containing handler functions. Each handler's
|
- Resolves each ``operationId`` to a handler function, and registers
|
||||||
name MUST exactly match an OpenAPI operationId.
|
a corresponding ``APIRoute`` on the FastAPI application.
|
||||||
|
- Injects FastAPI ``Depends()`` for each security requirement found
|
||||||
|
on the operation or inherited from the top-level ``security`` field.
|
||||||
|
|
||||||
Raises
|
**Guarantees:**
|
||||||
------
|
|
||||||
MissingOperationHandler
|
|
||||||
If an operationId is missing from the spec or if no corresponding
|
|
||||||
handler function exists in the routes module.
|
|
||||||
|
|
||||||
Behavior guarantees
|
- Route registration is deterministic and spec-driven. No route
|
||||||
-------------------
|
decorators are required or supported. Handler resolution errors
|
||||||
- Route registration is deterministic and spec-driven.
|
surface at application startup.
|
||||||
- No route decorators are required or supported.
|
|
||||||
- Handler resolution errors surface at application startup.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
paths = spec.get("paths", {})
|
paths = spec.get("paths", {})
|
||||||
|
security_deps = security_deps or {}
|
||||||
|
|
||||||
|
http_methods = {"get", "put", "post", "delete", "options", "head", "patch", "trace"}
|
||||||
|
|
||||||
for path, methods in paths.items():
|
for path, methods in paths.items():
|
||||||
for http_method, operation in methods.items():
|
for http_method, operation in methods.items():
|
||||||
|
if http_method.lower() not in http_methods or not isinstance(
|
||||||
|
operation, dict
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
operation_id = operation.get("operationId")
|
operation_id = operation.get("operationId")
|
||||||
if not operation_id:
|
if not operation_id:
|
||||||
@@ -90,12 +108,16 @@ def bind_routes(app, spec: dict, routes_module) -> None:
|
|||||||
path=path,
|
path=path,
|
||||||
method=http_method,
|
method=http_method,
|
||||||
operation_id=operation_id,
|
operation_id=operation_id,
|
||||||
)
|
) from None
|
||||||
|
|
||||||
|
key = f"{http_method.upper()}:{path}"
|
||||||
|
deps = security_deps.get(key, [])
|
||||||
|
|
||||||
route = APIRoute(
|
route = APIRoute(
|
||||||
path=path,
|
path=path,
|
||||||
endpoint=endpoint,
|
endpoint=endpoint,
|
||||||
methods=[http_method.upper()],
|
methods=[http_method.upper()],
|
||||||
|
dependencies=deps,
|
||||||
name=operation_id,
|
name=operation_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
5
openapi_first/binder.pyi
Normal file
5
openapi_first/binder.pyi
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
def bind_routes(app: FastAPI, spec: dict[str, Any], routes_module: Any) -> None: ...
|
||||||
@@ -1,89 +1,200 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.cli
|
|
||||||
========================
|
|
||||||
|
|
||||||
Command-line interface for FastAPI OpenAPI-first scaffolding utilities.
|
Command-line interface for FastAPI OpenAPI-first scaffolding utilities.
|
||||||
|
|
||||||
This module provides a small, focused CLI intended to help developers
|
---
|
||||||
quickly bootstrap OpenAPI-first FastAPI services using bundled project
|
|
||||||
templates.
|
|
||||||
|
|
||||||
Currently supported scaffolds:
|
## Summary
|
||||||
- Health check service (minimal OpenAPI-first application)
|
|
||||||
|
|
||||||
The CLI copies versioned templates packaged with the library into a
|
This CLI bootstraps OpenAPI-first FastAPI applications from versioned,
|
||||||
user-specified directory, allowing rapid local development without
|
bundled templates packaged with the library.
|
||||||
manual setup.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
|
||||||
from importlib import resources
|
from importlib import resources
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
DEFAULT_TEMPLATE = "health_app"
|
||||||
|
|
||||||
|
|
||||||
def copy_health_app_template(target_dir: Path) -> None:
|
def available_templates() -> list[str]:
|
||||||
"""
|
"""
|
||||||
Copy the bundled OpenAPI-first health app template into a directory.
|
Return a list of available application templates.
|
||||||
|
|
||||||
This function copies a fully working, minimal OpenAPI-first FastAPI
|
Returns:
|
||||||
health check application from the package's embedded templates into
|
list[str]:
|
||||||
the specified target directory.
|
Sorted list of template names found in the internal templates directory.
|
||||||
|
"""
|
||||||
|
root = resources.files("openapi_first.templates")
|
||||||
|
return sorted(
|
||||||
|
item.name
|
||||||
|
for item in root.iterdir()
|
||||||
|
if item.is_dir() and not item.name.startswith("_")
|
||||||
|
)
|
||||||
|
|
||||||
The target directory will be created if it does not already exist.
|
|
||||||
Existing files may be overwritten.
|
|
||||||
|
|
||||||
Parameters
|
def copy_template(template: str, target_dir: Path) -> None:
|
||||||
----------
|
"""
|
||||||
target_dir : pathlib.Path
|
Copy a bundled OpenAPI-first application template into a directory.
|
||||||
Destination directory into which the health app template
|
|
||||||
should be copied.
|
|
||||||
|
|
||||||
Raises
|
Args:
|
||||||
------
|
template (str):
|
||||||
FileNotFoundError
|
Name of the template to copy.
|
||||||
If the bundled health app template cannot be located.
|
target_dir (Path):
|
||||||
|
Filesystem path where the template should be copied.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
FileNotFoundError:
|
||||||
|
If the requested template does not exist.
|
||||||
"""
|
"""
|
||||||
target_dir = target_dir.resolve()
|
target_dir = target_dir.resolve()
|
||||||
target_dir.mkdir(parents=True, exist_ok=True)
|
target_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
with resources.files("openapi_first.templates").joinpath(
|
root = resources.files("openapi_first.templates")
|
||||||
"health_app"
|
|
||||||
) as src:
|
if template not in available_templates():
|
||||||
shutil.copytree(src, target_dir, dirs_exist_ok=True)
|
raise FileNotFoundError(
|
||||||
|
f"Template '{template}' not found. "
|
||||||
|
f"Available templates: {', '.join(available_templates())}"
|
||||||
|
)
|
||||||
|
|
||||||
|
src = root / template
|
||||||
|
|
||||||
|
with resources.as_file(src) as path:
|
||||||
|
shutil.copytree(path, target_dir, dirs_exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""
|
|
||||||
Entry point for the FastAPI OpenAPI-first CLI.
|
|
||||||
|
|
||||||
Parses command-line arguments and initializes a new OpenAPI-first
|
|
||||||
health check application by copying the bundled template into the
|
|
||||||
specified directory.
|
|
||||||
|
|
||||||
If no target path is provided, the scaffold is created in a directory
|
|
||||||
named ``health-app`` in the current working directory.
|
|
||||||
|
|
||||||
Example
|
|
||||||
-------
|
|
||||||
Create a health app in the default directory::
|
|
||||||
|
|
||||||
openapi-first
|
|
||||||
|
|
||||||
Create a health app in a custom directory::
|
|
||||||
|
|
||||||
openapi-first my-service
|
|
||||||
"""
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="FastAPI OpenAPI-first scaffolding tools"
|
description="FastAPI OpenAPI-first developer tools"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
subparsers = parser.add_subparsers(dest="command", help="Command to execute")
|
||||||
|
|
||||||
|
# Scaffold command
|
||||||
|
scaffold_parser = subparsers.add_parser(
|
||||||
|
"scaffold", help="Scaffold a new OpenAPI-first FastAPI application"
|
||||||
|
)
|
||||||
|
scaffold_parser.add_argument(
|
||||||
|
"template",
|
||||||
|
nargs="?",
|
||||||
|
default=DEFAULT_TEMPLATE,
|
||||||
|
help=f"Template name (default: {DEFAULT_TEMPLATE})",
|
||||||
|
)
|
||||||
|
scaffold_parser.add_argument(
|
||||||
"path",
|
"path",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
default="health-app",
|
default=None,
|
||||||
help="Target directory for the health app",
|
help="Target directory (defaults to template name)",
|
||||||
|
)
|
||||||
|
scaffold_parser.add_argument(
|
||||||
|
"--list",
|
||||||
|
action="store_true",
|
||||||
|
help="List available templates and exit",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Models command
|
||||||
|
models_parser = subparsers.add_parser(
|
||||||
|
"models", help="Generate Pydantic models from an OpenAPI specification"
|
||||||
|
)
|
||||||
|
models_parser.add_argument(
|
||||||
|
"spec",
|
||||||
|
help="Path to the OpenAPI specification file",
|
||||||
|
)
|
||||||
|
models_parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--output",
|
||||||
|
required=True,
|
||||||
|
help="Path to the output Python file",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Routes command
|
||||||
|
routes_parser = subparsers.add_parser(
|
||||||
|
"routes",
|
||||||
|
help="Generate route handler stubs from an OpenAPI specification",
|
||||||
|
)
|
||||||
|
routes_parser.add_argument(
|
||||||
|
"spec",
|
||||||
|
help="Path to the OpenAPI specification file",
|
||||||
|
)
|
||||||
|
routes_parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--output-dir",
|
||||||
|
required=True,
|
||||||
|
help="Directory where route files will be created",
|
||||||
|
)
|
||||||
|
routes_parser.add_argument(
|
||||||
|
"--use-models",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Import Pydantic models for request bodies",
|
||||||
|
)
|
||||||
|
routes_parser.add_argument(
|
||||||
|
"--models-module",
|
||||||
|
default="models",
|
||||||
|
help="Python module path for models (default: models)",
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
copy_health_app_template(Path(args.path))
|
|
||||||
print(f"Health app created at {args.path}")
|
if args.command == "models":
|
||||||
|
from .codegen import generate_models
|
||||||
|
|
||||||
|
try:
|
||||||
|
generate_models(Path(args.spec), Path(args.output))
|
||||||
|
print(f"Models generated successfully at {args.output}")
|
||||||
|
except Exception as exc:
|
||||||
|
raise SystemExit(str(exc)) from exc
|
||||||
|
return
|
||||||
|
|
||||||
|
if args.command == "routes":
|
||||||
|
from .codegen import generate_routes
|
||||||
|
|
||||||
|
try:
|
||||||
|
files = generate_routes(
|
||||||
|
spec_path=Path(args.spec),
|
||||||
|
output_dir=Path(args.output_dir),
|
||||||
|
use_models=args.use_models,
|
||||||
|
models_module=args.models_module,
|
||||||
|
)
|
||||||
|
print(f"Generated {len(files)} route file(s):")
|
||||||
|
for f in files:
|
||||||
|
print(f" {f}")
|
||||||
|
except Exception as exc:
|
||||||
|
raise SystemExit(str(exc)) from exc
|
||||||
|
return
|
||||||
|
|
||||||
|
# Default to scaffold if no command or scaffold command
|
||||||
|
if args.command == "scaffold" or args.command is None:
|
||||||
|
# Handle the case where someone uses the old CLI style (openapi-first template path)
|
||||||
|
# argparse with subparsers might not automatically handle this if positional args are passed
|
||||||
|
# but let's assume we want to encourage the new style.
|
||||||
|
|
||||||
|
# If no command was provided but positional args were, they might be for scaffolding
|
||||||
|
# This is a bit tricky with argparse subparsers.
|
||||||
|
# For simplicity, let's just support the new explicit commands.
|
||||||
|
|
||||||
|
if args.command is None and not any(vars(args).values()):
|
||||||
|
parser.print_help()
|
||||||
|
return
|
||||||
|
|
||||||
|
if getattr(args, "list", False):
|
||||||
|
for name in available_templates():
|
||||||
|
print(name)
|
||||||
|
return
|
||||||
|
|
||||||
|
template = getattr(args, "template", DEFAULT_TEMPLATE)
|
||||||
|
path_arg = getattr(args, "path", None)
|
||||||
|
target = Path(path_arg or template.replace("_", "-"))
|
||||||
|
|
||||||
|
try:
|
||||||
|
copy_template(template, target)
|
||||||
|
print(f"Template '{template}' created at {target}")
|
||||||
|
except Exception as exc:
|
||||||
|
raise SystemExit(str(exc)) from exc
|
||||||
|
return
|
||||||
|
|
||||||
|
parser.print_help()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -1,4 +1,38 @@
|
|||||||
from typing import Any, Callable, Dict, Optional
|
"""
|
||||||
|
# Summary
|
||||||
|
|
||||||
|
OpenAPI-first HTTP client for contract-driven services.
|
||||||
|
|
||||||
|
This module provides `OpenAPIClient`, a thin, strict HTTP client that
|
||||||
|
derives all callable operations directly from an OpenAPI 3.x specification.
|
||||||
|
|
||||||
|
It is the client counterpart to `OpenAPIFirstApp`.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
**Core Principles:**
|
||||||
|
|
||||||
|
- The OpenAPI specification is the single source of truth
|
||||||
|
- Each operationId becomes a callable Python method
|
||||||
|
- No implicit schema mutation or inference
|
||||||
|
- No code generation step
|
||||||
|
- Minimal abstraction over httpx
|
||||||
|
|
||||||
|
**Responsibilities:**
|
||||||
|
|
||||||
|
- Parses an OpenAPI 3.x specification
|
||||||
|
- Dynamically creates one callable per operationId
|
||||||
|
- Enforces presence of servers, paths, and operationId
|
||||||
|
- Formats path parameters safely
|
||||||
|
- Handles JSON request bodies explicitly
|
||||||
|
- Returns raw `httpx.Response` objects
|
||||||
|
|
||||||
|
**Constraints:**
|
||||||
|
|
||||||
|
- This module intentionally does NOT: Generate client code, validate request/response schemas, deserialize responses, retry requests, implement authentication helpers, or assume non-2xx responses are failures.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
@@ -7,29 +41,77 @@ from .errors import OpenAPIFirstError
|
|||||||
|
|
||||||
|
|
||||||
class OpenAPIClientError(OpenAPIFirstError):
|
class OpenAPIClientError(OpenAPIFirstError):
|
||||||
"""Raised when an OpenAPI client operation fails."""
|
"""
|
||||||
|
Raised when an OpenAPI client operation fails.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class OpenAPIClient:
|
class OpenAPIClient:
|
||||||
"""
|
"""
|
||||||
OpenAPI-first HTTP client (httpx-based).
|
OpenAPI-first HTTP client (`httpx`-based).
|
||||||
|
|
||||||
- One callable per operationId
|
Notes:
|
||||||
- Explicit parameters (path, query, headers, body)
|
**Responsibilities:**
|
||||||
- No implicit schema inference or mutation
|
|
||||||
|
- This client derives all callable methods directly from an
|
||||||
|
OpenAPI 3.x specification. Each `operationId` becomes a method
|
||||||
|
on the client instance.
|
||||||
|
|
||||||
|
**Guarantees:**
|
||||||
|
|
||||||
|
- One callable per `operationId`.
|
||||||
|
- Explicit parameters (path, query, headers, body).
|
||||||
|
- No implicit schema inference or mutation.
|
||||||
|
- Returns raw `httpx.Response` objects.
|
||||||
|
- No response validation or deserialization.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```python
|
||||||
|
from openapi_first import loader, client
|
||||||
|
|
||||||
|
spec = loader.load_openapi("openapi.yaml")
|
||||||
|
|
||||||
|
api = client.OpenAPIClient(
|
||||||
|
spec=spec,
|
||||||
|
base_url="http://localhost:8000",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Call operationId: getUser
|
||||||
|
response = api.getUser(
|
||||||
|
path_params={"user_id": 123}
|
||||||
|
)
|
||||||
|
|
||||||
|
print(response.status_code)
|
||||||
|
print(response.json())
|
||||||
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
spec: dict[str, Any],
|
spec: dict[str, Any],
|
||||||
base_url: Optional[str] = None,
|
base_url: str | None = None,
|
||||||
client: Optional[httpx.Client] = None,
|
client: httpx.Client | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""
|
||||||
|
Initialize the OpenAPI client.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
spec (dict[str, Any]):
|
||||||
|
Parsed OpenAPI 3.x specification.
|
||||||
|
base_url (str, optional):
|
||||||
|
Base URL of the target service. If omitted, the first entry in the OpenAPI `servers` list is used.
|
||||||
|
client (httpx.Client, optional):
|
||||||
|
Optional preconfigured httpx client instance.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
OpenAPIClientError:
|
||||||
|
If no servers are defined, spec has no paths, operationIds are missing/duplicate, or required parameters are missing.
|
||||||
|
"""
|
||||||
self.spec = spec
|
self.spec = spec
|
||||||
self.base_url = base_url or self._resolve_base_url(spec)
|
self.base_url = base_url or self._resolve_base_url(spec)
|
||||||
self.client = client or httpx.Client(base_url=self.base_url)
|
self.client = client or httpx.Client(base_url=self.base_url)
|
||||||
|
|
||||||
self._operations: Dict[str, Callable[..., httpx.Response]] = {}
|
self._operations: dict[str, Callable[..., httpx.Response]] = {}
|
||||||
self._build_operations()
|
self._build_operations()
|
||||||
|
|
||||||
# ------------------------------------------------------------------ #
|
# ------------------------------------------------------------------ #
|
||||||
@@ -42,7 +124,7 @@ class OpenAPIClient:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise AttributeError(f"No such operationId: {name}") from None
|
raise AttributeError(f"No such operationId: {name}") from None
|
||||||
|
|
||||||
def operations(self) -> Dict[str, Callable[..., httpx.Response]]:
|
def operations(self) -> dict[str, Callable[..., httpx.Response]]:
|
||||||
return dict(self._operations)
|
return dict(self._operations)
|
||||||
|
|
||||||
# ------------------------------------------------------------------ #
|
# ------------------------------------------------------------------ #
|
||||||
@@ -68,7 +150,13 @@ class OpenAPIClient:
|
|||||||
for path, path_item in paths.items():
|
for path, path_item in paths.items():
|
||||||
for method, operation in path_item.items():
|
for method, operation in path_item.items():
|
||||||
if method.lower() not in {
|
if method.lower() not in {
|
||||||
"get", "post", "put", "patch", "delete", "head", "options"
|
"get",
|
||||||
|
"post",
|
||||||
|
"put",
|
||||||
|
"patch",
|
||||||
|
"delete",
|
||||||
|
"head",
|
||||||
|
"options",
|
||||||
}:
|
}:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -100,11 +188,11 @@ class OpenAPIClient:
|
|||||||
|
|
||||||
def call(
|
def call(
|
||||||
*,
|
*,
|
||||||
path_params: Optional[dict[str, Any]] = None,
|
path_params: dict[str, Any] | None = None,
|
||||||
query: Optional[dict[str, Any]] = None,
|
query: dict[str, Any] | None = None,
|
||||||
headers: Optional[dict[str, str]] = None,
|
headers: dict[str, str] | None = None,
|
||||||
body: Optional[Any] = None,
|
body: Any | None = None,
|
||||||
timeout: Optional[float] = None,
|
timeout: float | None = None,
|
||||||
) -> httpx.Response:
|
) -> httpx.Response:
|
||||||
url = self._build_url(path, path_params or {})
|
url = self._build_url(path, path_params or {})
|
||||||
|
|
||||||
@@ -147,9 +235,7 @@ class OpenAPIClient:
|
|||||||
try:
|
try:
|
||||||
formatted_path = path.format(**path_params)
|
formatted_path = path.format(**path_params)
|
||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
raise OpenAPIClientError(
|
raise OpenAPIClientError(f"Missing path parameter: {exc.args[0]}") from exc
|
||||||
f"Missing path parameter: {exc.args[0]}"
|
|
||||||
) from exc
|
|
||||||
|
|
||||||
return urljoin(self.base_url, formatted_path.lstrip("/"))
|
return urljoin(self.base_url, formatted_path.lstrip("/"))
|
||||||
|
|
||||||
|
|||||||
21
openapi_first/client.pyi
Normal file
21
openapi_first/client.pyi
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
from .errors import OpenAPIFirstError
|
||||||
|
|
||||||
|
class OpenAPIClientError(OpenAPIFirstError): ...
|
||||||
|
|
||||||
|
class OpenAPIClient:
|
||||||
|
spec: dict[str, Any]
|
||||||
|
base_url: str
|
||||||
|
client: httpx.Client
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
spec: dict[str, Any],
|
||||||
|
base_url: str | None = ...,
|
||||||
|
client: httpx.Client | None = ...,
|
||||||
|
) -> None: ...
|
||||||
|
def __getattr__(self, name: str) -> Callable[..., httpx.Response]: ...
|
||||||
|
def operations(self) -> dict[str, Callable[..., httpx.Response]]: ...
|
||||||
54
openapi_first/codegen.py
Normal file
54
openapi_first/codegen.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
"""
|
||||||
|
# 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"]
|
||||||
317
openapi_first/codegen_routes.py
Normal file
317
openapi_first/codegen_routes.py
Normal file
@@ -0,0 +1,317 @@
|
|||||||
|
"""
|
||||||
|
Route handler code generation from OpenAPI specifications.
|
||||||
|
|
||||||
|
This module generates Python route handler stubs from an OpenAPI 3.x
|
||||||
|
specification. Each resource (derived from the first path segment)
|
||||||
|
gets its own file under the output directory. Every OpenAPI operation
|
||||||
|
must define an ``operationId``, which becomes the handler function name.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
**Design constraints:**
|
||||||
|
|
||||||
|
- ``operationId`` is required on every operation (matching
|
||||||
|
``binder.bind_routes``).
|
||||||
|
- Handlers are stubs raising ``NotImplementedError``.
|
||||||
|
- Sub-resources (e.g. ``/pets/{id}/photo``) are grouped with their
|
||||||
|
parent resource (``pets``).
|
||||||
|
- Parameter types and defaults are inferred from the spec.
|
||||||
|
- ``response: Response`` is injected for non-200 success codes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from .loader import load_openapi
|
||||||
|
|
||||||
|
|
||||||
|
def generate_routes(
|
||||||
|
spec_path: Path,
|
||||||
|
output_dir: Path,
|
||||||
|
*,
|
||||||
|
use_models: bool = False,
|
||||||
|
models_module: str = "models",
|
||||||
|
) -> list[Path]:
|
||||||
|
"""
|
||||||
|
Generate route handler stubs from an OpenAPI specification.
|
||||||
|
|
||||||
|
Creates one ``<resource>.py`` file per resource in *output_dir*.
|
||||||
|
Resources are derived from the first path segment (e.g. ``/pets``
|
||||||
|
and ``/pets/{id}`` both group under ``pets``).
|
||||||
|
|
||||||
|
Args:
|
||||||
|
spec_path:
|
||||||
|
Path to the OpenAPI specification file (YAML or JSON).
|
||||||
|
output_dir:
|
||||||
|
Directory where the generated route files are written.
|
||||||
|
Created automatically if it does not exist.
|
||||||
|
use_models:
|
||||||
|
If ``True``, import Pydantic models from *models_module*
|
||||||
|
for request-body schemas referenced via ``$ref``.
|
||||||
|
models_module:
|
||||||
|
Dotted Python module path from which to import models
|
||||||
|
(e.g. ``"models"``, ``"app.models"``).
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[Path]:
|
||||||
|
Absolute paths of every generated route file.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
OpenAPISpecLoadError:
|
||||||
|
If the spec cannot be loaded or validated.
|
||||||
|
ValueError:
|
||||||
|
If any operation is missing ``operationId``.
|
||||||
|
"""
|
||||||
|
spec = load_openapi(spec_path)
|
||||||
|
output_dir = Path(output_dir).resolve()
|
||||||
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
# Group paths by resource (first non-param path segment)
|
||||||
|
resources_map: dict[str, list[tuple[str, str, dict[str, Any]]]] = {}
|
||||||
|
|
||||||
|
paths = spec.get("paths", {})
|
||||||
|
for path, methods in paths.items():
|
||||||
|
segments = [s for s in path.split("/") if s and not s.startswith("{")]
|
||||||
|
if not segments:
|
||||||
|
continue
|
||||||
|
resource = segments[0]
|
||||||
|
if resource not in resources_map:
|
||||||
|
resources_map[resource] = []
|
||||||
|
|
||||||
|
for http_method, operation in methods.items():
|
||||||
|
if http_method.startswith("x-"):
|
||||||
|
continue
|
||||||
|
resources_map[resource].append((path, http_method, operation))
|
||||||
|
|
||||||
|
generated_files: list[Path] = []
|
||||||
|
|
||||||
|
for resource in sorted(resources_map):
|
||||||
|
operations = resources_map[resource]
|
||||||
|
_validate_operations(resource, operations)
|
||||||
|
|
||||||
|
file_path = output_dir / f"{resource}.py"
|
||||||
|
content = _generate_resource_file(
|
||||||
|
resource=resource,
|
||||||
|
operations=operations,
|
||||||
|
spec_path=str(spec_path),
|
||||||
|
use_models=use_models,
|
||||||
|
models_module=models_module,
|
||||||
|
)
|
||||||
|
file_path.write_text(content, encoding="utf-8")
|
||||||
|
generated_files.append(file_path)
|
||||||
|
|
||||||
|
return generated_files
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Internal helpers
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_TYPE_MAP: dict[str, str] = {
|
||||||
|
"integer": "int",
|
||||||
|
"number": "float",
|
||||||
|
"boolean": "bool",
|
||||||
|
"string": "str",
|
||||||
|
"array": "list",
|
||||||
|
"object": "dict",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_operations(
|
||||||
|
resource: str, operations: list[tuple[str, str, dict[str, Any]]]
|
||||||
|
) -> None:
|
||||||
|
"""Ensure every operation has an operationId."""
|
||||||
|
for path, http_method, operation in operations:
|
||||||
|
if not operation.get("operationId"):
|
||||||
|
raise ValueError(
|
||||||
|
f"Missing operationId for {http_method.upper()} {path} "
|
||||||
|
f"in resource '{resource}'. "
|
||||||
|
"All operations must have an explicit operationId."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_type(schema: dict[str, Any]) -> str:
|
||||||
|
"""Map an OpenAPI schema type to a Python type annotation."""
|
||||||
|
openapi_type = schema.get("type", "")
|
||||||
|
return _TYPE_MAP.get(openapi_type, "str")
|
||||||
|
|
||||||
|
|
||||||
|
def _get_request_body_schema(operation: dict[str, Any]) -> str | None:
|
||||||
|
"""Extract the ``$ref`` schema name from a request body, if any."""
|
||||||
|
request_body = operation.get("requestBody")
|
||||||
|
if not request_body:
|
||||||
|
return None
|
||||||
|
|
||||||
|
content = request_body.get("content", {})
|
||||||
|
for media_info in content.values():
|
||||||
|
schema = media_info.get("schema", {})
|
||||||
|
ref = schema.get("$ref", "")
|
||||||
|
if ref:
|
||||||
|
return str(ref.rsplit("/", 1)[-1])
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _get_success_status(operation: dict[str, Any]) -> str:
|
||||||
|
"""Return the primary success status code (200, 201, 204, or default)."""
|
||||||
|
responses = operation.get("responses", {})
|
||||||
|
for code in ("201", "200", "204"):
|
||||||
|
if code in responses:
|
||||||
|
return code
|
||||||
|
if "default" in responses:
|
||||||
|
return "default"
|
||||||
|
return "200"
|
||||||
|
|
||||||
|
|
||||||
|
def _needs_any(operations: list[tuple[str, str, dict[str, Any]]]) -> bool:
|
||||||
|
"""Check if any operation uses a type that requires `from typing import Any`."""
|
||||||
|
for _, _, op in operations:
|
||||||
|
for param in op.get("parameters", []):
|
||||||
|
schema = param.get("schema", {})
|
||||||
|
if schema.get("type", "") not in _TYPE_MAP:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# File / function generation
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def _generate_resource_file(
|
||||||
|
resource: str,
|
||||||
|
operations: list[tuple[str, str, dict[str, Any]]],
|
||||||
|
spec_path: str,
|
||||||
|
use_models: bool,
|
||||||
|
models_module: str,
|
||||||
|
) -> str:
|
||||||
|
"""Assemble the full Python source for a single resource file."""
|
||||||
|
op_ids = [op.get("operationId", "") for _, _, op in operations]
|
||||||
|
lines: list[str] = [
|
||||||
|
f'"""Route handlers for the {resource} resource.',
|
||||||
|
"",
|
||||||
|
f"Generated from OpenAPI spec: {spec_path}",
|
||||||
|
f'Bind via operationIds: {", ".join(op_ids)}',
|
||||||
|
'"""',
|
||||||
|
"",
|
||||||
|
"from fastapi import Response, HTTPException",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Conditional typing import
|
||||||
|
if _needs_any(operations):
|
||||||
|
lines.append("from typing import Any")
|
||||||
|
|
||||||
|
# Conditional model imports
|
||||||
|
if use_models:
|
||||||
|
schemas_needed: set[str] = set()
|
||||||
|
for _, _, op in operations:
|
||||||
|
schema = _get_request_body_schema(op)
|
||||||
|
if schema:
|
||||||
|
schemas_needed.add(schema)
|
||||||
|
if schemas_needed:
|
||||||
|
lines.append(
|
||||||
|
f"from {models_module} import {', '.join(sorted(schemas_needed))}"
|
||||||
|
)
|
||||||
|
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
|
for path, http_method, operation in operations:
|
||||||
|
lines.append("")
|
||||||
|
lines.extend(_generate_handler(path, http_method, operation, use_models))
|
||||||
|
|
||||||
|
lines.append("")
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def _generate_handler(
|
||||||
|
path: str,
|
||||||
|
http_method: str,
|
||||||
|
operation: dict[str, Any],
|
||||||
|
use_models: bool,
|
||||||
|
) -> list[str]:
|
||||||
|
"""Build the source lines for a single handler function."""
|
||||||
|
operation_id = operation.get("operationId", "")
|
||||||
|
summary = operation.get("summary", f"{http_method.upper()} {path}")
|
||||||
|
|
||||||
|
params: list[str] = []
|
||||||
|
path_params: list[str] = []
|
||||||
|
query_params: list[str] = []
|
||||||
|
|
||||||
|
for param in operation.get("parameters", []):
|
||||||
|
name: str = param.get("name", "")
|
||||||
|
param_in: str = param.get("in", "")
|
||||||
|
schema: dict[str, Any] = param.get("schema", {})
|
||||||
|
param_type: str = _resolve_type(schema)
|
||||||
|
required: bool = param.get("required", False)
|
||||||
|
default_raw = schema.get("default")
|
||||||
|
|
||||||
|
if param_in == "path":
|
||||||
|
path_params.append(f"{name}: {param_type}")
|
||||||
|
elif param_in == "query":
|
||||||
|
if default_raw is not None:
|
||||||
|
default_repr = repr(default_raw)
|
||||||
|
query_params.append(f"{name}: {param_type} = {default_repr}")
|
||||||
|
elif required:
|
||||||
|
query_params.append(f"{name}: {param_type}")
|
||||||
|
else:
|
||||||
|
query_params.append(f"{name}: {param_type} = None")
|
||||||
|
# header / cookie params could be extended here
|
||||||
|
|
||||||
|
params.extend(path_params)
|
||||||
|
params.extend(query_params)
|
||||||
|
|
||||||
|
# Request body
|
||||||
|
schema_name = _get_request_body_schema(operation)
|
||||||
|
if operation.get("requestBody"):
|
||||||
|
if use_models and schema_name:
|
||||||
|
params.append(f"payload: {schema_name}")
|
||||||
|
else:
|
||||||
|
params.append("payload: dict")
|
||||||
|
|
||||||
|
# Inject Response for non-200 success codes
|
||||||
|
success_status = _get_success_status(operation)
|
||||||
|
if success_status in ("201", "204"):
|
||||||
|
params.append("response: Response")
|
||||||
|
|
||||||
|
# Build function body
|
||||||
|
lines: list[str] = []
|
||||||
|
param_str = ", ".join(params)
|
||||||
|
lines.append(f"def {operation_id}({param_str}):")
|
||||||
|
lines.append(f' """{summary}')
|
||||||
|
|
||||||
|
# Document parameters
|
||||||
|
doc_params: list[tuple[str, str, str]] = []
|
||||||
|
for param in operation.get("parameters", []):
|
||||||
|
doc_name: str = param.get("name", "")
|
||||||
|
doc_in: str = param.get("in", "")
|
||||||
|
doc_schema: dict[str, Any] = param.get("schema", {})
|
||||||
|
doc_type: str = _resolve_type(doc_schema)
|
||||||
|
doc_description: str = param.get(
|
||||||
|
"description", doc_schema.get("x-description", "")
|
||||||
|
)
|
||||||
|
if doc_in in ("path", "query"):
|
||||||
|
doc_params.append((doc_name, doc_type, doc_description))
|
||||||
|
|
||||||
|
if doc_params:
|
||||||
|
lines.append("")
|
||||||
|
lines.append(" Parameters")
|
||||||
|
lines.append(" ----------")
|
||||||
|
for pname, ptype, desc in doc_params:
|
||||||
|
if desc:
|
||||||
|
lines.append(f" {pname} : {ptype}")
|
||||||
|
lines.append(f" {desc}")
|
||||||
|
else:
|
||||||
|
lines.append(f" {pname} : {ptype}")
|
||||||
|
|
||||||
|
if operation.get("requestBody"):
|
||||||
|
if use_models and schema_name:
|
||||||
|
lines.append("")
|
||||||
|
lines.append(f" payload : {schema_name}")
|
||||||
|
lines.append(" Request body.")
|
||||||
|
else:
|
||||||
|
lines.append("")
|
||||||
|
lines.append(" payload : dict")
|
||||||
|
lines.append(" Request body.")
|
||||||
|
|
||||||
|
lines.append(' """')
|
||||||
|
lines.append(" raise NotImplementedError")
|
||||||
|
|
||||||
|
return lines
|
||||||
@@ -1,34 +1,38 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.errors
|
# Summary
|
||||||
============================
|
|
||||||
|
|
||||||
Custom exceptions for OpenAPI-first FastAPI applications.
|
Exceptions for OpenAPI-first FastAPI applications.
|
||||||
|
|
||||||
This module defines a small hierarchy of explicit, intention-revealing
|
This module defines a small hierarchy of explicit, intention-revealing
|
||||||
exceptions used to signal contract violations between an OpenAPI
|
exceptions used to signal contract violations between an OpenAPI
|
||||||
specification and its Python implementation.
|
specification and its Python implementation.
|
||||||
|
|
||||||
Design principles
|
Notes:
|
||||||
-----------------
|
**Design Principles:**
|
||||||
- Errors represent *programmer mistakes*, not runtime conditions.
|
|
||||||
- All errors are raised during application startup.
|
|
||||||
- Messages are actionable and suitable for CI/CD output.
|
|
||||||
- Exceptions are explicit rather than reused from generic built-ins.
|
|
||||||
|
|
||||||
These errors should normally cause immediate application failure.
|
- Errors represent programmer mistakes, not runtime conditions.
|
||||||
|
- All errors are raised during application startup.
|
||||||
|
- Messages are actionable and suitable for CI/CD output.
|
||||||
|
- Exceptions are explicit rather than reused from generic built-ins.
|
||||||
|
|
||||||
|
These errors should normally cause immediate application failure.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class OpenAPIFirstError(Exception):
|
class OpenAPIFirstError(Exception):
|
||||||
"""
|
"""
|
||||||
Base exception for all OpenAPI-first enforcement errors.
|
Base exception for all OpenAPI-first enforcement errors.
|
||||||
|
|
||||||
This exception exists to allow callers, test suites, and CI pipelines
|
Notes:
|
||||||
to catch and distinguish OpenAPI contract violations from unrelated
|
**Responsibilities:**
|
||||||
runtime errors.
|
|
||||||
|
|
||||||
All exceptions raised by the OpenAPI-first core should inherit from
|
- This exception exists to allow callers, test suites, and CI
|
||||||
this type.
|
pipelines to catch and distinguish OpenAPI contract violations
|
||||||
|
from unrelated runtime errors.
|
||||||
|
- All exceptions raised by the OpenAPI-first core should inherit
|
||||||
|
from this type.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -36,27 +40,31 @@ class MissingOperationHandler(OpenAPIFirstError):
|
|||||||
"""
|
"""
|
||||||
Raised when an OpenAPI operation cannot be resolved to a handler.
|
Raised when an OpenAPI operation cannot be resolved to a handler.
|
||||||
|
|
||||||
This error occurs when:
|
Notes:
|
||||||
- An OpenAPI operation does not define an operationId, or
|
**Scenarios:**
|
||||||
- An operationId is defined but no matching function exists in the
|
|
||||||
provided routes module.
|
|
||||||
|
|
||||||
This represents a violation of the OpenAPI-first contract and
|
- An OpenAPI operation does not define an `operationId`.
|
||||||
indicates that the specification and implementation are out of sync.
|
- An `operationId` is defined but no matching function exists in
|
||||||
|
the provided routes module.
|
||||||
|
|
||||||
|
**Guarantees:**
|
||||||
|
|
||||||
|
- This represents a violation of the OpenAPI-first contract and
|
||||||
|
indicates that the specification and implementation are out of
|
||||||
|
sync.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *, path: str, method: str, operation_id: str | None = None):
|
def __init__(self, *, path: str, method: str, operation_id: str | None = None):
|
||||||
"""
|
"""
|
||||||
Parameters
|
Initialize the error.
|
||||||
----------
|
|
||||||
path : str
|
|
||||||
The HTTP path declared in the OpenAPI specification.
|
|
||||||
|
|
||||||
method : str
|
Args:
|
||||||
The HTTP method (as declared in the OpenAPI spec).
|
path (str):
|
||||||
|
The HTTP path declared in the OpenAPI specification.
|
||||||
operation_id : str, optional
|
method (str):
|
||||||
The operationId declared in the OpenAPI spec, if present.
|
The HTTP method (as declared in the OpenAPI spec).
|
||||||
|
operation_id (str, optional):
|
||||||
|
The operationId declared in the OpenAPI spec, if present.
|
||||||
"""
|
"""
|
||||||
if operation_id:
|
if operation_id:
|
||||||
message = (
|
message = (
|
||||||
@@ -64,9 +72,6 @@ class MissingOperationHandler(OpenAPIFirstError):
|
|||||||
f"({method.upper()} {path})"
|
f"({method.upper()} {path})"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
message = (
|
message = f"Missing operationId for operation " f"({method.upper()} {path})"
|
||||||
f"Missing operationId for operation "
|
|
||||||
f"({method.upper()} {path})"
|
|
||||||
)
|
|
||||||
|
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
|
|||||||
6
openapi_first/errors.pyi
Normal file
6
openapi_first/errors.pyi
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class OpenAPIFirstError(Exception): ...
|
||||||
|
|
||||||
|
class MissingOperationHandler(OpenAPIFirstError):
|
||||||
|
def __init__(
|
||||||
|
self, *, path: str, method: str, operation_id: str | None = ...
|
||||||
|
) -> None: ...
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.loaders
|
# Summary
|
||||||
=============================
|
|
||||||
|
|
||||||
OpenAPI specification loading and validation utilities.
|
OpenAPI specification loading and validation utilities.
|
||||||
|
|
||||||
@@ -10,19 +9,21 @@ from disk and validating it before it is used by the application.
|
|||||||
It enforces the principle that an invalid or malformed OpenAPI document
|
It enforces the principle that an invalid or malformed OpenAPI document
|
||||||
must never reach the routing or runtime layers.
|
must never reach the routing or runtime layers.
|
||||||
|
|
||||||
Design principles
|
Notes:
|
||||||
-----------------
|
**Design Principles:**
|
||||||
- OpenAPI is treated as an authoritative contract.
|
|
||||||
- Invalid specifications fail fast at application startup.
|
|
||||||
- Supported formats are JSON and YAML.
|
|
||||||
- Validation errors are surfaced clearly and early.
|
|
||||||
|
|
||||||
This module intentionally does NOT:
|
- OpenAPI is treated as an authoritative contract.
|
||||||
-----------------------------------
|
- Invalid specifications fail fast at application startup.
|
||||||
- Modify the OpenAPI document
|
- Supported formats are JSON and YAML.
|
||||||
- Infer missing fields
|
- Validation errors are surfaced clearly and early.
|
||||||
- Generate models or code
|
|
||||||
- Perform request/response validation at runtime
|
**Constraints:**
|
||||||
|
|
||||||
|
- This module intentionally does NOT:
|
||||||
|
- Modify the OpenAPI document.
|
||||||
|
- Infer missing fields.
|
||||||
|
- Generate models or code.
|
||||||
|
- Perform request/response validation at runtime.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@@ -39,9 +40,13 @@ class OpenAPISpecLoadError(OpenAPIFirstError):
|
|||||||
"""
|
"""
|
||||||
Raised when an OpenAPI specification cannot be loaded or validated.
|
Raised when an OpenAPI specification cannot be loaded or validated.
|
||||||
|
|
||||||
This error indicates that the OpenAPI document is unreadable,
|
Notes:
|
||||||
malformed, or violates the OpenAPI 3.x specification.
|
**Guarantees:**
|
||||||
|
|
||||||
|
- This error indicates that the OpenAPI document is unreadable,
|
||||||
|
malformed, or violates the OpenAPI 3.x specification.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -49,29 +54,27 @@ def load_openapi(path: str | Path) -> dict[str, Any]:
|
|||||||
"""
|
"""
|
||||||
Load and validate an OpenAPI 3.x specification from disk.
|
Load and validate an OpenAPI 3.x specification from disk.
|
||||||
|
|
||||||
The specification is parsed based on file extension and validated
|
Args:
|
||||||
using a strict OpenAPI schema validator. Any error results in an
|
path (str | Path):
|
||||||
immediate exception, preventing application startup.
|
Filesystem path to an OpenAPI specification file. Supported
|
||||||
|
extensions: `.json`, `.yaml`, `.yml`.
|
||||||
|
|
||||||
Parameters
|
Returns:
|
||||||
----------
|
dict[str, Any]:
|
||||||
path : str or pathlib.Path
|
Parsed and validated OpenAPI specification.
|
||||||
Filesystem path to an OpenAPI specification file.
|
|
||||||
Supported extensions:
|
|
||||||
- `.json`
|
|
||||||
- `.yaml`
|
|
||||||
- `.yml`
|
|
||||||
|
|
||||||
Returns
|
Raises:
|
||||||
-------
|
OpenAPISpecLoadError:
|
||||||
dict
|
If the file does not exist, cannot be parsed, or fails OpenAPI
|
||||||
Parsed and validated OpenAPI specification.
|
schema validation.
|
||||||
|
|
||||||
Raises
|
Notes:
|
||||||
------
|
**Guarantees:**
|
||||||
OpenAPISpecLoadError
|
|
||||||
If the file does not exist, cannot be parsed, or fails
|
- The specification is parsed based on file extension and validated
|
||||||
OpenAPI schema validation.
|
using a strict OpenAPI schema validator.
|
||||||
|
- Any error results in an immediate exception, preventing
|
||||||
|
application startup.
|
||||||
"""
|
"""
|
||||||
spec_path = Path(path)
|
spec_path = Path(path)
|
||||||
|
|
||||||
|
|||||||
8
openapi_first/loader.pyi
Normal file
8
openapi_first/loader.pyi
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from .errors import OpenAPIFirstError
|
||||||
|
|
||||||
|
class OpenAPISpecLoadError(OpenAPIFirstError): ...
|
||||||
|
|
||||||
|
def load_openapi(path: str | Path) -> dict[str, Any]: ...
|
||||||
0
openapi_first/py.typed
Normal file
0
openapi_first/py.typed
Normal file
150
openapi_first/security.py
Normal file
150
openapi_first/security.py
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
"""
|
||||||
|
OpenAPI security scheme parsing and auto-generated auth dependencies.
|
||||||
|
|
||||||
|
Reads `securitySchemes` and per-operation `security` from an OpenAPI spec,
|
||||||
|
resolves `{ENV_VAR}` placeholders in `x-` extension fields, and generates
|
||||||
|
FastAPI dependencies for token validation (e.g., Bearer JWT introspection).
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
from fastapi import Depends, HTTPException, Request
|
||||||
|
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||||
|
|
||||||
|
_env_pattern = re.compile(r"\{(\w+)\}")
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_env(value: str) -> str:
|
||||||
|
"""Replace {ENV_VAR} placeholders with values from os.environ."""
|
||||||
|
|
||||||
|
def _replace(m: re.Match[str]) -> str:
|
||||||
|
return os.environ.get(m.group(1), "")
|
||||||
|
|
||||||
|
return _env_pattern.sub(_replace, value)
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_scheme(scheme: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
"""Recursively resolve env vars in all string-valued fields of a scheme."""
|
||||||
|
resolved: dict[str, Any] = {}
|
||||||
|
for key, value in scheme.items():
|
||||||
|
if isinstance(value, str):
|
||||||
|
resolved[key] = _resolve_env(value)
|
||||||
|
elif isinstance(value, dict):
|
||||||
|
resolved[key] = _resolve_scheme(value)
|
||||||
|
else:
|
||||||
|
resolved[key] = value
|
||||||
|
return resolved
|
||||||
|
|
||||||
|
|
||||||
|
def parse_security_schemes(spec: dict[str, Any]) -> dict[str, dict[str, Any]]:
|
||||||
|
"""Extract and resolve environment variables in security schemes."""
|
||||||
|
raw = spec.get("components", {}).get("securitySchemes", {})
|
||||||
|
return {name: _resolve_scheme(scheme) for name, scheme in raw.items()}
|
||||||
|
|
||||||
|
|
||||||
|
def _make_bearer_dependency(introspect_url: str | None) -> Callable[..., Any]:
|
||||||
|
"""
|
||||||
|
Create a FastAPI dependency that validates a Bearer JWT.
|
||||||
|
|
||||||
|
If *introspect_url* is provided the dependency calls that endpoint
|
||||||
|
with ``{"token": "<token>"}`` and expects ``{"active": true, "user": …}``
|
||||||
|
back. The resolved user dict is stored on ``request.state.user``.
|
||||||
|
|
||||||
|
Without an introspection URL the dependency only extracts the raw token
|
||||||
|
and stores it on ``request.state.token`` — no remote validation.
|
||||||
|
"""
|
||||||
|
bearer = HTTPBearer(auto_error=False)
|
||||||
|
|
||||||
|
async def _bearer_dep(
|
||||||
|
request: Request,
|
||||||
|
credentials: HTTPAuthorizationCredentials | None = Depends(bearer),
|
||||||
|
) -> None:
|
||||||
|
if credentials is None:
|
||||||
|
raise HTTPException(status_code=401, detail="Not authenticated")
|
||||||
|
|
||||||
|
token = credentials.credentials
|
||||||
|
|
||||||
|
if introspect_url:
|
||||||
|
try:
|
||||||
|
async with httpx.AsyncClient(timeout=5) as client:
|
||||||
|
resp = await client.post(
|
||||||
|
introspect_url,
|
||||||
|
json={"token": token},
|
||||||
|
)
|
||||||
|
except httpx.RequestError:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=503,
|
||||||
|
detail="Authentication service unavailable",
|
||||||
|
) from None
|
||||||
|
|
||||||
|
if resp.status_code != 200:
|
||||||
|
raise HTTPException(status_code=401, detail="Invalid or expired token")
|
||||||
|
|
||||||
|
body = resp.json()
|
||||||
|
if not body.get("active", False):
|
||||||
|
raise HTTPException(status_code=401, detail="Invalid or expired token")
|
||||||
|
|
||||||
|
request.state.user = body.get("user")
|
||||||
|
else:
|
||||||
|
request.state.token = token
|
||||||
|
|
||||||
|
return _bearer_dep
|
||||||
|
|
||||||
|
|
||||||
|
def _build_dependency(
|
||||||
|
scheme_name: str, scheme: dict[str, Any]
|
||||||
|
) -> Callable[..., Any] | None:
|
||||||
|
"""Return a FastAPI dependency callable for *scheme*, or ``None``."""
|
||||||
|
scheme_type = scheme.get("type")
|
||||||
|
|
||||||
|
if scheme_type == "http" and scheme.get("scheme") == "bearer":
|
||||||
|
server_url = scheme.get("x-server-url", "")
|
||||||
|
introspect_path = scheme.get("x-introspect-path", "/introspect")
|
||||||
|
introspect_url = server_url + introspect_path if server_url else None
|
||||||
|
return _make_bearer_dependency(introspect_url)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def make_security_dependencies(
|
||||||
|
spec: dict[str, Any],
|
||||||
|
security_schemes: dict[str, dict[str, Any]],
|
||||||
|
) -> dict[str, list[Any]]:
|
||||||
|
"""
|
||||||
|
Build a mapping of ``METHOD:/path`` → list of ``Depends(...)``.
|
||||||
|
|
||||||
|
The effective security for each operation is resolved by:
|
||||||
|
|
||||||
|
1. Using the operation-level ``security`` field if present.
|
||||||
|
2. Falling back to the top-level ``security`` field.
|
||||||
|
3. An empty list means *no auth required* for that operation.
|
||||||
|
"""
|
||||||
|
global_security = spec.get("security", [])
|
||||||
|
paths = spec.get("paths", {})
|
||||||
|
|
||||||
|
result: dict[str, list[Any]] = {}
|
||||||
|
|
||||||
|
for path, methods in paths.items():
|
||||||
|
for http_method, operation in methods.items():
|
||||||
|
if http_method.startswith("x-"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
op_security = operation.get("security", global_security)
|
||||||
|
|
||||||
|
depends_list: list[Any] = []
|
||||||
|
for sec_req in op_security:
|
||||||
|
for scheme_name in sec_req:
|
||||||
|
scheme = security_schemes.get(scheme_name)
|
||||||
|
if scheme:
|
||||||
|
dep = _build_dependency(scheme_name, scheme)
|
||||||
|
if dep:
|
||||||
|
depends_list.append(Depends(dep))
|
||||||
|
|
||||||
|
key = f"{http_method.upper()}:{path}"
|
||||||
|
result[key] = depends_list
|
||||||
|
|
||||||
|
return result
|
||||||
18
openapi_first/templates/__init__.py
Normal file
18
openapi_first/templates/__init__.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
"""
|
||||||
|
Application templates for FastAPI OpenAPI First.
|
||||||
|
|
||||||
|
This package contains example and scaffolding templates intended to be
|
||||||
|
copied into user projects via the ``openapi-first`` CLI.
|
||||||
|
|
||||||
|
Templates in this package are:
|
||||||
|
- Reference implementations of OpenAPI-first services
|
||||||
|
- Not part of the ``openapi_first`` public or internal API
|
||||||
|
- Not intended to be imported as runtime dependencies
|
||||||
|
|
||||||
|
The presence of this file exists solely to:
|
||||||
|
- Mark the directory as an explicit Python package
|
||||||
|
- Enable deterministic tooling behavior (documentation, packaging)
|
||||||
|
- Avoid accidental traversal of non-package directories
|
||||||
|
|
||||||
|
No code in this package should be imported by library consumers.
|
||||||
|
"""
|
||||||
99
openapi_first/templates/crud_app/__init__.py
Normal file
99
openapi_first/templates/crud_app/__init__.py
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
"""
|
||||||
|
OpenAPI-first CRUD application template.
|
||||||
|
|
||||||
|
This package contains a complete, minimal example of an OpenAPI-first
|
||||||
|
CRUD service built using the ``openapi_first`` library.
|
||||||
|
|
||||||
|
The application is assembled exclusively from:
|
||||||
|
- an OpenAPI specification (``openapi.yaml``)
|
||||||
|
- a handler namespace implementing CRUD operations (``routes``)
|
||||||
|
- an in-memory mock data store (``data``)
|
||||||
|
|
||||||
|
All HTTP routes, methods, schemas, and operation bindings are defined
|
||||||
|
in the OpenAPI specification and enforced at application startup.
|
||||||
|
No decorator-driven routing or implicit framework behavior is used.
|
||||||
|
|
||||||
|
This template demonstrates:
|
||||||
|
- operationId-driven server-side route binding
|
||||||
|
- explicit HTTP status code control in handlers
|
||||||
|
- operationId-driven client usage against the same OpenAPI contract
|
||||||
|
- end-to-end validation using in-memory data and tests
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Scaffolding via CLI
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Create a new CRUD example service using the bundled template:
|
||||||
|
|
||||||
|
openapi-first crud_app
|
||||||
|
|
||||||
|
Create the service in a custom directory:
|
||||||
|
|
||||||
|
openapi-first crud_app my-crud-service
|
||||||
|
|
||||||
|
List all available application templates:
|
||||||
|
|
||||||
|
openapi-first --list
|
||||||
|
|
||||||
|
The CLI copies template files verbatim into the target directory.
|
||||||
|
No code is generated or modified beyond the copied scaffold.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Client Usage Example
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
The same OpenAPI specification used by the server can be used to
|
||||||
|
construct a strict, operationId-driven HTTP client.
|
||||||
|
|
||||||
|
Example client calls for CRUD operations:
|
||||||
|
|
||||||
|
from openapi_first.loader import load_openapi
|
||||||
|
from openapi_first.client import OpenAPIClient
|
||||||
|
|
||||||
|
spec = load_openapi("openapi.yaml")
|
||||||
|
client = OpenAPIClient(spec)
|
||||||
|
|
||||||
|
# List items
|
||||||
|
response = client.list_items()
|
||||||
|
|
||||||
|
# Get item by ID
|
||||||
|
response = client.get_item(
|
||||||
|
path_params={"item_id": 1}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create item
|
||||||
|
response = client.create_item(
|
||||||
|
body={"name": "Orange", "price": 0.8}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Update item
|
||||||
|
response = client.update_item(
|
||||||
|
path_params={"item_id": 1},
|
||||||
|
body={"name": "Green Apple", "price": 0.6},
|
||||||
|
)
|
||||||
|
|
||||||
|
# Delete item
|
||||||
|
response = client.delete_item(
|
||||||
|
path_params={"item_id": 1}
|
||||||
|
)
|
||||||
|
|
||||||
|
Client guarantees:
|
||||||
|
- One callable per OpenAPI ``operationId``
|
||||||
|
- No hardcoded URLs or HTTP methods in user code
|
||||||
|
- Path and request parameters must match the OpenAPI specification
|
||||||
|
- Invalid or incomplete OpenAPI specs fail at client construction time
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Non-Goals
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
This template is intentionally minimal and is NOT:
|
||||||
|
- production-ready
|
||||||
|
- persistent or concurrency-safe
|
||||||
|
- a reference architecture for data storage
|
||||||
|
|
||||||
|
It exists solely as a copyable example for learning, testing, and
|
||||||
|
bootstrapping OpenAPI-first services.
|
||||||
|
|
||||||
|
This package is not part of the ``openapi_first`` library API surface.
|
||||||
|
"""
|
||||||
@@ -3,27 +3,88 @@ In-memory mock data store for CRUD example.
|
|||||||
|
|
||||||
This module intentionally avoids persistence and concurrency guarantees.
|
This module intentionally avoids persistence and concurrency guarantees.
|
||||||
It is suitable for demos, tests, and scaffolding only.
|
It is suitable for demos, tests, and scaffolding only.
|
||||||
|
|
||||||
|
It intentionally avoids
|
||||||
|
- persistence
|
||||||
|
- concurrency guarantees
|
||||||
|
- validation
|
||||||
|
- error handling
|
||||||
|
|
||||||
|
The implementation is suitable for:
|
||||||
|
- demonstrations
|
||||||
|
- tests
|
||||||
|
- scaffolding and example services
|
||||||
|
|
||||||
|
It is explicitly NOT suitable for production use.
|
||||||
|
|
||||||
|
This module is not part of the ``openapi_first`` library API surface.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
|
||||||
|
# In-memory storage keyed by item ID.
|
||||||
_items: Dict[int, dict] = {
|
_items: Dict[int, dict] = {
|
||||||
1: {"id": 1, "name": "Apple", "price": 0.5},
|
1: {"id": 1, "name": "Apple", "price": 0.5},
|
||||||
2: {"id": 2, "name": "Banana", "price": 0.3},
|
2: {"id": 2, "name": "Banana", "price": 0.3},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Auto-incrementing ID counter.
|
||||||
_next_id = 3
|
_next_id = 3
|
||||||
|
|
||||||
|
|
||||||
def list_items():
|
def list_items():
|
||||||
|
"""
|
||||||
|
Return all items in the data store.
|
||||||
|
|
||||||
|
This function performs no filtering, pagination, or sorting.
|
||||||
|
The returned collection reflects the current in-memory state.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
list[dict]
|
||||||
|
A list of item representations.
|
||||||
|
"""
|
||||||
return list(_items.values())
|
return list(_items.values())
|
||||||
|
|
||||||
|
|
||||||
def get_item(item_id: int):
|
def get_item(item_id: int):
|
||||||
|
"""
|
||||||
|
Retrieve a single item by ID.
|
||||||
|
|
||||||
|
This function assumes the item exists and will raise ``KeyError``
|
||||||
|
if the ID is not present in the store.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
item_id : int
|
||||||
|
Identifier of the item to retrieve.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
dict
|
||||||
|
The stored item representation.
|
||||||
|
"""
|
||||||
return _items[item_id]
|
return _items[item_id]
|
||||||
|
|
||||||
|
|
||||||
def create_item(payload: dict):
|
def create_item(payload: dict):
|
||||||
|
"""
|
||||||
|
Create a new item in the data store.
|
||||||
|
|
||||||
|
A new integer ID is assigned automatically. No validation is
|
||||||
|
performed on the provided payload.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
payload : dict
|
||||||
|
Item attributes excluding the ``id`` field.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
dict
|
||||||
|
The newly created item, including its assigned ID.
|
||||||
|
"""
|
||||||
global _next_id
|
global _next_id
|
||||||
item = {"id": _next_id, **payload}
|
item = {"id": _next_id, **payload}
|
||||||
_items[_next_id] = item
|
_items[_next_id] = item
|
||||||
@@ -32,10 +93,40 @@ def create_item(payload: dict):
|
|||||||
|
|
||||||
|
|
||||||
def update_item(item_id: int, payload: dict):
|
def update_item(item_id: int, payload: dict):
|
||||||
|
"""
|
||||||
|
Replace an existing item in the data store.
|
||||||
|
|
||||||
|
This function overwrites the existing item entirely and does not
|
||||||
|
perform partial updates or validation. If the item does not exist,
|
||||||
|
it will be created implicitly.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
item_id : int
|
||||||
|
Identifier of the item to update.
|
||||||
|
payload : dict
|
||||||
|
Item attributes excluding the ``id`` field.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
dict
|
||||||
|
The updated item representation.
|
||||||
|
"""
|
||||||
item = {"id": item_id, **payload}
|
item = {"id": item_id, **payload}
|
||||||
_items[item_id] = item
|
_items[item_id] = item
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
def delete_item(item_id: int):
|
def delete_item(item_id: int):
|
||||||
|
"""
|
||||||
|
Remove an item from the data store.
|
||||||
|
|
||||||
|
This function assumes the item exists and will raise ``KeyError``
|
||||||
|
if the ID is not present.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
item_id : int
|
||||||
|
Identifier of the item to delete.
|
||||||
|
"""
|
||||||
del _items[item_id]
|
del _items[item_id]
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
"""
|
||||||
|
Application entry point for an OpenAPI-first CRUD example service.
|
||||||
|
|
||||||
|
This module constructs a FastAPI application exclusively from an
|
||||||
|
OpenAPI specification and a handler namespace, without using
|
||||||
|
decorator-driven routing.
|
||||||
|
|
||||||
|
All HTTP routes, methods, request/response schemas, and operation
|
||||||
|
bindings are defined in the OpenAPI document referenced by
|
||||||
|
``openapi_path``. Python callables defined in the ``routes`` module are
|
||||||
|
bound to OpenAPI operations strictly via ``operationId``.
|
||||||
|
|
||||||
|
This module contains no routing logic, persistence concerns, or
|
||||||
|
framework configuration beyond application assembly.
|
||||||
|
|
||||||
|
Design guarantees:
|
||||||
|
- OpenAPI is the single source of truth
|
||||||
|
- No undocumented routes can exist
|
||||||
|
- Every OpenAPI operationId must resolve to exactly one handler
|
||||||
|
- All contract violations fail at application startup
|
||||||
|
|
||||||
|
This file is intended to be used as the ASGI entry point.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
uvicorn main:app
|
||||||
|
"""
|
||||||
|
|
||||||
from openapi_first.app import OpenAPIFirstApp
|
from openapi_first.app import OpenAPIFirstApp
|
||||||
import routes
|
import routes
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,19 @@ CRUD route handlers bound via OpenAPI operationId.
|
|||||||
|
|
||||||
These handlers explicitly control HTTP status codes to ensure
|
These handlers explicitly control HTTP status codes to ensure
|
||||||
runtime behavior matches the OpenAPI contract.
|
runtime behavior matches the OpenAPI contract.
|
||||||
|
|
||||||
|
This module defines OpenAPI-bound operation handlers for a simple CRUD
|
||||||
|
service. Functions in this module are bound to HTTP routes exclusively
|
||||||
|
via OpenAPI ``operationId`` values.
|
||||||
|
|
||||||
|
Handlers explicitly control HTTP response status codes to ensure runtime
|
||||||
|
behavior matches the OpenAPI contract. Error conditions are translated
|
||||||
|
into explicit HTTP responses rather than relying on implicit framework
|
||||||
|
behavior.
|
||||||
|
|
||||||
|
No routing decorators or path definitions appear in this module. All
|
||||||
|
routing, HTTP methods, and schemas are defined in the OpenAPI
|
||||||
|
specification.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from fastapi import Response, HTTPException
|
from fastapi import Response, HTTPException
|
||||||
@@ -17,10 +30,42 @@ from data import (
|
|||||||
|
|
||||||
|
|
||||||
def list_items():
|
def list_items():
|
||||||
|
"""
|
||||||
|
List all items.
|
||||||
|
|
||||||
|
Implements the OpenAPI operation identified by
|
||||||
|
``operationId: list_items``.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
list[dict]
|
||||||
|
A list of item representations.
|
||||||
|
"""
|
||||||
return _list_items()
|
return _list_items()
|
||||||
|
|
||||||
|
|
||||||
def get_item(item_id: int):
|
def get_item(item_id: int):
|
||||||
|
"""
|
||||||
|
Retrieve a single item by ID.
|
||||||
|
|
||||||
|
Implements the OpenAPI operation identified by
|
||||||
|
``operationId: get_item``.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
item_id : int
|
||||||
|
Identifier of the item to retrieve.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
dict
|
||||||
|
The requested item.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
HTTPException
|
||||||
|
404 if the item does not exist.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return _get_item(item_id)
|
return _get_item(item_id)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -28,12 +73,53 @@ def get_item(item_id: int):
|
|||||||
|
|
||||||
|
|
||||||
def create_item(payload: dict, response: Response):
|
def create_item(payload: dict, response: Response):
|
||||||
|
"""
|
||||||
|
Create a new item.
|
||||||
|
|
||||||
|
Implements the OpenAPI operation identified by
|
||||||
|
``operationId: create_item``.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
payload : dict
|
||||||
|
Item attributes excluding the ``id`` field.
|
||||||
|
response : fastapi.Response
|
||||||
|
Response object used to set the HTTP status code.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
dict
|
||||||
|
The newly created item.
|
||||||
|
"""
|
||||||
item = _create_item(payload)
|
item = _create_item(payload)
|
||||||
response.status_code = 201
|
response.status_code = 201
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
def update_item(item_id: int, payload: dict):
|
def update_item(item_id: int, payload: dict):
|
||||||
|
"""
|
||||||
|
Update an existing item.
|
||||||
|
|
||||||
|
Implements the OpenAPI operation identified by
|
||||||
|
``operationId: update_item``.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
item_id : int
|
||||||
|
Identifier of the item to update.
|
||||||
|
payload : dict
|
||||||
|
Item attributes excluding the ``id`` field.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
dict
|
||||||
|
The updated item.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
HTTPException
|
||||||
|
404 if the item does not exist.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return _update_item(item_id, payload)
|
return _update_item(item_id, payload)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -41,10 +127,32 @@ def update_item(item_id: int, payload: dict):
|
|||||||
|
|
||||||
|
|
||||||
def delete_item(item_id: int, response: Response):
|
def delete_item(item_id: int, response: Response):
|
||||||
|
"""
|
||||||
|
Delete an existing item.
|
||||||
|
|
||||||
|
Implements the OpenAPI operation identified by
|
||||||
|
``operationId: delete_item``.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
item_id : int
|
||||||
|
Identifier of the item to delete.
|
||||||
|
response : fastapi.Response
|
||||||
|
Response object used to set the HTTP status code.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
None
|
||||||
|
No content.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
HTTPException
|
||||||
|
404 if the item does not exist.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
_delete_item(item_id)
|
_delete_item(item_id)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise HTTPException(status_code=404, detail="Item not found")
|
raise HTTPException(status_code=404, detail="Item not found")
|
||||||
|
|
||||||
response.status_code = 204
|
response.status_code = 204
|
||||||
return None
|
|
||||||
|
|||||||
@@ -3,11 +3,20 @@ End-to-end tests for the OpenAPI-first CRUD example app.
|
|||||||
|
|
||||||
These tests validate that all CRUD operations behave correctly
|
These tests validate that all CRUD operations behave correctly
|
||||||
against the in-memory mock data store.
|
against the in-memory mock data store.
|
||||||
|
- OpenAPI specification loading
|
||||||
|
- OperationId-driven route binding on the server
|
||||||
|
- OperationId-driven client invocation
|
||||||
|
- Correct HTTP status codes and response payloads
|
||||||
|
|
||||||
|
The tests exercise all CRUD operations against an in-memory mock data
|
||||||
|
store and assume deterministic behavior within a single process.
|
||||||
|
|
||||||
The tests assume:
|
The tests assume:
|
||||||
- OpenAPI-first route binding
|
- OpenAPI-first route binding
|
||||||
- In-memory storage (no persistence guarantees)
|
- In-memory storage (no persistence guarantees)
|
||||||
- Deterministic behavior in a single process
|
- Deterministic behavior in a single process
|
||||||
|
- One-to-one correspondence between OpenAPI operationId values and
|
||||||
|
server/client callables
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
@@ -61,7 +70,7 @@ def test_create_item():
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = client.create_item(
|
response = client.create_item(
|
||||||
body=payload
|
body=payload,
|
||||||
)
|
)
|
||||||
assert response.status_code == 201
|
assert response.status_code == 201
|
||||||
|
|
||||||
@@ -106,7 +115,7 @@ def test_update_item():
|
|||||||
def test_delete_item():
|
def test_delete_item():
|
||||||
"""Deleting an item should remove it from the store."""
|
"""Deleting an item should remove it from the store."""
|
||||||
response = client.delete_item(
|
response = client.delete_item(
|
||||||
path_params={"item_id": 2}
|
path_params={"item_id": 2},
|
||||||
)
|
)
|
||||||
assert response.status_code == 204
|
assert response.status_code == 204
|
||||||
|
|
||||||
|
|||||||
65
openapi_first/templates/health_app/__init__.py
Normal file
65
openapi_first/templates/health_app/__init__.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
"""
|
||||||
|
OpenAPI-first FastAPI application template.
|
||||||
|
|
||||||
|
This package contains a minimal, fully working example of an
|
||||||
|
OpenAPI-first FastAPI service built using the ``openapi_first`` library.
|
||||||
|
|
||||||
|
The application is assembled exclusively from:
|
||||||
|
- an OpenAPI specification (``openapi.yaml``)
|
||||||
|
- a handler namespace (``routes``)
|
||||||
|
|
||||||
|
No routing decorators, implicit behavior, or framework-specific
|
||||||
|
convenience abstractions are used. All HTTP routes, methods, and
|
||||||
|
operation bindings are defined in OpenAPI and enforced at application
|
||||||
|
startup.
|
||||||
|
|
||||||
|
This package is intended to be copied as a starting point for new
|
||||||
|
services via the ``openapi-first`` CLI. It is not part of the
|
||||||
|
``openapi_first`` library API surface.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Scaffolding via CLI
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Create a new OpenAPI-first health check service using the bundled
|
||||||
|
template:
|
||||||
|
|
||||||
|
openapi-first health_app
|
||||||
|
|
||||||
|
Create the service in a custom directory:
|
||||||
|
|
||||||
|
openapi-first health_app my-health-service
|
||||||
|
|
||||||
|
List all available application templates:
|
||||||
|
|
||||||
|
openapi-first --list
|
||||||
|
|
||||||
|
The CLI copies template files verbatim into the target directory.
|
||||||
|
No code is generated or modified beyond the copied scaffold.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Client Usage Example
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
The same OpenAPI specification used by the server can be used to
|
||||||
|
construct a strict, operationId-driven HTTP client.
|
||||||
|
|
||||||
|
Example client call for the ``get_health`` operation:
|
||||||
|
|
||||||
|
from openapi_first.loader import load_openapi
|
||||||
|
from openapi_first.client import OpenAPIClient
|
||||||
|
|
||||||
|
spec = load_openapi("openapi.yaml")
|
||||||
|
client = OpenAPIClient(spec)
|
||||||
|
|
||||||
|
response = client.get_health()
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == {"status": "ok"}
|
||||||
|
|
||||||
|
Client guarantees:
|
||||||
|
- One callable per OpenAPI ``operationId``
|
||||||
|
- No hardcoded URLs or HTTP methods in user code
|
||||||
|
- Path and request parameters must match the OpenAPI specification
|
||||||
|
- Invalid or incomplete OpenAPI specs fail at client construction time
|
||||||
|
"""
|
||||||
@@ -1,3 +1,31 @@
|
|||||||
|
"""
|
||||||
|
Application entry point for an OpenAPI-first FastAPI service.
|
||||||
|
|
||||||
|
This module constructs a FastAPI application exclusively from an
|
||||||
|
OpenAPI specification and a handler namespace, without using
|
||||||
|
decorator-driven routing.
|
||||||
|
|
||||||
|
All HTTP routes, methods, and operation bindings are defined in the
|
||||||
|
OpenAPI document referenced by ``openapi_path``. Python callables
|
||||||
|
defined in the ``routes`` module are bound to OpenAPI operations
|
||||||
|
strictly via ``operationId``.
|
||||||
|
|
||||||
|
This module contains no routing logic, request handling, or framework
|
||||||
|
configuration beyond application assembly.
|
||||||
|
|
||||||
|
Design guarantees:
|
||||||
|
- OpenAPI is the single source of truth
|
||||||
|
- No undocumented routes can exist
|
||||||
|
- Every OpenAPI operationId must resolve to exactly one handler
|
||||||
|
- All contract violations fail at application startup
|
||||||
|
|
||||||
|
This file is intended to be used as the ASGI entry point.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
uvicorn main:app
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
from openapi_first.app import OpenAPIFirstApp
|
from openapi_first.app import OpenAPIFirstApp
|
||||||
import routes
|
import routes
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,32 @@
|
|||||||
|
"""
|
||||||
|
OpenAPI operation handlers.
|
||||||
|
|
||||||
|
This module defines pure Python callables that implement OpenAPI
|
||||||
|
operations for this service. Functions in this module are bound to HTTP
|
||||||
|
routes exclusively via OpenAPI ``operationId`` values.
|
||||||
|
|
||||||
|
No routing decorators, HTTP metadata, or framework-specific logic
|
||||||
|
should appear here. All request/response semantics are defined in the
|
||||||
|
OpenAPI specification.
|
||||||
|
|
||||||
|
This module serves solely as an operationId namespace.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def get_health():
|
def get_health():
|
||||||
|
"""
|
||||||
|
Health check operation handler.
|
||||||
|
|
||||||
|
This function implements the OpenAPI operation identified by
|
||||||
|
``operationId: get_health``.
|
||||||
|
|
||||||
|
It contains no routing metadata or framework-specific logic.
|
||||||
|
Request binding, HTTP method, and response semantics are defined
|
||||||
|
exclusively by the OpenAPI specification.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
dict
|
||||||
|
A minimal liveness payload indicating service health.
|
||||||
|
"""
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user