Skip to content

Commit eff1375

Browse files
committed
Initial Commit
0 parents  commit eff1375

File tree

9 files changed

+129
-0
lines changed

9 files changed

+129
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/build/*
2+
/dist/*
3+
/swagger_confluence_pub.egg-info/*
4+
/venv/*
5+
**/.DS_Store
6+
**/*.pyc
7+
.vscode/*
8+
/.eggs/*
9+
/docs/build/*
10+
/test-reports/*
11+
/_build/*
12+
/_static/*
13+
/_templates/*
14+
/__pycache__/*
15+
/*.egg-info/

LICENSE.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
MIT License
2+
Copyright (c) 2018 YOUR NAME
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
The above copyright notice and this permission notice shall be included in all
10+
copies or substantial portions of the Software.
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17+
SOFTWARE.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### What this repository contains
2+
3+
A Command Line Interface to save openapi file from a FastAPI application
4+
5+
### Installation:
6+
7+
install the package
8+
```
9+
pip install fastapi-openapi-generator
10+
```
11+
12+
### How to use
13+
```
14+
fastapi-openapi-gen main:app \
15+
--app-dir= # The path to mounth in the python path to import the module \
16+
--output-dir= # The path where store the openapi template
17+
```

generator/__init__.py

Whitespace-only changes.

generator/lib/__init__.py

Whitespace-only changes.

generator/lib/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class NotFastAPIException(Exception):
2+
pass

generator/main.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
import json
3+
import click
4+
from fastapi import FastAPI
5+
from uvicorn.importer import import_from_string
6+
from generator.lib.exceptions import NotFastAPIException
7+
8+
@click.command()
9+
@click.argument("app")
10+
@click.option(
11+
"--app-dir",
12+
"app_dir",
13+
default=".",
14+
show_default=True,
15+
help="Look for APP in the specified directory, by adding this to the PYTHONPATH."
16+
" Defaults to the current working directory."
17+
)
18+
@click.option(
19+
"--output-dir",
20+
"output_dir",
21+
default=".",
22+
show_default=True,
23+
help="The folder where the swagger is stored."
24+
)
25+
def main(app, app_dir, output_dir):
26+
sys.path.insert(0, app_dir)
27+
28+
fastapi: FastAPI = import_from_string(app)
29+
30+
if not isinstance(fastapi, FastAPI):
31+
raise NotFastAPIException('The given object is not a FastAPI application')
32+
33+
with open('{}/openapi.json'.format(output_dir), 'w+') as openapi:
34+
openapi.write(json.dumps(fastapi.openapi(), indent=2))
35+
36+
if __name__ == "__main__":
37+
main()

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
click==7.1.2
2+
uvicorn==0.13.3
3+
fastapi==0.63.0

setup.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# pylint: disable=line-too-long
2+
"""
3+
:author: Pasquale Carmone Carbone
4+
5+
Setup module
6+
"""
7+
import setuptools
8+
9+
with open("README.md", "r") as fh:
10+
LONG_DESCRIPTION = fh.read()
11+
12+
with open('requirements.txt', 'r') as fin:
13+
REQS = fin.read().splitlines()
14+
15+
setuptools.setup(
16+
setup_requires=['setuptools-git-version'],
17+
version_format='{tag}',
18+
name="fastapi-openapi-generator",
19+
author="Pasquale Carmine Carbone",
20+
author_email="[email protected]",
21+
description="A Command Line Interface to save openapi file from a FastAPI application",
22+
long_description=LONG_DESCRIPTION,
23+
url="https://github.com/KiraPC/fastapi-openapi-generator",
24+
long_description_content_type="text/markdown",
25+
packages=setuptools.find_packages(exclude=['venv', 'fastapi-openapi-generator.egg-info', 'build']),
26+
classifiers=[
27+
"Programming Language :: Python :: 3",
28+
"License :: OSI Approved :: MIT License",
29+
"Operating System :: OS Independent",
30+
],
31+
entry_points={
32+
'console_scripts': [
33+
'fastapi-openapi-gen = generator.main:main'
34+
]
35+
},
36+
python_requires='>=3.0',
37+
install_requires=REQS
38+
)

0 commit comments

Comments
 (0)