This commit is contained in:
@@ -86,7 +86,9 @@
|
||||
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
|
||||
|
||||
<header class="md-header md-header--shadow" 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">
|
||||
|
||||
@@ -151,12 +153,19 @@
|
||||
</label>
|
||||
<nav class="md-search__options" aria-label="Search">
|
||||
|
||||
<a href="javascript:void(0)" class="md-search__icon md-icon" title="Share" aria-label="Share" data-clipboard data-clipboard-text="" data-md-component="search-share" tabindex="-1">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.15c-.05.21-.08.43-.08.66 0 1.61 1.31 2.91 2.92 2.91s2.92-1.3 2.92-2.91A2.92 2.92 0 0 0 18 16.08"/></svg>
|
||||
</a>
|
||||
|
||||
<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>
|
||||
|
||||
<div class="md-search__suggest" data-md-component="search-suggest"></div>
|
||||
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
|
||||
@@ -182,96 +191,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<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">
|
||||
<a href=".." class="md-tabs__link">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Home
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-tabs__item md-tabs__item--active">
|
||||
<a href="./" 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">
|
||||
@@ -285,10 +204,8 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--primary md-nav--lifted" aria-label="Navigation" data-md-level="0">
|
||||
<nav class="md-nav md-nav--primary" 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">
|
||||
|
||||
@@ -333,13 +250,18 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active md-nav__item--section md-nav__item--nested">
|
||||
@@ -436,56 +358,24 @@
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--openapi_firstapp" class="md-nav__link">
|
||||
<a href="#openapi_first.app--summary" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
openapi_first.app
|
||||
Summary
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="openapi_first.app">
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app-classes" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Classes
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="Classes">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--core-principles" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Core principles
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--what-this-module-does" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
What this module does
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--what-this-module-does-not-do" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
What this module does NOT do
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--intended-usage" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Intended usage
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
@@ -497,36 +387,9 @@
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp--parameters" class="md-nav__link">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp-functions" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Parameters
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp--raises" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Raises
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp--behavior-guarantees" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Behavior guarantees
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp--example" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Example
|
||||
Functions
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -540,6 +403,20 @@
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app-functions" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Functions
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
@@ -589,13 +466,21 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--nested">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--section md-nav__item--nested">
|
||||
|
||||
|
||||
|
||||
@@ -604,7 +489,7 @@
|
||||
<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">
|
||||
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="">
|
||||
|
||||
|
||||
|
||||
@@ -685,13 +570,19 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--nested">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--section md-nav__item--nested">
|
||||
|
||||
|
||||
|
||||
@@ -700,7 +591,7 @@
|
||||
<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">
|
||||
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="">
|
||||
|
||||
|
||||
|
||||
@@ -787,56 +678,24 @@
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--openapi_firstapp" class="md-nav__link">
|
||||
<a href="#openapi_first.app--summary" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
openapi_first.app
|
||||
Summary
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="openapi_first.app">
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app-classes" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Classes
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<nav class="md-nav" aria-label="Classes">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--core-principles" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Core principles
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--what-this-module-does" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
What this module does
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--what-this-module-does-not-do" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
What this module does NOT do
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app--intended-usage" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Intended usage
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
@@ -848,36 +707,9 @@
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp--parameters" class="md-nav__link">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp-functions" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Parameters
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp--raises" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Raises
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp--behavior-guarantees" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Behavior guarantees
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app.OpenAPIFirstApp--example" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Example
|
||||
Functions
|
||||
</span>
|
||||
</a>
|
||||
|
||||
@@ -891,6 +723,20 @@
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#openapi_first.app-functions" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
Functions
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
@@ -917,50 +763,47 @@
|
||||
|
||||
|
||||
<h2 id="openapi_first.app" class="doc doc-heading">
|
||||
<span class="doc doc-object-name doc-module-name">openapi_first.app</span>
|
||||
<code class="doc-symbol doc-symbol-heading doc-symbol-module"></code> <span class="doc doc-object-name doc-module-name">openapi_first.app</span>
|
||||
|
||||
|
||||
</h2>
|
||||
|
||||
<div class="doc doc-contents first">
|
||||
|
||||
<h3 id="openapi_first.app--openapi_firstapp">openapi_first.app</h3>
|
||||
<p>OpenAPI-first application bootstrap for FastAPI.</p>
|
||||
<p>OpenAPI-first application bootstrap for FastAPI.</p>
|
||||
<hr />
|
||||
<h4 id="openapi_first.app--summary">Summary</h4>
|
||||
<p>This module provides <code>OpenAPIFirstApp</code>, a thin but strict abstraction
|
||||
that enforces OpenAPI as the single source of truth for a FastAPI service.</p>
|
||||
<h4 id="openapi_first.app--core-principles">Core principles</h4>
|
||||
<ul>
|
||||
<li>The OpenAPI specification (JSON or YAML) defines the entire API surface.</li>
|
||||
<li>Every operationId in the OpenAPI spec must have a corresponding
|
||||
Python handler function.</li>
|
||||
<li>Handlers are plain Python callables (no FastAPI decorators).</li>
|
||||
<li>FastAPI route registration is derived exclusively from the spec.</li>
|
||||
<li>FastAPI's autogenerated OpenAPI schema is fully overridden.</li>
|
||||
</ul>
|
||||
<h4 id="openapi_first.app--what-this-module-does">What this module does</h4>
|
||||
<ul>
|
||||
<li>Loads and validates an OpenAPI 3.x specification.</li>
|
||||
<li>Dynamically binds HTTP routes to handler functions using operationId.</li>
|
||||
<li>Registers routes with FastAPI at application startup.</li>
|
||||
<li>Ensures runtime behavior matches the OpenAPI contract exactly.</li>
|
||||
</ul>
|
||||
<h4 id="openapi_first.app--what-this-module-does-not-do">What this module does NOT do</h4>
|
||||
<ul>
|
||||
<li>It does not generate OpenAPI specs.</li>
|
||||
<li>It does not generate client code.</li>
|
||||
<li>It does not introduce a new framework or lifecycle.</li>
|
||||
<li>It does not alter FastAPI dependency injection semantics.</li>
|
||||
</ul>
|
||||
<h4 id="openapi_first.app--intended-usage">Intended usage</h4>
|
||||
<p>This module is intended for teams that want:</p>
|
||||
<ul>
|
||||
<li>OpenAPI-first API development</li>
|
||||
<li>Strong contract enforcement</li>
|
||||
<li>Minimal FastAPI boilerplate</li>
|
||||
<li>Predictable, CI-friendly failures for spec/implementation drift</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<details class="notes" open>
|
||||
<summary>Notes</summary>
|
||||
<p><strong>Core Principles:</strong></p>
|
||||
<div class="language-text highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
|
||||
<span class="normal">2</span>
|
||||
<span class="normal">3</span>
|
||||
<span class="normal">4</span>
|
||||
<span class="normal">5</span></pre></div></td><td class="code"><div><pre><span></span><code>- 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
|
||||
</code></pre></div></td></tr></table></div>
|
||||
<p><strong>Responsibilities:</strong></p>
|
||||
<div class="language-text highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
|
||||
<span class="normal">2</span>
|
||||
<span class="normal">3</span>
|
||||
<span class="normal">4</span></pre></div></td><td class="code"><div><pre><span></span><code>- Loads and validates an OpenAPI 3.x specification
|
||||
- Dynamically binds HTTP routes to handler functions using operationId
|
||||
- Registers routes with FastAPI at application startup
|
||||
- Ensures runtime behavior matches the OpenAPI contract exactly
|
||||
</code></pre></div></td></tr></table></div>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
<div class="language-text highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>- This module intentionally does NOT: Generate OpenAPI specs, generate client code, introduce a new framework or lifecycle, or alter FastAPI dependency injection semantics.
|
||||
</code></pre></div></td></tr></table></div>
|
||||
</details>
|
||||
|
||||
|
||||
<div class="doc doc-children">
|
||||
|
||||
@@ -969,19 +812,19 @@ that enforces OpenAPI as the single source of truth for a FastAPI service.</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="openapi_first.app-classes">Classes</h3>
|
||||
|
||||
<div class="doc doc-object doc-class">
|
||||
|
||||
|
||||
|
||||
<h3 id="openapi_first.app.OpenAPIFirstApp" class="doc doc-heading">
|
||||
<span class="doc doc-object-name doc-class-name">OpenAPIFirstApp</span>
|
||||
<h4 id="openapi_first.app.OpenAPIFirstApp" class="doc doc-heading">
|
||||
<code class="doc-symbol doc-symbol-heading doc-symbol-class"></code> <span class="doc doc-object-name doc-class-name">OpenAPIFirstApp</span>
|
||||
|
||||
|
||||
</h3>
|
||||
<div class="doc-signature highlight"><pre><span></span><code><span class="nf">OpenAPIFirstApp</span><span class="p">(</span><span class="o">*</span><span class="p">,</span> <span class="n">openapi_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">routes_module</span><span class="p">:</span> <span class="n">Any</span><span class="p">,</span> <span class="o">**</span><span class="n">fastapi_kwargs</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span>
|
||||
</code></pre></div>
|
||||
</h4>
|
||||
<div class="language-python doc-signature highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1">1</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1"></a><span class="nf">OpenAPIFirstApp</span><span class="p">(</span><span class="o">*</span><span class="p">,</span> <span class="n">openapi_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">routes_module</span><span class="p">:</span> <span class="n">Any</span><span class="p">,</span> <span class="o">**</span><span class="n">fastapi_kwargs</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span>
|
||||
</span></code></pre></div></td></tr></table></div>
|
||||
|
||||
<div class="doc doc-contents ">
|
||||
<p class="doc doc-class-bases">
|
||||
@@ -989,48 +832,126 @@ that enforces OpenAPI as the single source of truth for a FastAPI service.</p>
|
||||
|
||||
|
||||
<p>FastAPI application enforcing OpenAPI-first design.</p>
|
||||
<p><code>OpenAPIFirstApp</code> subclasses FastAPI and replaces manual route
|
||||
registration with OpenAPI-driven binding. All routes are derived
|
||||
from the provided OpenAPI specification, and each operationId is
|
||||
mapped to a Python function in the supplied routes module.</p>
|
||||
<h5 id="openapi_first.app.OpenAPIFirstApp--parameters">Parameters</h5>
|
||||
<p>openapi_path : str
|
||||
Filesystem path to the OpenAPI 3.x specification file.
|
||||
This specification is treated as the authoritative API contract.</p>
|
||||
|
||||
|
||||
<details class="routes_module-" open>
|
||||
<summary>module</summary>
|
||||
<p>Python module containing handler functions whose names correspond
|
||||
exactly to OpenAPI operationId values.</p>
|
||||
</details> <p>**fastapi_kwargs
|
||||
Additional keyword arguments passed directly to <code>fastapi.FastAPI</code>
|
||||
(e.g., title, version, middleware, lifespan handlers).</p>
|
||||
<h5 id="openapi_first.app.OpenAPIFirstApp--raises">Raises</h5>
|
||||
<p>OpenAPIFirstError
|
||||
If the OpenAPI specification is invalid, or if any declared
|
||||
operationId does not have a corresponding handler function.</p>
|
||||
<h5 id="openapi_first.app.OpenAPIFirstApp--behavior-guarantees">Behavior guarantees</h5>
|
||||
<ul>
|
||||
<li>No route can exist without an OpenAPI declaration.</li>
|
||||
<li>No OpenAPI operation can exist without a handler.</li>
|
||||
<li>Swagger UI and <code>/openapi.json</code> always reflect the provided spec.</li>
|
||||
<li>Handler functions remain framework-agnostic and testable.</li>
|
||||
</ul>
|
||||
<h5 id="openapi_first.app.OpenAPIFirstApp--example">Example</h5>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<p>from openapi_first import OpenAPIFirstApp
|
||||
import app.routes as routes</p>
|
||||
<p>app = OpenAPIFirstApp(
|
||||
... openapi_path="app/openapi.json",
|
||||
... routes_module=routes,
|
||||
... title="Example Service"
|
||||
... )</p>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<details class="notes" open>
|
||||
<summary>Notes</summary>
|
||||
<p><strong>Responsibilities:</strong></p>
|
||||
<div class="language-text highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><code>- `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding
|
||||
- All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module
|
||||
</code></pre></div></td></tr></table></div>
|
||||
<p><strong>Guarantees:</strong></p>
|
||||
<div class="language-text highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
|
||||
<span class="normal">2</span>
|
||||
<span class="normal">3</span>
|
||||
<span class="normal">4</span></pre></div></td><td class="code"><div><pre><span></span><code>- No route can exist without an OpenAPI declaration
|
||||
- No OpenAPI operation can exist without a handler
|
||||
- Swagger UI and `/openapi.json` always reflect the provided spec
|
||||
- Handler functions remain framework-agnostic and testable
|
||||
</code></pre></div></td></tr></table></div>
|
||||
</details>
|
||||
|
||||
<details class="example" open>
|
||||
<summary>Example</summary>
|
||||
<div class="language-python highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1">1</a></span>
|
||||
<span class="normal"><a href="#__codelineno-0-2">2</a></span>
|
||||
<span class="normal"><a href="#__codelineno-0-3">3</a></span>
|
||||
<span class="normal"><a href="#__codelineno-0-4">4</a></span>
|
||||
<span class="normal"><a href="#__codelineno-0-5">5</a></span>
|
||||
<span class="normal"><a href="#__codelineno-0-6">6</a></span>
|
||||
<span class="normal"><a href="#__codelineno-0-7">7</a></span>
|
||||
<span class="normal"><a href="#__codelineno-0-8">8</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1"></a><span class="kn">from</span><span class="w"> </span><span class="nn">openapi_first</span><span class="w"> </span><span class="kn">import</span> <span class="n">OpenAPIFirstApp</span>
|
||||
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2"></a><span class="kn">import</span><span class="w"> </span><span class="nn">app.routes</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">routes</span>
|
||||
</span><span id="__span-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3"></a>
|
||||
</span><span id="__span-0-4"><a id="__codelineno-0-4" name="__codelineno-0-4"></a><span class="n">app</span> <span class="o">=</span> <span class="n">OpenAPIFirstApp</span><span class="p">(</span>
|
||||
</span><span id="__span-0-5"><a id="__codelineno-0-5" name="__codelineno-0-5"></a> <span class="n">openapi_path</span><span class="o">=</span><span class="s2">"app/openapi.json"</span><span class="p">,</span>
|
||||
</span><span id="__span-0-6"><a id="__codelineno-0-6" name="__codelineno-0-6"></a> <span class="n">routes_module</span><span class="o">=</span><span class="n">routes</span><span class="p">,</span>
|
||||
</span><span id="__span-0-7"><a id="__codelineno-0-7" name="__codelineno-0-7"></a> <span class="n">title</span><span class="o">=</span><span class="s2">"Example Service"</span><span class="p">,</span>
|
||||
</span><span id="__span-0-8"><a id="__codelineno-0-8" name="__codelineno-0-8"></a><span class="p">)</span>
|
||||
</span></code></pre></div></td></tr></table></div>
|
||||
</details>
|
||||
<p>Initialize the application.</p>
|
||||
|
||||
|
||||
<p><span class="doc-section-title">Parameters:</span></p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Description</th>
|
||||
<th>Default</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="doc-section-item">
|
||||
<td><code>openapi_path</code></td>
|
||||
<td>
|
||||
<code>str</code>
|
||||
</td>
|
||||
<td>
|
||||
<div class="doc-md-description">
|
||||
<p>Filesystem path to the OpenAPI 3.x specification file. This specification is treated as the authoritative API contract.</p>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<em>required</em>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="doc-section-item">
|
||||
<td><code>routes_module</code></td>
|
||||
<td>
|
||||
<code>module</code>
|
||||
</td>
|
||||
<td>
|
||||
<div class="doc-md-description">
|
||||
<p>Python module containing handler functions whose names correspond exactly to OpenAPI operationId values.</p>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<em>required</em>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="doc-section-item">
|
||||
<td><code>**fastapi_kwargs</code></td>
|
||||
<td>
|
||||
<code><span title="typing.Any">Any</span></code>
|
||||
</td>
|
||||
<td>
|
||||
<div class="doc-md-description">
|
||||
<p>Additional keyword arguments passed directly to <code>fastapi.FastAPI</code> (e.g., title, version, middleware, lifespan handlers).</p>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<code>{}</code>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<p><span class="doc-section-title">Raises:</span></p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Type</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="doc-section-item">
|
||||
<td>
|
||||
<code>OpenAPIFirstError</code>
|
||||
</td>
|
||||
<td>
|
||||
<div class="doc-md-description">
|
||||
<p>If the OpenAPI specification is invalid, or if any declared operationId does not have a corresponding handler function.</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
@@ -1043,7 +964,7 @@ import app.routes as routes</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<h5 id="openapi_first.app.OpenAPIFirstApp-functions">Functions</h5>
|
||||
|
||||
|
||||
|
||||
@@ -1052,7 +973,7 @@ import app.routes as routes</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<h3 id="openapi_first.app-functions">Functions</h3>
|
||||
|
||||
|
||||
|
||||
@@ -1078,6 +999,8 @@ import app.routes as routes</p>
|
||||
</div>
|
||||
|
||||
|
||||
<script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script>
|
||||
|
||||
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
|
||||
</div>
|
||||
|
||||
@@ -1115,7 +1038,7 @@ import app.routes as routes</p>
|
||||
|
||||
|
||||
|
||||
<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 id="__config" type="application/json">{"base": "..", "features": ["navigation.sections", "navigation.expand", "navigation.top", "navigation.instant", "navigation.tracking", "navigation.indexes", "content.code.copy", "content.code.annotate", "content.tabs.link", "content.action.edit", "search.highlight", "search.share", "search.suggest"], "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>
|
||||
|
||||
Reference in New Issue
Block a user