Files
docs/libs/openapi-first/site/openapi_first/index.html
Vishesh 'ironeagle' Bangotra 24ecde4222
All checks were successful
continuous-integration/drone/push Build is passing
added more libs
2026-01-22 17:20:17 +05:30

1210 lines
30 KiB
HTML

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="next" href="app/">
<link rel="icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.6.23">
<title>Home - openapi_first</title>
<link rel="stylesheet" href="../assets/stylesheets/main.84d31ad4.min.css">
<link rel="stylesheet" href="../assets/stylesheets/palette.06af60db.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300,300i,400,400i,700,700i%7CJetBrains+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Inter";--md-code-font:"JetBrains Mono"}</style>
<link rel="stylesheet" href="../assets/_mkdocstrings.css">
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr" data-md-color-scheme="slate" data-md-color-primary="deep-purple" data-md-color-accent="cyan">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#openapi-first" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href=".." title="openapi_first" class="md-header__button md-logo" aria-label="openapi_first" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
openapi_first
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Home
</span>
</div>
</div>
</div>
<form class="md-header__option" data-md-component="palette">
<input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="deep-purple" data-md-color-accent="cyan" aria-hidden="true" type="radio" name="__palette" id="__palette_0">
</form>
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
<div class="md-grid">
<ul class="md-tabs__list">
<li class="md-tabs__item md-tabs__item--active">
<a href="./" class="md-tabs__link">
Home
</a>
</li>
<li class="md-tabs__item">
<a href="app/" class="md-tabs__link">
Application Bootstrap
</a>
</li>
<li class="md-tabs__item">
<a href="loader/" class="md-tabs__link">
Core Utilities
</a>
</li>
<li class="md-tabs__item">
<a href="client/" class="md-tabs__link">
OpenAPI Client
</a>
</li>
</ul>
</div>
</nav>
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary md-nav--lifted" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href=".." title="openapi_first" class="md-nav__button md-logo" aria-label="openapi_first" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
openapi_first
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Home
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Home
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#openapi_first" class="md-nav__link">
<span class="md-ellipsis">
openapi_first
</span>
</a>
<nav class="md-nav" aria-label="openapi_first">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#openapi_first--architecture-overview" class="md-nav__link">
<span class="md-ellipsis">
Architecture Overview
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--installation" class="md-nav__link">
<span class="md-ellipsis">
Installation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--command-line-interface-scaffolding-templates" class="md-nav__link">
<span class="md-ellipsis">
Command-Line Interface (Scaffolding, Templates)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--server-side-usage-openapi-fastapi" class="md-nav__link">
<span class="md-ellipsis">
Server-Side Usage (OpenAPI → FastAPI)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--client-side-usage-openapi-http-client" class="md-nav__link">
<span class="md-ellipsis">
Client-Side Usage (OpenAPI → HTTP Client)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--extensibility-model" class="md-nav__link">
<span class="md-ellipsis">
Extensibility Model
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--public-api-surface" class="md-nav__link">
<span class="md-ellipsis">
Public API Surface
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--design-guarantees" class="md-nav__link">
<span class="md-ellipsis">
Design Guarantees
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--core-philosophy" class="md-nav__link">
<span class="md-ellipsis">
Core Philosophy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--documentation-design" class="md-nav__link">
<span class="md-ellipsis">
Documentation Design
</span>
</a>
<nav class="md-nav" aria-label="Documentation Design">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#openapi_first--for-humans" class="md-nav__link">
<span class="md-ellipsis">
For Humans
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--for-llms" class="md-nav__link">
<span class="md-ellipsis">
For LLMs
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_2" >
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
<span class="md-ellipsis">
Application Bootstrap
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_2">
<span class="md-nav__icon md-icon"></span>
Application Bootstrap
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="app/" class="md-nav__link">
<span class="md-ellipsis">
App
</span>
</a>
</li>
<li class="md-nav__item">
<a href="binder/" class="md-nav__link">
<span class="md-ellipsis">
Binder
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_3" >
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
<span class="md-ellipsis">
Core Utilities
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3">
<span class="md-nav__icon md-icon"></span>
Core Utilities
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="loader/" class="md-nav__link">
<span class="md-ellipsis">
Loader
</span>
</a>
</li>
<li class="md-nav__item">
<a href="errors/" class="md-nav__link">
<span class="md-ellipsis">
Errors
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_4" >
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
OpenAPI Client
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
OpenAPI Client
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="client/" class="md-nav__link">
<span class="md-ellipsis">
Client
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#openapi_first" class="md-nav__link">
<span class="md-ellipsis">
openapi_first
</span>
</a>
<nav class="md-nav" aria-label="openapi_first">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#openapi_first--architecture-overview" class="md-nav__link">
<span class="md-ellipsis">
Architecture Overview
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--installation" class="md-nav__link">
<span class="md-ellipsis">
Installation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--command-line-interface-scaffolding-templates" class="md-nav__link">
<span class="md-ellipsis">
Command-Line Interface (Scaffolding, Templates)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--server-side-usage-openapi-fastapi" class="md-nav__link">
<span class="md-ellipsis">
Server-Side Usage (OpenAPI → FastAPI)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--client-side-usage-openapi-http-client" class="md-nav__link">
<span class="md-ellipsis">
Client-Side Usage (OpenAPI → HTTP Client)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--extensibility-model" class="md-nav__link">
<span class="md-ellipsis">
Extensibility Model
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--public-api-surface" class="md-nav__link">
<span class="md-ellipsis">
Public API Surface
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--design-guarantees" class="md-nav__link">
<span class="md-ellipsis">
Design Guarantees
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--core-philosophy" class="md-nav__link">
<span class="md-ellipsis">
Core Philosophy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--documentation-design" class="md-nav__link">
<span class="md-ellipsis">
Documentation Design
</span>
</a>
<nav class="md-nav" aria-label="Documentation Design">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#openapi_first--for-humans" class="md-nav__link">
<span class="md-ellipsis">
For Humans
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#openapi_first--for-llms" class="md-nav__link">
<span class="md-ellipsis">
For LLMs
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="openapi-first">Openapi First</h1>
<div class="doc doc-object doc-module">
<h2 id="openapi_first" class="doc doc-heading">
<span class="doc doc-object-name doc-module-name">openapi_first</span>
</h2>
<div class="doc doc-contents first">
<p>FastAPI OpenAPI First — strict OpenAPI-first application bootstrap for FastAPI.</p>
<p>FastAPI OpenAPI First is a <strong>contract-first infrastructure library</strong> that
enforces OpenAPI as the single source of truth for FastAPI services.</p>
<p>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.</p>
<p>The package is intentionally minimal and layered. Each module has a
single responsibility and exposes explicit contracts rather than
convenience facades.</p>
<hr />
<h4 id="openapi_first--architecture-overview">Architecture Overview</h4>
<p>The library is structured around four core responsibilities:</p>
<ul>
<li>loader: load and validate OpenAPI 3.x specifications (JSON/YAML)</li>
<li>binder: bind OpenAPI operations to FastAPI routes via operationId</li>
<li>app: OpenAPI-first FastAPI application bootstrap</li>
<li>client: OpenAPI-first HTTP client driven by the same specification</li>
<li>errors: explicit error hierarchy for contract violations</li>
</ul>
<p>The package root acts as a <strong>namespace</strong>, not a facade. Consumers are
expected to import functionality explicitly from the appropriate module.</p>
<hr />
<h4 id="openapi_first--installation">Installation</h4>
<p>Install using pip:</p>
<pre><code>pip install openapi-first
</code></pre>
<p>Or with Poetry:</p>
<pre><code>poetry add openapi-first
</code></pre>
<p>Runtime dependencies are intentionally minimal:
- fastapi (server-side)
- httpx (client-side)
- openapi-spec-validator
- pyyaml (optional, for YAML specs)</p>
<p>The ASGI server (e.g., uvicorn) is an application-level dependency and is
not bundled with this library.</p>
<hr />
<h4 id="openapi_first--command-line-interface-scaffolding-templates">Command-Line Interface (Scaffolding, Templates)</h4>
<p>FastAPI OpenAPI First ships with a small CLI for bootstrapping
OpenAPI-first FastAPI applications from bundled templates.</p>
<p>List available application templates:</p>
<pre><code>openapi-first --list
</code></pre>
<p>Create a new application using the default template:</p>
<pre><code>openapi-first
</code></pre>
<p>Create a new application using a specific template:</p>
<pre><code>openapi-first health_app
</code></pre>
<p>Create a new application in a custom directory:</p>
<pre><code>openapi-first health_app my-service
</code></pre>
<p>The CLI copies template files verbatim into the target directory.
No code is generated or modified beyond the copied scaffold.</p>
<hr />
<h4 id="openapi_first--server-side-usage-openapi-fastapi">Server-Side Usage (OpenAPI → FastAPI)</h4>
<p>Minimal OpenAPI-first FastAPI application:</p>
<pre><code>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",
)
# Run with:
# uvicorn my_service.main:api
</code></pre>
<p>Handler definitions (no decorators):</p>
<pre><code>def get_health():
return {"status": "ok"}
</code></pre>
<p>OpenAPI snippet:</p>
<pre><code>paths:
/health:
get:
operationId: get_health
responses:
"200":
description: OK
</code></pre>
<p>The binder guarantees:
- Every OpenAPI operationId has exactly one handler
- No undocumented routes exist
- All mismatches fail at application startup</p>
<hr />
<h4 id="openapi_first--client-side-usage-openapi-http-client">Client-Side Usage (OpenAPI → HTTP Client)</h4>
<p>The same OpenAPI specification can be used to construct a strict,
operationId-driven HTTP client.</p>
<p>Client construction:</p>
<pre><code>from openapi_first.loader import load_openapi
from openapi_first.client import OpenAPIClient
spec = load_openapi("openapi.yaml")
client = OpenAPIClient(spec)
</code></pre>
<p>Calling operations (operationId is the API):</p>
<pre><code>response = client.get_health()
assert response.status_code == 200
assert response.json() == {"status": "ok"}
</code></pre>
<p>Path parameters must match the OpenAPI specification exactly:</p>
<pre><code>response = client.get_item(
path_params={"item_id": 1}
)
</code></pre>
<p>Request bodies are passed explicitly:</p>
<pre><code>response = client.create_item(
body={"name": "Orange", "price": 0.8}
)
</code></pre>
<p>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</p>
<p>The client is transport-level only and returns <code>httpx.Response</code>
objects directly. Response interpretation and validation are left to
the consumer or higher-level layers.</p>
<hr />
<h4 id="openapi_first--extensibility-model">Extensibility Model</h4>
<p>FastAPI OpenAPI First is designed to be extended via <strong>explicit contracts</strong>:</p>
<ul>
<li>Users MAY extend OpenAPI loading behavior (e.g. multi-file specs)
by wrapping or replacing <code>loader.load_openapi</code></li>
<li>Users MAY extend route binding behavior by building on top of
<code>binder.bind_routes</code></li>
<li>Users MAY layer additional validation (e.g. signature checks)
without modifying core modules</li>
</ul>
<p>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.</p>
<hr />
<h4 id="openapi_first--public-api-surface">Public API Surface</h4>
<p>The supported public API consists of the following top-level modules:</p>
<ul>
<li>openapi_first.app</li>
<li>openapi_first.binder</li>
<li>openapi_first.loader</li>
<li>openapi_first.client</li>
<li>openapi_first.errors</li>
</ul>
<p>Classes and functions should be imported explicitly from these modules.
No individual symbols are re-exported at the package root.</p>
<hr />
<h4 id="openapi_first--design-guarantees">Design Guarantees</h4>
<ul>
<li>OpenAPI is the single source of truth</li>
<li>No undocumented routes can exist</li>
<li>No OpenAPI operation can exist without a handler or client callable</li>
<li>All contract violations fail at application startup or client creation</li>
<li>No hidden FastAPI magic or implicit behavior</li>
<li>Deterministic, testable application assembly</li>
<li>CI-friendly failure modes</li>
</ul>
<p>FastAPI OpenAPI First favors correctness, explicitness, and contract
enforcement over convenience shortcuts.</p>
<h4 id="openapi_first--core-philosophy">Core Philosophy</h4>
<p><code>FastAPI OpenAPI First</code> operates on the <strong>Contract-as-Code</strong> principle:</p>
<ol>
<li><strong>Spec-Driven Routing</strong>: The OpenAPI document <em>is</em> the router. Code only exists to fulfill established contracts.</li>
<li><strong>Startup Fail-Fast</strong>: Binding mismatches (missing handlers or extra operations) are detected during app initialization, not at runtime.</li>
<li><strong>Decoupled Symmetry</strong>: The same specification drives both the FastAPI server and the <code>httpx</code>-based client, ensuring type-safe communication.</li>
</ol>
<h4 id="openapi_first--documentation-design">Documentation Design</h4>
<p>Follow these "AI-Native" docstring principles to maximize developer and agent productivity:</p>
<h5 id="openapi_first--for-humans">For Humans</h5>
<ul>
<li><strong>Logical Grouping</strong>: Document the Loader, Binder, and Client as distinct infrastructure layers.</li>
<li><strong>Spec Snippets</strong>: Always include the corresponding OpenAPI YAML/JSON snippet alongside Python examples.</li>
</ul>
<h5 id="openapi_first--for-llms">For LLMs</h5>
<ul>
<li><strong>Full Path Linking</strong>: Refer to cross-module dependencies using their full dotted paths (e.g., <code>openapi_first.loader.load_openapi</code>).</li>
<li><strong>Complete Stubs</strong>: Maintain high-fidelity <code>.pyi</code> stubs for all public interfaces to provide an optimized machine-context.</li>
<li><strong>Traceable Errors</strong>: Use specific <code>: description</code> pairs in <code>Raises</code> blocks to allow agents to accurately map errors to spec violations.</li>
</ul>
<div class="doc doc-children">
</div>
</div>
</div>
</article>
</div>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
<button type="button" class="md-top md-icon" data-md-component="top" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg>
Back to top
</button>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": "..", "features": ["navigation.tabs", "navigation.expand", "navigation.top", "navigation.instant", "content.code.copy", "content.code.annotate"], "search": "../assets/javascripts/workers/search.973d3a69.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script>
<script src="../assets/javascripts/bundle.f55a23d4.min.js"></script>
</body>
</html>