<h3 dir="auto">First check</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I used the GitHub search to find a similar issue and didn't find it.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I searched the FastAPI documentation, with the integrated search.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already searched in Google "How to X in FastAPI" and didn't find any information.</li>
</ul>
<h3 dir="auto">Description</h3>
<p dir="auto">How can I generate the swagger without starting the service?</p>
<h3 dir="auto">Is your feature request related to a problem</h3>
<p dir="auto">Not a bug, just a problem with my CI system.</p>
<p dir="auto">I want to be able to programmatically access the openapi schema and save it to a file without running the web server</p>
<h3 dir="auto">The solution you would like</h3>
<p dir="auto">Ideally, I'd like to write a script that would output the openapi schema without running the webserver.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from myapp.api import api
json.dump(
  get_schema_from_app(api),
  open('openapi_schema.json', 'w')
)"><pre class="notranslate"><code class="notranslate">from myapp.api import api
json.dump(
  get_schema_from_app(api),
  open('openapi_schema.json', 'w')
)
</code></pre></div>
<h3 dir="auto">Describe alternatives you've considered</h3>
<p dir="auto">I've considered running the app in my CICD workflow and requesting the schema via http, but that seems like a lot of overhead, and I'd bet the functions to do what I want are already in the code and just need to be invoked in the right order.</p>
<h3 dir="auto">Additional context</h3>
<p dir="auto">Nothing to add, other than I'm gonna open a PR and see if I can figure it out.</p>