|
1 | | -import json |
| 1 | +#this script is written for changing the hash field name from the request json in spec file for generating the ruby sdk as |
| 2 | +# in ruby sdk there is an issue for Hash key field name in request & response body. |
2 | 3 |
|
3 | | -# changing the hash field name from the request json in spec file for generating the ruby sdk as |
4 | | -# in ruby sdk there is an issue for Hash key field name in request body. |
5 | | -with open("cybersource-rest-spec.json", "r") as read_file: |
6 | | - spec_json = json.load(read_file) |
| 4 | +import json |
| 5 | +import sys, getopt |
7 | 6 |
|
8 | | -apis = spec_json["paths"].keys() |
9 | 7 |
|
10 | 8 | # fieldNames in request and response body structure and change with the value of it. |
11 | 9 | # eg: fieldNames ={ |
|
17 | 15 | "hash": "sdkHashValue" |
18 | 16 | } |
19 | 17 |
|
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +def getSpecJson(): |
| 22 | + argumentList = sys.argv[1:] |
| 23 | + |
| 24 | + # Short Options |
| 25 | + # Short Options are `-h`, `-i` |
| 26 | + options = "hi:" |
| 27 | + |
| 28 | + # Long Options |
| 29 | + # Long Options are `--help`, `--inputFile = ` |
| 30 | + long_options = ["Help", "inputFile = "] |
| 31 | + inputFile = "" |
| 32 | + |
| 33 | + try: |
| 34 | + opts, args = getopt.getopt(argumentList, options, long_options) |
| 35 | + |
| 36 | + if not opts: |
| 37 | + print("Error : Missing Arguments") |
| 38 | + raise getopt.GetoptError("Usage Error") |
| 39 | + |
| 40 | + for opt, arg in opts: |
| 41 | + if opt in ("-h", "--Help"): |
| 42 | + print("Command Usage : main.py [-h | -i <inputFile>]") |
| 43 | + sys.exit() |
| 44 | + elif opt in ("-i", "--inputFile"): |
| 45 | + inputFile = arg.strip() |
| 46 | + if(inputFile == ""): |
| 47 | + print("Error : Missing input file") |
| 48 | + raise getopt.GetoptError("Filename cannot be blank") |
| 49 | + print(f"Using input file: {arg}") |
| 50 | + except getopt.GetoptError: |
| 51 | + print("Command Usage : main.py [-h | -i <inputFile>]") |
| 52 | + sys.exit() |
| 53 | + |
| 54 | + try: |
| 55 | + f = open(inputFile, encoding = "utf-8") |
| 56 | + except FileNotFoundError: |
| 57 | + print("Error : File not found") |
| 58 | + sys.exit() |
| 59 | + |
| 60 | + spec_json = json.load(f) |
| 61 | + return spec_json |
| 62 | + |
| 63 | + |
20 | 64 | def replaceFieldNamefromJSONObject(jsonObject): |
21 | 65 | fields= jsonObject.keys() |
22 | 66 | for field in fields: |
@@ -52,7 +96,8 @@ def replaceFieldNamefromJSONObjectForResponse(jsonObject): |
52 | 96 | result_json[field]=jsonObject[field] |
53 | 97 | return result_json |
54 | 98 |
|
55 | | - |
| 99 | +spec_json= getSpecJson() |
| 100 | +apis = spec_json["paths"].keys() |
56 | 101 | for api in apis: |
57 | 102 | verbs = spec_json["paths"][api].keys() |
58 | 103 | # print api end point to check the issue for which api it occured |
@@ -97,7 +142,7 @@ def replaceFieldNamefromJSONObjectForResponse(jsonObject): |
97 | 142 |
|
98 | 143 |
|
99 | 144 |
|
100 | | -with open("rest-api-spec-ruby.json", "w") as outfile: |
| 145 | +with open("cybersource-rest-spec-ruby.json", "w") as outfile: |
101 | 146 | json.dump(spec_json, outfile,indent=4) |
102 | 147 |
|
103 | 148 |
|
|
0 commit comments