-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-example.py
32 lines (26 loc) · 1.19 KB
/
get-example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
### Check whether ServiceInputs/example exists
import json
import pandas as pd
import argparse
def download_swagger_json(testdata):
SWAGGER_DIR_PATH = './swagger'
SWAGGER_JSON_PATH = f'{SWAGGER_DIR_PATH}/swagger_spec.json'
# read ./swagger/swagger_spec.json
with open(SWAGGER_JSON_PATH, 'r') as file:
swagger_data = json.load(file)
example = swagger_data['definitions']['ServiceInput']['example']
first_key = list(example.keys())[0]
df = pd.read_csv(testdata, index_col=None)
example_data = json.loads(df[df.index==0].to_json(orient='split'))
# final json scheme
final_data = {f"{first_key}": example_data}
swagger_data['definitions']['ServiceInput']['example'] = final_data
# update ./swagger/swagger_spec.json
with open(SWAGGER_JSON_PATH, 'w') as json_file:
json.dump(swagger_data, json_file, indent=2)
print("added ServiceInput example")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Get Example Json from testdata csv')
parser.add_argument('--testdata', required=True, help='ACTUAL TestData CSV Path')
args = parser.parse_args()
download_swagger_json(args.testdata)