-
Notifications
You must be signed in to change notification settings - Fork 15
/
transformation.sh
executable file
·130 lines (112 loc) · 5.49 KB
/
transformation.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
#!/bin/bash
### -!- Workaround START
#
# Copy journal endpoint
#
echo "-!- WORKAROUND -!- Moving characters fleet from dev to latest"
#
# Copy dev endpoint to variable
#
ENDPOINT=$(jq ".paths[\"/v2/characters/{character_id}/fleet/\"]" dev.json)
#
# Delete the existing endpoint from latest
#
jq "del(.paths[\"/v1/characters/{character_id}/fleet/\"])" esi.json > work1.json
#
# Added the dev endpoint to latest
#
jq ".paths[\"/v2/characters/{character_id}/fleet/\"] = $ENDPOINT" work1.json > work2.json
#
# Rename json to default name
#
mv work2.json esi.json
### -!- Workaround END
# definitions
echo "Removing definitions"
jq "(.definitions) = {}" esi.json > work1.json
# Position
echo "Transforming position"
POS=$(jq ".paths[].get.responses.\"200\".schema.properties.position | select(.title == \"get_universe_structures_structure_id_position\")" work1.json)
jq ".definitions.position = $POS" work1.json > work2.json
jq "(.paths[][].responses.\"200\".schema.properties | select(.position != null).position ) = { \"\$ref\": \"#/definitions/position\" }" work2.json > work1.json
jq "(.paths[][].responses.\"200\".schema.properties | select(.victim != null).victim.properties.position) = { \"\$ref\": \"#/definitions/position\" }" work1.json > work2.json
jq "(.paths[][].responses.\"200\".schema.items.properties | select(.target != null).target.properties.coordinates) = { \"\$ref\": \"#/definitions/position\" }" work2.json > work1.json
sed -i -e 's#get_universe_structures_structure_id_position#Position#g' work1.json
# Recipient
echo "Transforming recipient"
RECIPIENT=$(jq ".paths[].get.responses.\"200\".schema.properties.recipients | select(.items != null).items" esi.json)
jq ".definitions.recipient = $RECIPIENT" work1.json > work2.json
jq "(.paths[].get.responses.\"200\".schema.properties.recipients | select(.items != null).items) = { \"\$ref\": \"#/definitions/recipient\" }" work2.json > work1.json
jq "(.paths[].get.responses[\"200\"].schema.items.properties.recipients | select(.items != null).items) = { \"\$ref\": \"#/definitions/recipient\" }" work1.json > work2.json
jq "(.paths[].post.parameters[2].schema.properties.recipients | select(.items != null).items) = { \"\$ref\": \"#/definitions/recipient\" }" work2.json > work1.json
sed -i -e 's#get_characters_character_id_mail_mail_id_recipient#Recipient#g' work1.json
# Killmail items are double named
echo "Transforming double named killmail items"
jq "(.paths[].get.responses[\"200\"].schema.properties.victim.properties.items.items.properties.items.items | select(.title != null).title) = \"KillmailSubItem\"" work1.json > work2.json
sed -e 's#get_killmails_killmail_id_killmail_hash_item#KillmailItem#' work2.json > work1.json
# Fitting item
echo "Transforming fitting item"
FITTINGITEM=$(jq ".paths[].get.responses.\"200\".schema.items.properties.items | select(.items != null).items" esi.json)
jq ".definitions.fitting_item = $FITTINGITEM" work1.json > work2.json
jq "(.paths[].get.responses.\"200\".schema.items.properties.items | select(.items != null).items) = { \"\$ref\": \"#/definitions/fitting_item\" }" work2.json > work1.json
jq "(.paths[].post.parameters[2].schema.properties.items | select(.title == \"post_characters_character_id_fittings_items\").items) = { \"\$ref\": \"#/definitions/fitting_item\" }" work1.json > work2.json
mv work2.json work1.json
# Bad request = 400
echo "Removing 400 Bad Request "
jq "(.paths[][].responses[\"400\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Unauthorized = 401
echo "Removing 401 Unauthorized"
jq "(.paths[][].responses[\"401\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Forbidden = 403
echo "Removing 401 Forbidden"
jq "(.paths[][].responses[\"403\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Not Found = 404
echo "Removing 404 Not Found"
jq "(.paths[][].responses[\"404\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Unauthorized = 420
echo "Removing 420 Error limited"
jq "(.paths[][].responses[\"420\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Unprocessable Entity = 422
echo "Removing 404 Not Found"
jq "(.paths[][].responses[\"422\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Internal server error = 500
echo "Removing 500 Internal Server Error"
jq "(.paths[][].responses[\"500\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Not modified = 502
echo "Removing 502 Bad Gateway"
jq "(.paths[][].responses[\"502\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Service unavailable = 503
echo "Removing 503 Service Unavailable"
jq "(.paths[][].responses[\"503\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Gateway timeout = 504
echo "Removing 504 Gateway Timeout"
jq "(.paths[][].responses[\"504\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# EVE server rate limit = 520
echo "Removing 520 EVE server rate limit"
jq "(.paths[][].responses[\"520\"]) = {}" work1.json > work2.json
mv work2.json work1.json
# Add SSO scope to description
echo "Adding SSO scopes"
jq ".paths[][] | select(.security[0].evesso) | [.description , .security[].evesso[0]] | @csv" work1.json > tmp.csv
sed -i -e 's#\\#\\\\#g' tmp.csv
sed -i -e 's#\/#\\\/#g' tmp.csv
sed -i -e 's#\[#\\\[#g' tmp.csv
sed -i -e 's#\]#\\\]#g' tmp.csv
sed -i -e 's#\.#\\\.#g' tmp.csv
sed -i -e 's#\$#\\\$#g' tmp.csv
sed -i -e 's#\*#\\\*#g' tmp.csv
sed -i -e 's#\^#\\\^#g' tmp.csv
sed -e 's|"\\\\"\(.*\)\\\\",\\\\"\(.*\)\\\\""|s/\1/\1\\\\n\\\\nSSO Scope: \2/g|' tmp.csv > scope.sed
sed -f scope.sed work1.json > esi.json
# Clean up
rm work1.json work2.json tmp.csv scope.sed