Skip to content

Generate the openapi_schema for a specific api version using the app.openapi() method #62

Description

@ddoren

Is your feature request related to a problem? Please describe.
Hey, I'm trying to generate the full openapi.json file for a specific API version without running the server, programmatically, as I need to generate the html documentation from it. Is there a way to do that? using the app.openapi() would hide the endpoints behind the versions.
But I need the openapi schema for a specific API version.

Describe the solution you'd like
A method that would allow the generation of a specific versioned openapi schema, something like app.openapi('v1') or anything would work really.

Additional context

from fastapi.openapi.utils import get_openapi
from app import app
import json


with open("openapi.json", "w") as file:
    json.dump(app.openapi(), file)


with open("openapi-get.json", "w") as file:
    openapi_schema = get_openapi(
        title="Custom title",
        version="2.5.0",
        description="This is a very custom OpenAPI schema",
        routes=app.routes,
    )

The generated openapi schema includes the v0 and v1 endpoints, however need a method to generate the schema with the endpoints for a specific version.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions