fastapi-openapi-cli 0.1.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,11 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: fastapi-openapi-cli
3
- Version: 0.1.0
3
+ Version: 0.2.2
4
4
  Summary: CLI tool to export FastAPI OpenAPI specifications
5
5
  Author: Hector Castro
6
6
  Author-email: Hector Castro <hectcastro@gmail.com>
7
7
  License: Apache-2.0
8
8
  Requires-Dist: fastapi>=0.115.0
9
- Requires-Dist: typer>=0.15.0
10
9
  Requires-Dist: pyyaml>=6.0.2
11
10
  Requires-Python: >=3.12
12
11
  Description-Content-Type: text/markdown
@@ -1,15 +1,15 @@
1
1
  [project]
2
2
  name = "fastapi-openapi-cli"
3
- version = "0.1.0"
3
+ version = "0.2.2"
4
4
  description = "CLI tool to export FastAPI OpenAPI specifications"
5
5
  readme = "README.md"
6
6
  license = { text = "Apache-2.0" }
7
7
  authors = [{ name = "Hector Castro", email = "hectcastro@gmail.com" }]
8
8
  requires-python = ">=3.12"
9
- dependencies = ["fastapi>=0.115.0", "typer>=0.15.0", "pyyaml>=6.0.2"]
9
+ dependencies = ["fastapi>=0.115.0", "pyyaml>=6.0.2"]
10
10
 
11
11
  [project.scripts]
12
- fastapi-openapi = "fastapi_openapi_cli.cli:app"
12
+ fastapi-openapi = "fastapi_openapi_cli.cli:main"
13
13
 
14
14
  [dependency-groups]
15
15
  dev = [
@@ -0,0 +1,50 @@
1
+ import argparse
2
+ import sys
3
+ from collections.abc import Sequence
4
+
5
+ from fastapi_openapi_cli.export import export_openapi
6
+ from fastapi_openapi_cli.loader import AppLoadError, load_app
7
+
8
+
9
+ def build_parser() -> argparse.ArgumentParser:
10
+ parser = argparse.ArgumentParser(
11
+ prog="fastapi-openapi",
12
+ description="CLI tool to export FastAPI OpenAPI specifications",
13
+ )
14
+ parser.add_argument(
15
+ "--app",
16
+ "-a",
17
+ required=True,
18
+ help="FastAPI app path (e.g., module:app)",
19
+ )
20
+ parser.add_argument(
21
+ "--output",
22
+ "-o",
23
+ default=None,
24
+ help="Output file path (default: stdout)",
25
+ )
26
+ return parser
27
+
28
+
29
+ def main(argv: Sequence[str] | None = None) -> int:
30
+ parser = build_parser()
31
+ arguments = list(argv) if argv is not None else sys.argv[1:]
32
+
33
+ if not arguments:
34
+ parser.print_help()
35
+ return 0
36
+
37
+ args = parser.parse_args(arguments)
38
+
39
+ try:
40
+ fastapi_app = load_app(args.app)
41
+ export_openapi(fastapi_app, args.output)
42
+ except AppLoadError as e:
43
+ print(str(e), file=sys.stderr)
44
+ return 1
45
+
46
+ return 0
47
+
48
+
49
+ if __name__ == "__main__":
50
+ raise SystemExit(main())
@@ -1,31 +0,0 @@
1
- import typer
2
-
3
- from fastapi_openapi_cli.export import export_openapi
4
- from fastapi_openapi_cli.loader import AppLoadError, load_app
5
-
6
- app = typer.Typer(
7
- name="fastapi-openapi",
8
- help="CLI tool to export FastAPI OpenAPI specifications",
9
- no_args_is_help=True,
10
- )
11
-
12
-
13
- @app.command()
14
- def export(
15
- app_path: str = typer.Option(..., "--app", "-a", help="FastAPI app path (e.g., module:app)"),
16
- output: str | None = typer.Option(
17
- None, "--output", "-o", help="Output file path (default: stdout)"
18
- ),
19
- ) -> None:
20
- """
21
- Export the OpenAPI specification from a FastAPI application.
22
-
23
- Supports both JSON and YAML formats. Format is auto-detected from file extension.
24
- If no output file is specified, outputs JSON to stdout.
25
- """
26
- try:
27
- fastapi_app = load_app(app_path)
28
- export_openapi(fastapi_app, output)
29
- except AppLoadError as e:
30
- typer.echo(str(e), err=True)
31
- raise typer.Exit(code=1) from e