forked from wolfadex/elm-open-api-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestGenScript.elm
More file actions
215 lines (179 loc) · 8.71 KB
/
Copy pathTestGenScript.elm
File metadata and controls
215 lines (179 loc) · 8.71 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
module TestGenScript exposing (run)
import Ansi.Color
import BackendTask exposing (BackendTask)
import BackendTask.Custom
import Cli
import Cli.Option
import Cli.OptionsParser
import Cli.Program
import FatalError exposing (FatalError)
import Json.Decode
import Json.Encode
import OpenApi.Config
import Pages.Script
{-| Generate various SDKs as test cases, all at once.
This is more than twice as fast as running the generator separately for
each OAS.
-}
run : Pages.Script.Script
run =
let
additionalProperties : OpenApi.Config.Input
additionalProperties =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/additional-properties.yaml")
amadeusAirlineLookup : OpenApi.Config.Input
amadeusAirlineLookup =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/amadeus-airline-lookup.json")
anyOfEnums : OpenApi.Config.Input
anyOfEnums =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/anyOfEnums.yaml")
binaryResponse : OpenApi.Config.Input
binaryResponse =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/binary-response.yaml")
bug : Int -> OpenApi.Config.Input
bug n =
OpenApi.Config.inputFrom (OpenApi.Config.File ("./example/openapi-generator-bugs/" ++ String.fromInt n ++ ".yaml"))
cookieAuth : OpenApi.Config.Input
cookieAuth =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/cookie-auth.yaml")
dbFahrplanApi : OpenApi.Config.Input
dbFahrplanApi =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/db-fahrplan-api-specification.yaml")
gitHub : OpenApi.Config.Input
gitHub =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/github-spec.json")
|> OpenApi.Config.withWarnOnMissingEnums False
ifconfigOvh : OpenApi.Config.Input
ifconfigOvh =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/ifconfig.ovh.json")
marioPartyStats : OpenApi.Config.Input
marioPartyStats =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/MarioPartyStats.json")
multipartFormData : OpenApi.Config.Input
multipartFormData =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/multipart-form-data.yaml")
nullableEnum : OpenApi.Config.Input
nullableEnum =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/nullable-enum.yaml")
overridingGlobalSecurity : OpenApi.Config.Input
overridingGlobalSecurity =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/overriding-global-security.yaml")
|> OpenApi.Config.withOverrides [ OpenApi.Config.File "./example/overriding-global-security-override.yaml" ]
pathLevelParams : OpenApi.Config.Input
pathLevelParams =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/path-level-params.yaml")
patreon : OpenApi.Config.Input
patreon =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/patreon.json")
realworldConduit : OpenApi.Config.Input
realworldConduit =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/realworld-conduit.yaml")
recursiveAllOfRefs : OpenApi.Config.Input
recursiveAllOfRefs =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/recursive-allof-refs.yaml")
simpleRef : OpenApi.Config.Input
simpleRef =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/simple-ref.yaml")
singleEnum : OpenApi.Config.Input
singleEnum =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/single-enum.yaml")
telegramBot : OpenApi.Config.Input
telegramBot =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/telegram-bot.json")
trustmark : OpenApi.Config.Input
trustmark =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/trustmark.json")
|> OpenApi.Config.withOutputModuleName [ "Trustmark" ]
|> OpenApi.Config.withEffectTypes [ OpenApi.Config.ElmHttpCmd ]
|> OpenApi.Config.withServer (OpenApi.Config.Single "https://api.sandbox.retrofitintegration.data-hub.org.uk")
trustmarkTradeCheck : OpenApi.Config.Input
trustmarkTradeCheck =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/trustmark-trade-check.json")
|> OpenApi.Config.withOutputModuleName [ "Trustmark", "TradeCheck" ]
|> OpenApi.Config.withEffectTypes [ OpenApi.Config.ElmHttpCmd ]
tupleTriple : OpenApi.Config.Input
tupleTriple =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/tuple-triple.yaml")
|> OpenApi.Config.withEffectTypes [ OpenApi.Config.ElmHttpCmd ]
uuidArrayParam : OpenApi.Config.Input
uuidArrayParam =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/uuid-array-param.yaml")
viaggiatreno : OpenApi.Config.Input
viaggiatreno =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/viaggiatreno.yaml")
profileConfig : OpenApi.Config.Config
profileConfig =
-- Slimmed config for profiling
OpenApi.Config.init "./generated"
|> OpenApi.Config.withNoElmFormat True
|> OpenApi.Config.withKeepGoing True
|> OpenApi.Config.withInput additionalProperties
|> OpenApi.Config.withInput amadeusAirlineLookup
|> OpenApi.Config.withInput anyOfEnums
|> OpenApi.Config.withInput binaryResponse
|> OpenApi.Config.withInput cookieAuth
|> OpenApi.Config.withInput ifconfigOvh
|> OpenApi.Config.withInput marioPartyStats
|> OpenApi.Config.withInput multipartFormData
|> OpenApi.Config.withInput nullableEnum
|> OpenApi.Config.withInput overridingGlobalSecurity
|> OpenApi.Config.withInput pathLevelParams
|> OpenApi.Config.withInput realworldConduit
|> OpenApi.Config.withInput recursiveAllOfRefs
|> OpenApi.Config.withInput simpleRef
|> OpenApi.Config.withInput singleEnum
|> OpenApi.Config.withInput trustmark
|> OpenApi.Config.withInput trustmarkTradeCheck
|> OpenApi.Config.withInput tupleTriple
|> OpenApi.Config.withInput uuidArrayParam
|> OpenApi.Config.withInput viaggiatreno
|> OpenApi.Config.withInput (bug 7889)
|> OpenApi.Config.withInput (bug 10398)
|> OpenApi.Config.withInput (bug 16104)
|> OpenApi.Config.withInput (bug 22119)
|> OpenApi.Config.withInput (bug 22530)
config : OpenApi.Config.Config
config =
profileConfig
|> OpenApi.Config.withInput dbFahrplanApi
|> OpenApi.Config.withInput gitHub
|> OpenApi.Config.withInput patreon
|> OpenApi.Config.withInput telegramBot
|> OpenApi.Config.withNoElmFormat False
|> OpenApi.Config.withAutoConvertSwagger OpenApi.Config.AlwaysConvert
in
Pages.Script.withCliOptions programConfig
(\profile ->
if profile then
profiling "main" (Cli.withConfig profileConfig)
else
BackendTask.doEach
[ Cli.withConfig config
, "\nCompiling Example app"
|> Ansi.Color.fontColor Ansi.Color.brightGreen
|> Pages.Script.log
, Pages.Script.exec "sh"
[ "-c", "cd example && npx --no -- elm make src/Example.elm --output=/dev/null" ]
]
)
programConfig : Cli.Program.Config Bool
programConfig =
Cli.Program.config
|> Cli.Program.add
(Cli.OptionsParser.build identity
|> Cli.OptionsParser.with (Cli.Option.flag "profile")
)
profiling : String -> BackendTask FatalError a -> BackendTask FatalError a
profiling label task =
BackendTask.Custom.run "profile" (Json.Encode.string label) (Json.Decode.succeed ())
|> BackendTask.allowFatal
|> BackendTask.andThen
(\() ->
task
)
|> BackendTask.andThen
(\res ->
BackendTask.Custom.run "profileEnd" (Json.Encode.string label) (Json.Decode.succeed ())
|> BackendTask.allowFatal
|> BackendTask.map (\() -> res)
)