<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>
<h3 dir="auto">Is your feature request related to a problem</h3>
<p dir="auto">Is your feature request related to a problem?</p>
<p dir="auto">In a common CI environment there are cases when automatically deploying an openapi.json to services like Github Pages can very useful. However, in order to access the openapi.json thats generated after fastapi instance is running and providing the <code class="notranslate">docs</code> endpoint is sub-optimal because it requires spinning up the service in CI just to curl that file.</p>
<h3 dir="auto">The solution you would like</h3>
<p dir="auto">Add extra flags to <code class="notranslate">fastapi</code> that will allow to generate the <code class="notranslate">openapi.json</code> without running the service instance.</p>
<p dir="auto">For example when invoking via uvicorn pass extra args that fastapi will somehow intercept and produce the openapi file to specified location:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="uvicorn main:app --fastapi_generate_openapi --fastapi_openapi_output &quot;{output_path_goes_here}&quot;"><pre class="notranslate"><code class="notranslate">uvicorn main:app --fastapi_generate_openapi --fastapi_openapi_output "{output_path_goes_here}"
</code></pre></div>
<p dir="auto">If its not possible to intercept the args when invoked via <code class="notranslate">uvicorn</code>, then perhaps another alternative is to provide a simple <code class="notranslate">fastapi</code> cli, pre packaged with the python module and do something like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fastapi --fastapi_generate_openapi --fastapi_openapi_output &quot;{output_path_goes_here}&quot;"><pre class="notranslate"><code class="notranslate">fastapi --fastapi_generate_openapi --fastapi_openapi_output "{output_path_goes_here}"
</code></pre></div>
<h3 dir="auto">Describe alternatives you've considered</h3>
<p dir="auto">As described in problem description, the working alternative is running the instance and curling the openapi.json from the docs endpoint.</p>
<h3 dir="auto">Additional comments</h3>
<p dir="auto">If this feature is somehow already available and someone could provide a link to how to use/invoke it ill greatly appreciate it and close the GitHub issue :-)</p>