flask-ast-openapi 0.1.0__py3-none-any.whl
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.
- flask_ast_openapi/__init__.py +13 -0
- flask_ast_openapi/cli.py +70 -0
- flask_ast_openapi/generator.py +1685 -0
- flask_ast_openapi/swagger.py +104 -0
- flask_ast_openapi-0.1.0.dist-info/METADATA +14 -0
- flask_ast_openapi-0.1.0.dist-info/RECORD +10 -0
- flask_ast_openapi-0.1.0.dist-info/WHEEL +5 -0
- flask_ast_openapi-0.1.0.dist-info/entry_points.txt +2 -0
- flask_ast_openapi-0.1.0.dist-info/licenses/LICENSE +21 -0
- flask_ast_openapi-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Generate OpenAPI specifications from Flask source code using Python AST."""
|
|
2
|
+
|
|
3
|
+
from .generator import FlaskASTOpenAPI, PathParameter, RouteDefinition
|
|
4
|
+
from .swagger import create_swagger_blueprint
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0"
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"FlaskASTOpenAPI",
|
|
10
|
+
"PathParameter",
|
|
11
|
+
"RouteDefinition",
|
|
12
|
+
"create_swagger_blueprint",
|
|
13
|
+
]
|
flask_ast_openapi/cli.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Command-line interface for flask-ast-openapi."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from .generator import FlaskASTOpenAPI
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
10
|
+
"""Build the command-line argument parser."""
|
|
11
|
+
|
|
12
|
+
parser = argparse.ArgumentParser(
|
|
13
|
+
prog="flask-ast-openapi",
|
|
14
|
+
description=(
|
|
15
|
+
"Generate OpenAPI specifications from Flask source code."
|
|
16
|
+
),
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"source_dir",
|
|
21
|
+
type=Path,
|
|
22
|
+
help="Path to the Flask source directory.",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"--output",
|
|
27
|
+
"-o",
|
|
28
|
+
type=Path,
|
|
29
|
+
default=Path("openapi.json"),
|
|
30
|
+
help="Output file path.",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
"--title",
|
|
35
|
+
default="Flask API",
|
|
36
|
+
help="OpenAPI document title.",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
"--version",
|
|
41
|
+
default="1.0.0",
|
|
42
|
+
help="OpenAPI document version.",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
return parser
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def main() -> None:
|
|
49
|
+
"""Generate an OpenAPI specification from Flask source code."""
|
|
50
|
+
|
|
51
|
+
parser = build_parser()
|
|
52
|
+
args = parser.parse_args()
|
|
53
|
+
|
|
54
|
+
generator = FlaskASTOpenAPI(
|
|
55
|
+
args.source_dir
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
spec = generator.generate(
|
|
59
|
+
title=args.title,
|
|
60
|
+
version=args.version,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
generator.write_json(
|
|
64
|
+
spec,
|
|
65
|
+
args.output,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
main()
|