-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathswagger_codegen.sh
executable file
·156 lines (105 loc) · 8.39 KB
/
swagger_codegen.sh
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
CURRENT_DIR=$(pwd)
# Defining a temporary directory for cloning
TMP_DIR=$(mktemp -d)
# Function to clean up the temporary directory
cleanup() {
echo "Cleaning up..."
rm -rf "$TMP_DIR"
}
# Trap to clean up in case of script exit or interruption
trap cleanup EXIT
curl -o $TMP_DIR/swagger.json https://raw.githubusercontent.com/dydxprotocol/v4-chain/main/indexer/services/comlink/public/swagger.json
# Remove required attribute
${CURRENT_DIR}/json_remove_attr.sh -f $TMP_DIR/swagger.json -a required
# Remove APIOrderStatus
${CURRENT_DIR}/json_remove_attr.sh -f $TMP_DIR/swagger.json -a APIOrderStatus
# Codegen doesn't support allOf with enum, so we need to replace it with the enum directly
# Add APIOrderStatus with content of OrderStatus and BestEffortOrderStatus
${CURRENT_DIR}/json_add_attr.sh $TMP_DIR/swagger.json '.components.schemas' APIOrderStatus TO_REPLACE
# Remove "TO_REPLACE" with the content of OrderStatus and BestEffortOrderStatus
sed -i '' "s/\"TO_REPLACE\"/{ \"enum\": [\"OPEN\",\"FILLED\",\"CANCELED\",\"BEST_EFFORT_CANCELED\",\"UNTRIGGERED\",\"BEST_EFFORT_OPENED\"],\"type\": \"string\" }/g" $TMP_DIR/swagger.json
cd "$TMP_DIR"
swagger-codegen generate -i swagger.json -o generated -l kotlin-client \
--model-package indexer.codegen
mv generated/src/main/kotlin/indexer/codegen/TransferResponseObject_sender.kt \
generated/src/main/kotlin/indexer/codegen/TransferResponseObjectSender.kt
# replace AllOfPerpetualPositionResponseObjectClosedAt with IsoString
sed -i '' 's/AllOfPerpetualPositionResponseObjectClosedAt/IsoString/' generated/src/main/kotlin/indexer/codegen/PerpetualPositionResponseObject.kt
# replace BESTEFFORTCANCELED with BEST_EFFORT_CANCELED in IndexerAPIOrderStatus.kt
sed -i '' 's/BESTEFFORTCANCELED/BEST_EFFORT_CANCELED/' generated/src/main/kotlin/indexer/codegen/APIOrderStatus.kt
# replace BESTEFFORTOPENED with BEST_EFFORT_OPENED in IndexerAPIOrderStatus.kt
sed -i '' 's/BESTEFFORTOPENED/BEST_EFFORT_OPENED/' generated/src/main/kotlin/indexer/codegen/APIOrderStatus.kt
# replace BESTEFFORTCANCELED with BEST_EFFORT_CANCELED in IndexerAPIOrderStatus.kt
sed -i '' 's/BESTEFFORTCANCELED/BEST_EFFORT_CANCELED/' generated/src/main/kotlin/indexer/codegen/OrderStatus.kt
# replace BESTEFFORTOPENED with BEST_EFFORT_OPENED in IndexerAPIOrderStatus.kt
sed -i '' 's/BESTEFFORTOPENED/BEST_EFFORT_OPENED/' generated/src/main/kotlin/indexer/codegen/OrderStatus.kt
# replace STOPLIMIT with STOP_LIMIT in IndexerAPIOrderType.kt
sed -i '' 's/STOPLIMIT/STOP_LIMIT/' generated/src/main/kotlin/indexer/codegen/OrderType.kt
# replace STOPMARKET with STOP_MARKET in IndexerAPIOrderType.kt
sed -i '' 's/STOPMARKET/STOP_MARKET/' generated/src/main/kotlin/indexer/codegen/OrderType.kt
# replace TRAILINGSTOP with TRAILING_STOP in IndexerAPIOrderType.kt
sed -i '' 's/TRAILINGSTOP/TRAILING_STOP/' generated/src/main/kotlin/indexer/codegen/OrderType.kt
# replace TAKEPROFIT with TAKE_PROFIT in IndexerAPIOrderType.kt
sed -i '' 's/TAKEPROFIT/TAKE_PROFIT/' generated/src/main/kotlin/indexer/codegen/OrderType.kt
# replace TAKEPROFITMARKET with TAKE_PROFIT_MARKET in IndexerAPIOrderType.kt
sed -i '' 's/TAKEPROFITMARKET/TAKE_PROFIT_MARKET/' generated/src/main/kotlin/indexer/codegen/OrderType.kt
# replace TRANSFERIN with TRANSFER_IN in TransferType.kt
sed -i '' 's/TRANSFERIN/TRANSFER_IN/' generated/src/main/kotlin/indexer/codegen/TransferType.kt
# replace TRANSFEROUT with TRANSFER_OUT in TransferType.kt
sed -i '' 's/TRANSFEROUT/TRANSFER_OUT/' generated/src/main/kotlin/indexer/codegen/TransferType.kt
# replace PerpetualPositionsMap with Map<String, PerpetualPositionResponseObject> in SubaccountResponseObject.kt
sed -i '' 's/\ PerpetualPositionsMap/\ Map<String, IndexerPerpetualPositionResponseObject>/g' generated/src/main/kotlin/indexer/codegen/SubaccountResponseObject.kt
# replace AssetPositionsMap with Map<String, AssetPositionResponseObject> in SubaccountResponseObject.kt
sed -i '' 's/\ AssetPositionsMap/\ Map<String, IndexerAssetPositionResponseObject>/g' generated/src/main/kotlin/indexer/codegen/SubaccountResponseObject.kt
# add import kotlinx.serialization.SerialName to the top of CandleResolution.kt
sed -i '' 's/package indexer.codegen/package indexer.codegen\n\nimport kotlinx.serialization.SerialName/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt
# add import kotlinx.serialization.Serializable to the top of CandleResolution.kt
sed -i '' 's/package indexer.codegen/package indexer.codegen\n\nimport kotlinx.serialization.Serializable/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt
# add @SerialName("1MIN") to _1MIN("1MIN") in CandleResolution.kt
sed -i '' 's/_1MIN("1MIN")/@SerialName("1MIN")\n _1MIN("1MIN")/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt
# add @SerialName("5MIN") to _5MIN("5MIN") in CandleResolution.kt
sed -i '' 's/_5MINS("5MINS")/@SerialName("5MINS")\n _5MINS("5MINS")/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt
# add @SerialName("15MIN") to _15MIN("15MIN") in CandleResolution.kt
sed -i '' 's/_15MINS("15MINS")/@SerialName("15MINS")\n _15MINS("15MINS")/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt
# add @SerialName("30MIN") to _30MIN("30MIN") in CandleResolution.kt
sed -i '' 's/_30MINS("30MINS")/@SerialName("30MINS")\n _30MINS("30MINS")/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt
# add @SerialName("1HOUR") to _1HOUR("1HOUR") in CandleResolution.kt
sed -i '' 's/_1HOUR("1HOUR")/@SerialName("1HOUR")\n _1HOUR("1HOUR")/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt
# add @SerialName("4HOUR") to _4HOUR("4HOUR") in CandleResolution.kt
sed -i '' 's/_4HOURS("4HOURS")/@SerialName("4HOURS")\n _4HOURS("4HOURS")/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt
# add @SerialName("1DAY") to _1DAY("1DAY") in CandleResolution.kt
sed -i '' 's/_1DAY("1DAY")/@SerialName("1DAY")\n _1DAY("1DAY")/' generated/src/main/kotlin/indexer/codegen/CandleResolution.kt
# replace CANCELONLY with CANCEL_ONLY in PerpetualMarketStatus.kt
sed -i '' 's/CANCELONLY/CANCEL_ONLY/' generated/src/main/kotlin/indexer/codegen/PerpetualMarketStatus.kt
# replace POSTONLY with POST_ONLY in PerpetualMarketStatus.kt
sed -i '' 's/POSTONLY/POST_ONLY/' generated/src/main/kotlin/indexer/codegen/PerpetualMarketStatus.kt
# replace FINALSETTLEMENT with FINAL_SETTLEMENT in PerpetualMarketStatus.kt
sed -i '' 's/FINALSETTLEMENT/FINAL_SETTLEMENT/' generated/src/main/kotlin/indexer/codegen/PerpetualMarketStatus.kt
# replace SANCTIONEDGEO with SANCTIONED_GEO in ComplianceReason.kt
sed -i '' 's/SANCTIONEDGEO/SANCTIONED_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt
# replace COMPLIANCEPROVIDER with COMPLIANCE_PROVIDER in ComplianceReason.kt
sed -i '' 's/COMPLIANCEPROVIDER/COMPLIANCE_PROVIDER/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt
# replace USGEO with US_GEO in ComplianceReason.kt
sed -i '' 's/USGEO/US_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt
# replace CAGEO with CA_GEO in ComplianceReason.kt
sed -i '' 's/CAGEO/CA_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt
# replace GBGEO with GB_GEO in ComplianceReason.kt
sed -i '' 's/GBGEO/GB_GEO/' generated/src/main/kotlin/indexer/codegen/ComplianceReason.kt
# replace FIRSTSTRIKECLOSEONLY with FIRST_STRIKE_CLOSE_ONLY in ComplianceStatus.kt
sed -i '' 's/FIRSTSTRIKECLOSEONLY/FIRST_STRIKE_CLOSE_ONLY/' generated/src/main/kotlin/indexer/codegen/ComplianceStatus.kt
# replace FIRSTSTRIKE with FIRST_STRIKE in ComplianceStatus.kt
sed -i '' 's/FIRSTSTRIKE/FIRST_STRIKE/' generated/src/main/kotlin/indexer/codegen/ComplianceStatus.kt
# replace CLOSEONLY with CLOSE_ONLY in ComplianceStatus.kt
sed -i '' 's/CLOSEONLY/CLOSE_ONLY/' generated/src/main/kotlin/indexer/codegen/ComplianceStatus.kt
# replace ONEDAY with ONE_DAY in SparklineTimePeriod.kt
sed -i '' 's/ONEDAY/ONE_DAY/' generated/src/main/kotlin/indexer/codegen/SparklineTimePeriod.kt
# replace SEVENDAYS with SEVEN_DAYS in SparklineTimePeriod.kt
sed -i '' 's/SEVENDAYS/SEVEN_DAYS/' generated/src/main/kotlin/indexer/codegen/SparklineTimePeriod.kt
# for each of the time in the generated code, run "swagger_update_file.sh <file>"
find generated/src/main/kotlin/indexer -type f \
-exec $CURRENT_DIR/swagger_update_file.sh {} \;
rm -rf $CURRENT_DIR/src/commonMain/kotlin/indexer/codegen
mv generated/src/main/kotlin/indexer/codegen $CURRENT_DIR/src/commonMain/kotlin/indexer
cd $CURRENT_DIR
./gradlew spotlessApply