fastapi-cli icon indicating copy to clipboard operation
fastapi-cli copied to clipboard

feat: Add markdown doc based on app's openapi specification

Open Iito opened this issue 1 year ago • 1 comments

This feat adds the possibility to generate the documentation of an app in Markdown (git style). Beautifully named fastapi doc It uses from fastapi.openapi.utils.get_openapi to generate the openapi specs then turn those specs into markdown.

Here is an example of generated doc based on FastAPI's example

from typing import Union

from fastapi import FastAPI

app = FastAPI(title="MyFirstAPI")


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

Generated doc:

MyFirstAPI

Version: 0.1.0

Paths

/

GET

Summary: Read Root

Operation ID: read_root__get

Responses:

Status Code Description Content
200 Successful Response application/json: schema: [A](#a)

/items/{item_id}

GET

Summary: Read Item

Operation ID: read_item_items__item_id__get

Parameters:

Name In Required Schema Description Example
item_id path True type: integer
title: Item Id
N/A N/A
q query False type: N/A
title: Q
N/A N/A
Responses:
Status Code Description Content
200 Successful Response application/json: schema: [A](#a)
422 Validation Error application/json: schema: [HTTPValidationError](#httpvalidationerror)

Components

Schemas

HTTPValidationError
  • Type: object
  • Title: HTTPValidationError
  • Properties:
    • detail:
      • Type: array
      • Title: Detail
      • Description: N/A
ValidationError
  • Type: object
  • Required: loc, msg, type
  • Title: ValidationError
  • Properties:
    • loc:
      • Type: array
      • Title: Location
      • Description: N/A
    • msg:
      • Type: string
      • Title: Message
      • Description: N/A
    • type:
      • Type: string
      • Title: Error Type
      • Description: N/A

Iito avatar Jul 10 '24 14:07 Iito

This pull request has a merge conflict that needs to be resolved.

github-actions[bot] avatar Sep 05 '25 08:09 github-actions[bot]