question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to export Swagger to Yaml when accessed with docs.

See original GitHub issue

Hello.

As the title says, I always want to have the Swagger documentation that opens when I access / docs as a yaml file, but I don’t know how to do it.

I want to generate type information to be used in the front end from the output yaml file.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
insomnescommented, Feb 1, 2021

@satodaiki as @falkben mentioned you can get openapi data in app, so you can run startup function like this:

import json

from fastapi import FastAPI


app = FastAPI()


@app.on_event("startup")
def save_openapi_json():
    openapi_data = app.openapi()
    # Change "openapi.json" to desired filename
    with open("openapi.json", "w") as file:
        json.dump(openapi_data, file)

But there is catch if you run uvicorn as: uvicorn app.main: app --reload It would reload permanently, cause file would be overwritten in this simple example. You can check for changes before writing or remove --reload option

3reactions
falkbencommented, Jan 28, 2021

app.openapi() will return the openapi schema as a dictionary.

you could convert this to yaml file, and serve it on /docs if you wanted…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to export swagger.json (or yaml) - Stack Overflow
Then refresh the page and search for the API definition file ( swagger.json , swagger.yaml , api-docs or similar) among HTTP requests.
Read more >
API Documentation Made Easy with OpenAPI & Swagger
Head over to Swagger Inspector, and insert the end point of the resource you want to have documented. You can then navigate to...
Read more >
How To Generate A Yaml File From A Swagger Ui
You can export your API using YAML by selecting it from the Export menu. On the Export menu, choose the JSON export option...
Read more >
How to host Swagger documentation using yaml/json ...
Update swagger documentation with Swagger Editor, export the yaml ... Run the spring boot server and access <hostname>/swagger-ui.html to ...
Read more >
Swagger UI tutorial | Documenting APIs - Idratherbewriting.com
Change the url value to an online web URL to your Swagger file. For example: https://idratherbewriting.com/learnapidoc/docs/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found