-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathgenerateobjectsfromxsd.sh
More file actions
executable file
·129 lines (114 loc) · 3.51 KB
/
generateobjectsfromxsd.sh
File metadata and controls
executable file
·129 lines (114 loc) · 3.51 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# Script to generate the python contract from XSD
# Requires pyxb module to be installed and available in path
dt=`date '+%m/%d/%Y %H:%M:%S'`
AnetURL=https://apitest.authorize.net/xml/v1/schema/AnetApiSchema.xsd
AnetURLPERL='https:\/\/apitest.authorize.net\/xml\/v1\/schema\/AnetApiSchema.xsd'
LOCALXSDWITHANY=./script/AnetOut.xsd
CONTRACTSDIR=authorizenet
CONTRACTSFILE=apicontractsv1
PYXBGENPATH=`which pyxbgen`
TEMPFILE=binding
TEMPDIRECTORY=./script/temp
echo Starting pyxbgen on ${dt}
which python > /dev/null
if [ $? -eq 0 ]
then
echo Found python
else
echo Unable to find python. Make sure python is installed.
exit 1
fi
which pyxbgen > /tmp/pyxbgenpath.txt
if [ $? -eq 0 ]
then
echo Found pyxbgen
else
echo Unable to find pyxbgen. Make sure pyxb package is installed.
exit 1
fi
which perl > /dev/null
if [ $? -eq 0 ]
then
echo Found perl
else
echo Unable to find perl. Make sure perl is installed.
exit 1
fi
# which wget > /dev/null
# if [ $? -eq 0 ]
# then
# echo Found wget. Downloading AnetAPISchema file under Script directory.
# wget -O ./script/AnetApiSchema.xsd ${AnetURL}
# if [ $? -eq 0 ]
# then
# echo AnetAPISchema.xsd downloaded.
# else
# echo Unable to download AnetAPISchema.
# exit 1
# fi
# else
# echo Wget not found. Looking for Curl
# which curl > /dev/null
# if [ $? -eq 0 ]
# then
# echo Found curl. Downloading AnetAPISchema file under Script directory.
# curl --noproxy '*' ${AnetURL} > ./script/AnetApiSchema.xsd
# if [ $? -eq 0 ]
# then
# echo AnetAPISchema.xsd downloaded.
# else
# curl ${AnetURL} > ./script/AnetApiSchema.xsd
# if [ $? -eq 0 ]
# then
# echo AnetAPISchema.xsd downloaded.
# else
# echo Unable to download AnetAPISchema.
# exit 1
# fi
# fi
# else
# echo Unable to find wget and curl. Make sure either one is installed
# exit 1
# fi
# fi
echo Modifying XSD using perl to support backward compatibility
echo Creating temporary directory
mkdir -p "$TEMPDIRECTORY"
# Added since UpdateCustomerProfile API was updated for SOAP APIs, thus requiring changes to the contract object UpdateCustomerProfileRequest.
# Doesn't remove the type declaration for customerProfileInfoExType, but prevents it from being used anywhere else in the contract
perl -pi.back -e 's/type=\"anet:customerProfileInfoExType\"/type=\"anet:customerProfileExType\"/g;' script/AnetApiSchema.xsd
perl script/addany.pl script/AnetApiSchema.xsd ${TEMPDIRECTORY}/IntermediateAnetOut.xsd ${LOCALXSDWITHANY}
if [ $? -eq 0 ]
then
: #echo AnetOut.xsd generated #Uncomment for debugging
else
echo Unable to generate AnetOut.xsd
exit 1
fi
echo Deleting temporary directory
rm -rf "$TEMPDIRECTORY"
echo Using pyxb from "${PYXBGENPATH}"
if [ -e "${TEMPFILE}.py" ]; then
rm ${TEMPFILE}.py
fi
python "${PYXBGENPATH}" -u ${LOCALXSDWITHANY} -m ${TEMPFILE}
if [ $? -eq 0 ]
then
if [ -e "${CONTRACTSDIR}/${CONTRACTSFILE}.old" ]
then
rm "${CONTRACTSDIR}/${CONTRACTSFILE}.old"
fi
if [ -e "${CONTRACTSDIR}/${CONTRACTSFILE}.py" ]
then
rm "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
fi
mv "${TEMPFILE}.py" "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
echo Bindings have been successfully generated from XSD in the file "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
echo Old contracts have been moved to .old
else
echo Error generating bindings from XSD. Review the errors and rerun the script.
exit 1
fi
perl -i -pe "s/.Location\(\'.*xsd\'/.Location\(\'$AnetURLPERL\'/g" ${CONTRACTSDIR}/${CONTRACTSFILE}.py
exit 0