Search code examples
pythonopenapi-generatoruvicorn

How to start from example diverging REST interface?


In the uvicorn exmaple, one writes uvicorn filename:attributename and by that start the server. However, the interface I have generated has no such method attributename in filename. Therefore, I am unsure what to pass as attributename.

Generated code in main.py

"""
    Somename

    Specification for REST-API of somename.

    The version of the OpenAPI document: 1.0.0
    Generated by: https://openapi-generator.tech
"""
from fastapi import FastAPI
from openapi_server.apis.some_api import router as SomeApiRouter

app = FastAPI(
    title="SomeName",
    description="Specification for REST-API of somename",
    version="1.0.0",
)

app.include_router(SomeApiRouter)

Solution

  • The attribute name that you should specify is the name of the variable that holds your FastAPI instance. As they say in the docs:

    The ASGI application should be specified in the form path.to.module:instance.path.

    In this case for you, it would be uvicorn main:app where main.py is the file your code is in and app is the name of the variable in that file that holds your FastAPI instance.