Redoc: Export to PDF

Created on 28 Nov 2018  路  3Comments  路  Source: Redocly/redoc

Most helpful comment

Not PDF but HTML, and for a FastAPI application, from a Python script:

"""Script to export the ReDoc documentation page into a standalone HTML file."""

import json

from my_app.app import app

HTML_TEMPLATE = """<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>My Project - ReDoc</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="https://fastapi.tiangolo.com/img/favicon.png">
    <style>
        body {
            margin: 0;
            padding: 0;
        }
    </style>
    <style data-styled="" data-styled-version="4.4.1"></style>
</head>
<body>
    <div id="redoc-container"></div>
    <script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
    <script>
        var spec = %s;
        Redoc.init(spec, {}, document.getElementById("redoc-container"));
    </script>
</body>
</html>
"""

if __name__ == "__main__":
    with open(f"api-docs-my-project.html", "w") as fd:
        print(HTML_TEMPLATE % json.dumps(app.openapi()), file=fd)

All 3 comments

Who were you @gavinkalika, what did you see?!

Not PDF but HTML, and for a FastAPI application, from a Python script:

"""Script to export the ReDoc documentation page into a standalone HTML file."""

import json

from my_app.app import app

HTML_TEMPLATE = """<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>My Project - ReDoc</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="https://fastapi.tiangolo.com/img/favicon.png">
    <style>
        body {
            margin: 0;
            padding: 0;
        }
    </style>
    <style data-styled="" data-styled-version="4.4.1"></style>
</head>
<body>
    <div id="redoc-container"></div>
    <script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
    <script>
        var spec = %s;
        Redoc.init(spec, {}, document.getElementById("redoc-container"));
    </script>
</body>
</html>
"""

if __name__ == "__main__":
    with open(f"api-docs-my-project.html", "w") as fd:
        print(HTML_TEMPLATE % json.dumps(app.openapi()), file=fd)

@pawamoy Thank you! That could be somewhere in fastapi documentation or in the library but as a standalone it's really nice!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dwilding picture dwilding  路  4Comments

jaroslawr picture jaroslawr  路  3Comments

dvh picture dvh  路  3Comments

gauravmokhasi picture gauravmokhasi  路  4Comments

yuji38kwmt picture yuji38kwmt  路  3Comments