Fastapi: [FEATURE] Export API docs

Created on 12 Dec 2019  路  7Comments  路  Source: tiangolo/fastapi

Is it possible to have a method to extract or export the auto generated docs to a static set of pages? (This may already be possible, and I've missed it)

Thinking of separate docs subdomain and separating API and docs HTTP request traffic, etc.

enhancement

Most helpful comment

@pawamoy
You can call FastAPI.openapi() method that will return OpenAPI schema as python dictionary. Check here for more information.

All 7 comments

It's a matter of copying the openapi.json and setting up which ever Doc System you wanna use, Swagger, Redoc. They both are just static one page websites.

Is it that easy? That's pretty cool. Thanks - closing this issue.

@jaddison This section of the docs may also be of interest to you: https://fastapi.tiangolo.com/tutorial/extending-openapi/#self-hosting-javascript-and-css-for-docs

Page was moved to https://fastapi.tiangolo.com/advanced/extending-openapi/#self-hosting-javascript-and-css-for-docs

It's a matter of copying the openapi.json and setting up which ever Doc System you wanna use, Swagger, Redoc. They both are just static one page websites.

Then, is there a way to generate and export the openapi.json, without having to actually run/serve the API? I would like to generate the JSON file in a CI job, keep it as an artifact, and deploy it somewhere else in another job. If I have to run the API to get the JSON file, it means I have to run the API in a background process and wget/curl the /openapi.json URL in a foreground process? It feels a bit weird to use background processes in CI.

@pawamoy
You can call FastAPI.openapi() method that will return OpenAPI schema as python dictionary. Check here for more information.

Thanks for the help here everyone! :cake: :bowing_man:

And thanks @jaddison for reporting back and closing the issue :+1:

I posted a Python script here to export the ReDoc docs into a standalone HTML file, if anyone is interested :wink:

Was this page helpful?
0 / 5 - 0 ratings