Skip to content

Commit 8300140

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

File tree

11 files changed

+44
-44
lines changed

11 files changed

+44
-44
lines changed

.idea/fastapi-cli.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ In most cases you would (and should) have a "termination proxy" handling HTTPS f
106106

107107
When you run `fastapi schema`, it will generate a swagger/openapi document.
108108

109-
This document will be output to stderr by default, however `--output <filename>` option can be used to write output into file. You can control the format of the JSON file by specifying indent level with `--indent #`. If set to 0, JSON will be in the minimal/compress form. Default is 2 spaces.
109+
This document will be output to stderr by default, however `--output <filename>` option can be used to write output into file. You can control the format of the JSON file by specifying indent level with `--indent #`. If set to 0, JSON will be in the minimal/compress form. Default is 2 spaces.
110110

111111
## License
112112

openapi.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
}
2323
}
2424
}
25-
}
25+
}

src/fastapi_cli/cli.py

+28-29
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from rich.panel import Panel
1111
from typing_extensions import Annotated
1212

13-
from fastapi_cli.discover import get_import_string
14-
from fastapi_cli.discover import get_app
13+
from fastapi_cli.discover import get_app, get_import_string
1514
from fastapi_cli.exceptions import FastAPICLIException
1615

1716
from . import __version__
@@ -275,35 +274,34 @@ def run(
275274
proxy_headers=proxy_headers,
276275
)
277276

277+
278278
@app.command()
279279
def schema(
280-
path: Annotated[
281-
Union[Path, None],
282-
typer.Argument(
283-
help="A path to a Python file or package directory (with [blue]__init__.py[/blue] files) containing a [bold]FastAPI[/bold] app. If not provided, a default set of paths will be tried."
284-
),
285-
] = None,
286-
*,
287-
app: Annotated[
288-
Union[str, None],
289-
typer.Option(
290-
help="The name of the variable that contains the [bold]FastAPI[/bold] app in the imported module or package. If not provided, it is detected automatically."
291-
),
292-
] = None,
293-
output: Annotated[
294-
Union[str, None],
295-
typer.Option(
296-
help="The filename to write schema to. If not provided, write to stderr."
297-
),
298-
] = None,
299-
indent: Annotated[
300-
int,
301-
typer.Option(
302-
help="JSON format indent. If 0, disable pretty printing"
303-
),
304-
] = 2,
305-
) -> Any:
306-
""" Generate schema """
280+
path: Annotated[
281+
Union[Path, None],
282+
typer.Argument(
283+
help="A path to a Python file or package directory (with [blue]__init__.py[/blue] files) containing a [bold]FastAPI[/bold] app. If not provided, a default set of paths will be tried."
284+
),
285+
] = None,
286+
*,
287+
app: Annotated[
288+
Union[str, None],
289+
typer.Option(
290+
help="The name of the variable that contains the [bold]FastAPI[/bold] app in the imported module or package. If not provided, it is detected automatically."
291+
),
292+
] = None,
293+
output: Annotated[
294+
Union[str, None],
295+
typer.Option(
296+
help="The filename to write schema to. If not provided, write to stderr."
297+
),
298+
] = None,
299+
indent: Annotated[
300+
int,
301+
typer.Option(help="JSON format indent. If 0, disable pretty printing"),
302+
] = 2,
303+
) -> Any:
304+
"""Generate schema"""
307305
app = get_app(path=path, app_name=app)
308306
schema = app.openapi()
309307

@@ -313,5 +311,6 @@ def schema(
313311
stream.close()
314312
return 0
315313

314+
316315
def main() -> None:
317316
app()

src/fastapi_cli/discover.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ModuleData:
4949

5050
@contextmanager
5151
def sys_path(self):
52-
""" Context manager to temporarily alter sys.path"""
52+
"""Context manager to temporarily alter sys.path"""
5353
extra_sys_path = str(self.extra_sys_path) if self.extra_sys_path else ""
5454
if extra_sys_path:
5555
logger.warning("Adding %s to sys.path...", extra_sys_path)
@@ -179,8 +179,9 @@ def get_import_string(
179179
logger.info(f"Using import string [b green]{import_string}[/b green]")
180180
return import_string
181181

182+
182183
def get_app(
183-
*, path: Union[Path, None] = None, app_name: Union[str, None] = None
184+
*, path: Union[Path, None] = None, app_name: Union[str, None] = None
184185
) -> FastAPI:
185186
if not path:
186187
path = get_default_path()
@@ -227,5 +228,4 @@ def get_app(
227228
obj = getattr(mod, name)
228229
if isinstance(obj, FastAPI):
229230
return obj
230-
raise FastAPICLIException(
231-
"Could not find FastAPI app in module, try using --app")
231+
raise FastAPICLIException("Could not find FastAPI app in module, try using --app")

tests/assets/openapi.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
}
2323
}
2424
}
25-
}
25+
}

tests/test_cli.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,15 @@ def test_dev_help() -> None:
179179
assert "The name of the variable that contains the FastAPI app" in result.output
180180
assert "Use multiple worker processes." not in result.output
181181

182+
182183
def test_schema() -> None:
183184
with changing_dir(assets_path):
184-
with open('openapi.json', 'r') as stream:
185+
with open("openapi.json") as stream:
185186
expected = stream.read()
186-
assert expected != "" , "Failed to read expected result"
187+
assert expected != "", "Failed to read expected result"
187188
result = runner.invoke(app, ["schema", "single_file_app.py"])
188189
assert result.exit_code == 0, result.output
189-
assert expected in result.output, result.output
190+
assert expected in result.output, result.output
190191

191192

192193
def test_run_help() -> None:

0 commit comments

Comments
 (0)