|
7 | 7 | import os |
8 | 8 |
|
9 | 9 | from flask import json |
10 | | -from time_tracker_api import create_app |
11 | 10 | from flask_script import Manager |
| 11 | + |
| 12 | +from time_tracker_api import create_app |
12 | 13 | from time_tracker_api.api import api |
13 | 14 |
|
14 | 15 | app = create_app() |
15 | 16 | cli_manager = Manager(app) |
16 | 17 |
|
17 | 18 |
|
18 | 19 | @cli_manager.command |
19 | | -@cli_manager.option('-f', '--filename', help='Path of the swagger file. By default swagger.json') |
| 20 | +@cli_manager.option('-f', '--filename', |
| 21 | + dest='filename', |
| 22 | + help='Path of the swagger file. By default swagger.json') |
20 | 23 | def gen_swagger_json(filename='swagger.json'): |
21 | 24 | """ Exports swagger specifications in json format """ |
22 | 25 | schema_json_data = json.dumps(api.__schema__) |
23 | 26 | save_data(schema_json_data, filename) |
24 | 27 |
|
25 | 28 |
|
26 | 29 | @cli_manager.command |
27 | | -@cli_manager.option('-f', '--filename', dest='filename', help='Path of the postman collection file.' |
28 | | - 'By default it is timetracker-api-postman-collection.json') |
29 | | -def gen_postman_collection(filename='timetracker-api-postman-collection.json'): |
| 30 | +@cli_manager.option('-f', '--filename', |
| 31 | + dest='filename', |
| 32 | + help='Path of the postman collection file.' |
| 33 | + 'By default it is timetracker-api-postman-collection.json') |
| 34 | +@cli_manager.option('-b', '--base-url-placeholder', |
| 35 | + dest='base_url_placeholder', |
| 36 | + help='Text used as placeholder. E.g. {{timetracker_api_host}}.' |
| 37 | + 'By default the base url will be http://localhost') |
| 38 | +def gen_postman_collection(filename='timetracker-api-postman-collection.json', |
| 39 | + base_url_placeholder=None): |
30 | 40 | """ Generates a Postman collection for the API """ |
31 | 41 | data = api.as_postman(urlvars=False, swagger=True) |
32 | 42 | postman_collection_json_data = json.dumps(data) |
33 | | - parsed_json = postman_collection_json_data.replace("http://localhost", '{{timetracker_api_host}}') |
| 43 | + if base_url_placeholder is not None: |
| 44 | + parsed_json = postman_collection_json_data.replace("http://localhost", base_url_placeholder) |
| 45 | + else: |
| 46 | + parsed_json = postman_collection_json_data |
| 47 | + |
34 | 48 | save_data(parsed_json, filename) |
35 | 49 |
|
36 | 50 |
|
37 | | -def save_data(data, filename): |
| 51 | +def save_data(data: str, filename: str) -> None: |
38 | 52 | """ Save text content to a file """ |
39 | 53 | if filename: |
40 | 54 | try: |
|
0 commit comments