Skip to content

Commit c4e42b5

Browse files
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
1 parent df0329b commit c4e42b5

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

src/fastapi_cli/cli.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
from rich.panel import Panel
99
from typing_extensions import Annotated
1010

11-
from fastapi_cli.discover import get_import_string, get_api_spec
11+
from fastapi_cli.discover import get_api_spec, get_import_string
1212
from fastapi_cli.exceptions import FastAPICLIException
1313

1414
from . import __version__
1515
from .logging import setup_logging
1616
from .utils import generate_markdown
17+
1718
app = typer.Typer(rich_markup_mode="rich")
1819

1920
setup_logging()
@@ -272,6 +273,7 @@ def run(
272273
proxy_headers=proxy_headers,
273274
)
274275

276+
275277
@app.command()
276278
def doc(
277279
path: Annotated[
@@ -291,9 +293,9 @@ def doc(
291293
Union[str, None],
292294
typer.Option(
293295
help="The title to use for the generated markdown file. If not provided, it is detected automatically."
294-
)
296+
),
295297
] = None,
296-
) -> None:
298+
) -> None:
297299
"""
298300
Generate [bold]FastAPI[/bold] API docs. 📚
299301
@@ -320,5 +322,6 @@ def doc(
320322
with open(f"{title.upper()}.md", "w") as f:
321323
f.write(markdown)
322324

325+
323326
def main() -> None:
324327
app()

src/fastapi_cli/discover.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import importlib
2+
import inspect
23
import sys
34
from dataclasses import dataclass
45
from logging import getLogger
56
from pathlib import Path
67
from typing import Union
7-
import inspect
88

99
from rich import print
1010
from rich.padding import Padding
@@ -168,13 +168,17 @@ def get_import_string(
168168
logger.info(f"Using import string [b green]{import_string}[/b green]")
169169
return import_string
170170

171+
171172
def get_api_spec(import_string: str) -> dict:
172173
app_module, app_name = import_string.replace("/", ".").rsplit(":", 1)
173174
app = getattr(__import__(app_module, fromlist=[app_name]), app_name)
174175
signature = inspect.signature(get_openapi)
175-
props = {prop.name: getattr(app, prop.name, None) for prop in signature.parameters.values()}
176-
176+
props = {
177+
prop.name: getattr(app, prop.name, None)
178+
for prop in signature.parameters.values()
179+
}
180+
177181
props["webhooks"] = None
178182
spec = get_openapi(**props)
179-
180-
return spec
183+
184+
return spec

src/fastapi_cli/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def generate_markdown(api_spec, title):
3434
schema = param.get("schema", {})
3535
schema_str = f"`type: {schema.get('type', 'N/A')}`<br>`title: {schema.get('title', 'N/A')}`"
3636
if "description" in schema:
37-
schema_str += f"<br>`description: {schema.get('description', 'N/A')}`"
37+
schema_str += (
38+
f"<br>`description: {schema.get('description', 'N/A')}`"
39+
)
3840
if "enum" in schema:
3941
schema_str += f"<br>`enum: {schema.get('enum')}`"
4042
if "default" in schema:
@@ -50,7 +52,7 @@ def generate_markdown(api_spec, title):
5052
if request_body:
5153
md.append("**Request Body:**")
5254
md.append(f"- **Required:** {request_body.get('required', False)}")
53-
md.append(f"- **Content:**")
55+
md.append("- **Content:**")
5456
content = request_body.get("content", {})
5557
for content_type, content_schema in content.items():
5658
md.append(f" - **{content_type}:**")
@@ -72,7 +74,9 @@ def generate_markdown(api_spec, title):
7274
for content_type, content_schema in content.items():
7375
schema_ref = content_schema.get("schema", {}).get("$ref", "N/A")
7476
content_str += f"{content_type}: `schema: [{schema_ref.split('/')[-1]}](#{schema_ref.split('/')[-1].lower()})`<br>"
75-
md.append(f"| {status} | {description} | {content_str.strip('<br>')} |")
77+
md.append(
78+
f"| {status} | {description} | {content_str.strip('<br>')} |"
79+
)
7680

7781
# Components
7882
components = api_spec.get("components", {}).get("schemas", {})
@@ -83,7 +87,9 @@ def generate_markdown(api_spec, title):
8387
md.append(f"##### {schema_name}")
8488
md.append(f"- **Type:** {schema_details.get('type', 'N/A')}")
8589
if "required" in schema_details:
86-
md.append(f"- **Required:** {', '.join(schema_details.get('required', []))}")
90+
md.append(
91+
f"- **Required:** {', '.join(schema_details.get('required', []))}"
92+
)
8793
md.append(f"- **Title:** {schema_details.get('title', 'N/A')}")
8894
md.append("- **Properties:**")
8995
properties = schema_details.get("properties", {})

0 commit comments

Comments
 (0)