File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ pip install fastapi-openapi-generator
12
12
### How to use
13
13
```
14
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
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.
17
18
```
Original file line number Diff line number Diff line change 22
22
show_default = True ,
23
23
help = "The folder where the swagger is stored."
24
24
)
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 ):
26
33
sys .path .insert (0 , app_dir )
27
34
28
35
fastapi : FastAPI = import_from_string (app )
29
36
30
37
if not isinstance (fastapi , FastAPI ):
31
38
raise NotFastAPIException ('The given object is not a FastAPI application' )
32
39
33
- with open ('{}/openapi.json ' .format (output_dir ), 'w+' ) as openapi :
40
+ with open ('{}/{} ' .format (output_dir , file_name ), 'w+' ) as openapi :
34
41
openapi .write (json .dumps (fastapi .openapi (), indent = 2 ))
42
+ openapi .close ()
35
43
36
44
if __name__ == "__main__" :
37
45
main ()
You can’t perform that action at this time.
0 commit comments