Skip to content

Commit 28ca003

Browse files
committed
added file-name input option
1 parent 2afe819 commit 28ca003

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pip install fastapi-openapi-generator
1212
### How to use
1313
```
1414
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
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+
--file-name= # The name the openapi file will assume.
1718
```

generator/main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,24 @@
2222
show_default=True,
2323
help="The folder where the swagger is stored."
2424
)
25-
def main(app, app_dir, output_dir):
25+
@click.option(
26+
"--file-name",
27+
"file_name",
28+
default="openapi.json",
29+
show_default=True,
30+
help="The name the openapi file will assume."
31+
)
32+
def main(app, app_dir, output_dir, file_name):
2633
sys.path.insert(0, app_dir)
2734

2835
fastapi: FastAPI = import_from_string(app)
2936

3037
if not isinstance(fastapi, FastAPI):
3138
raise NotFastAPIException('The given object is not a FastAPI application')
3239

33-
with open('{}/openapi.json'.format(output_dir), 'w+') as openapi:
40+
with open('{}/{}'.format(output_dir, file_name), 'w+') as openapi:
3441
openapi.write(json.dumps(fastapi.openapi(), indent=2))
42+
openapi.close()
3543

3644
if __name__ == "__main__":
3745
main()

0 commit comments

Comments
 (0)