Skip to content

Commit 28c5d84

Browse files
committed
changing the input way for python script
1 parent 2f00c67 commit 28c5d84

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

generator/cybersource_ruby_SDK_gen.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
echo $0
33

4-
python replaceFieldNameFromRequestBody.py
4+
python replaceFieldNameFromRequestBody.py -i cybersource-rest-spec.json > replaceFieldLogs.log
5+
rm replaceFieldLogs.log
56

67

78
# Delete the previously generated SDK code
@@ -14,7 +15,7 @@ rm ../lib/cybersource_rest_client.rb
1415

1516
# Command to generate SDK
1617

17-
java -jar swagger-codegen-cli-2.2.3.jar generate -t cybersource-ruby-template -i rest-api-spec-ruby.json -l ruby -o ../ -c cybersource-ruby-config.json
18+
java -jar swagger-codegen-cli-2.2.3.jar generate -t cybersource-ruby-template -i cybersource-rest-spec-ruby.json -l ruby -o ../ -c cybersource-ruby-config.json
1819

1920
sed -i "s|select_header_content_type(\["\'"application\/json;charset=utf-8|select_header_content_type(\["\'"\*\/\*|g" ../lib/cybersource_rest_client/api/secure_file_share_api.rb
2021
#sed -i 's/$/\r/' ../lib/cybersource_rest_client/api/secure_file_share_api.rb

generator/replaceFieldNameFromRequestBody.py

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
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.
23

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
76

8-
apis = spec_json["paths"].keys()
97

108
# fieldNames in request and response body structure and change with the value of it.
119
# eg: fieldNames ={
@@ -17,6 +15,52 @@
1715
"hash": "sdkHashValue"
1816
}
1917

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+
2064
def replaceFieldNamefromJSONObject(jsonObject):
2165
fields= jsonObject.keys()
2266
for field in fields:
@@ -52,7 +96,8 @@ def replaceFieldNamefromJSONObjectForResponse(jsonObject):
5296
result_json[field]=jsonObject[field]
5397
return result_json
5498

55-
99+
spec_json= getSpecJson()
100+
apis = spec_json["paths"].keys()
56101
for api in apis:
57102
verbs = spec_json["paths"][api].keys()
58103
# print api end point to check the issue for which api it occured
@@ -97,7 +142,7 @@ def replaceFieldNamefromJSONObjectForResponse(jsonObject):
97142

98143

99144

100-
with open("rest-api-spec-ruby.json", "w") as outfile:
145+
with open("cybersource-rest-spec-ruby.json", "w") as outfile:
101146
json.dump(spec_json, outfile,indent=4)
102147

103148

0 commit comments

Comments
 (0)