@@ -16,6 +16,7 @@ function Invoke-MgmtTestgen ()
16
16
[switch ]$cleanGenerated ,
17
17
[switch ]$format ,
18
18
[switch ]$tidy ,
19
+ [switch ]$alwaysSetBodyParamRequired ,
19
20
[string ]$autorestPath = " " ,
20
21
[string ]$config = " autorest.md" ,
21
22
[string ]$autorestVersion = " 3.8.2" ,
@@ -40,7 +41,8 @@ function Invoke-MgmtTestgen ()
40
41
{
41
42
Write-Host " ##[command]Executing autorest.gotest in " $sdkDirectory
42
43
43
- if ($autorestPath -eq " " ) {
44
+ if ($autorestPath -eq " " )
45
+ {
44
46
$autorestPath = " ./" + $config
45
47
}
46
48
@@ -59,8 +61,15 @@ function Invoke-MgmtTestgen ()
59
61
{
60
62
$mockTestFlag = " false"
61
63
}
62
- Write-Host " autorest --version=$autorestVersion --use=$goExtension --use=$testExtension --go --track2 --output-folder=$outputFolder --clear-output-folder=false --go.clear-output-folder=false --generate-sdk=false --testmodeler.generate-mock-test=$mockTestFlag --testmodeler.generate-sdk-example=$exampleFlag $autorestPath "
63
- npx autorest -- version= $autorestVersion -- use= $goExtension -- use= $testExtension -- go -- track2 -- output- folder= $outputFolder -- clear-output - folder= false -- go.clear-output - folder= false -- generate- sdk= false -- testmodeler.generate- mock- test= $mockTestFlag -- testmodeler.generate- sdk- example= $exampleFlag $autorestPath
64
+
65
+ $honorBodyPlacement = " false"
66
+ if (-not $alwaysSetBodyParamRequired )
67
+ {
68
+ $honorBodyPlacement = " true"
69
+ }
70
+
71
+ Write-Host " autorest --version=$autorestVersion --use=$goExtension --use=$testExtension --go --track2 --output-folder=$outputFolder --clear-output-folder=false --go.clear-output-folder=false --generate-sdk=false --testmodeler.generate-mock-test=$mockTestFlag --testmodeler.generate-sdk-example=$exampleFlag --honor-body-placement=$honorBodyPlacement $autorestPath "
72
+ npx autorest -- version= $autorestVersion -- use= $goExtension -- use= $testExtension -- go -- track2 -- output- folder= $outputFolder -- clear-output - folder= false -- go.clear-output - folder= false -- generate- sdk= false -- testmodeler.generate- mock- test= $mockTestFlag -- testmodeler.generate- sdk- example= $exampleFlag -- honor- body- placement= $honorBodyPlacement $autorestPath
64
73
if ($LASTEXITCODE )
65
74
{
66
75
Write-Host " ##[error]Error running autorest.gotest"
@@ -134,16 +143,21 @@ function StartMockServer()
134
143
135
144
$swaggerPath = $swaggerInfo.path
136
145
$specName = $swaggerInfo.specName
137
- if ($swaggerInfo.isRepoUrl -eq $true ) {
146
+ if ($swaggerInfo.isRepoUrl -eq $true )
147
+ {
138
148
Add-Content $envFile " specRetrievalGitUrl=$swaggerPath "
139
- if ([string ]::IsNullOrEmpty($swaggerInfo.branch ) -eq $false ) {
149
+ if ([string ]::IsNullOrEmpty($swaggerInfo.branch ) -eq $false )
150
+ {
140
151
Add-Content $envFile " specRetrievalGitBranch=$ ( $swaggerInfo.branch ) "
141
152
}
142
- if ([string ]::IsNullOrEmpty($swaggerInfo.commitID ) -eq $false ) {
153
+ if ([string ]::IsNullOrEmpty($swaggerInfo.commitID ) -eq $false )
154
+ {
143
155
Add-Content $envFile " specRetrievalGitCommitID=$ ( $swaggerInfo.commitID ) "
144
156
}
145
157
Add-Content $envFile " validationPathsPattern=specification/$specName /resource-manager/**/*.json"
146
- } else {
158
+ }
159
+ else
160
+ {
147
161
Write-Host " start Mock Test from local swagger"
148
162
Add-Content $envFile " specRetrievalMethod=filesystem
149
163
specRetrievalLocalRelativePath=$swaggerPath
@@ -191,7 +205,8 @@ function StopMockServer()
191
205
}
192
206
}
193
207
194
- function GetSwaggerInfo () {
208
+ function GetSwaggerInfo ()
209
+ {
195
210
param (
196
211
[string ]$specDir = " " ,
197
212
[string ]$rpSDKFolder ,
@@ -200,29 +215,35 @@ function GetSwaggerInfo() {
200
215
201
216
if ([string ]::IsNullOrEmpty($rpSDKFolder ))
202
217
{
203
- if ([string ]::IsNullOrEmpty($specDir )) {
218
+ if ([string ]::IsNullOrEmpty($specDir ))
219
+ {
204
220
$swaggerInfo = [PSCustomObject ]@ {
205
221
isRepoUrl = $true
206
- path = " https://github.com/Azure/azure-rest-api-specs"
207
- specName = " *"
208
- org = " Azure"
209
- branch = " main"
210
- commitID = " "
222
+ path = " https://github.com/Azure/azure-rest-api-specs"
223
+ specName = " *"
224
+ org = " Azure"
225
+ branch = " main"
226
+ commitID = " "
211
227
}
212
- } else {
228
+ }
229
+ else
230
+ {
213
231
$swaggerInfo = [PSCustomObject ]@ {
214
232
isRepoUrl = $false
215
- path = $specDir
216
- specName = " *"
217
- org = " "
218
- branch = " "
219
- commitID = " "
233
+ path = $specDir
234
+ specName = " *"
235
+ org = " "
236
+ branch = " "
237
+ commitID = " "
220
238
}
221
239
}
222
- } else {
223
- $file = " $rpSDKFolder /$autorestConfigFile "
224
- $readmefile = (Select-String - Path $file - Pattern " .*readme.md" | ForEach-Object {$_.Matches.Value }) -replace " require *:|- " , " "
225
- if ([string ]::IsNullOrEmpty($readmefile )) {
240
+ }
241
+ else
242
+ {
243
+ $file = " $rpSDKFolder /$autorestConfigFile "
244
+ $readmefile = (Select-String - Path $file - Pattern " .*readme.md" | ForEach-Object { $_.Matches.Value }) -replace " require *:|- " , " "
245
+ if ([string ]::IsNullOrEmpty($readmefile ))
246
+ {
226
247
Write-Host " Cannot get swagger info"
227
248
exit 1
228
249
}
@@ -236,10 +257,12 @@ function GetSwaggerInfo() {
236
257
$commitID = " "
237
258
$readmefile = $readmefile.Trim ()
238
259
239
- if ($readmefile.StartsWith (" http" )) {
260
+ if ($readmefile.StartsWith (" http" ))
261
+ {
240
262
$isRepoUrl = $true
241
263
}
242
- if ($isRepoUrl -eq $true ) {
264
+ if ($isRepoUrl -eq $true )
265
+ {
243
266
$swaggerInfoRegex = " .*github.*.com\/(?<org>.*)\/azure-rest-api-specs\/blob\/(?<commitID>[0-9a-f]{40})\/specification\/(?<specName>.*)\/resource-manager\/readme.md"
244
267
$rawSwaggerInfoRegex = " .*github.*.com\/(?<org>.*)\/azure-rest-api-specs\/(?<commitID>[0-9a-f]{40})\/specification\/(?<specName>.*)\/resource-manager\/readme.md"
245
268
$swaggerNoCommitRegex = " .*github.*.com\/(?<org>.*)\/azure-rest-api-specs\/(blob\/)?(?<branch>.*)\/specification\/(?<specName>.*)\/resource-manager\/readme.md"
@@ -251,13 +274,15 @@ function GetSwaggerInfo() {
251
274
$specName = $matches [" specName" ]
252
275
$commitID = $matches [" commitID" ]
253
276
$path = " https://github.com/$org /azure-rest-api-specs"
254
- } elseif ($readmefile -match $rawSwaggerInfoRegex )
277
+ }
278
+ elseif ($readmefile -match $rawSwaggerInfoRegex )
255
279
{
256
280
$org = $matches [" org" ]
257
281
$specName = $matches [" specName" ]
258
282
$commitID = $matches [" commitID" ]
259
283
$path = " https://github.com/$org /azure-rest-api-specs"
260
- }elseif ($readmefile -match $swaggerNoCommitRegex )
284
+ }
285
+ elseif ($readmefile -match $swaggerNoCommitRegex )
261
286
{
262
287
$org = $matches [" org" ]
263
288
$specName = $matches [" specName" ]
@@ -270,22 +295,25 @@ function GetSwaggerInfo() {
270
295
Write-Error " Error parsing swagger info"
271
296
Write-Error $_
272
297
}
273
- } else {
298
+ }
299
+ else
300
+ {
274
301
$paths = $readmefile.split (" /" );
275
302
$len = $paths.count
276
- if ($len -gt 2 ) {
303
+ if ($len -gt 2 )
304
+ {
277
305
$specName = $paths [$len - 3 ]
278
306
$path = ($paths [0 .. ($len - 4 )]) -join " /"
279
307
}
280
308
}
281
309
282
310
$swaggerInfo = [PSCustomObject ]@ {
283
311
isRepoUrl = $isRepoUrl
284
- path = $path
285
- specName = $specName
286
- org = $org
287
- branch = $branch
288
- commitID = $commitID
312
+ path = $path
313
+ specName = $specName
314
+ org = $org
315
+ branch = $branch
316
+ commitID = $commitID
289
317
}
290
318
}
291
319
@@ -329,16 +357,18 @@ function JudgeExitCode($errorMsg = "execution error")
329
357
}
330
358
}
331
359
332
- function ExecuteSingleTest ($sdk , $needRunMockServer = $true )
360
+ function ExecuteSingleTest ($sdk , $needRunMockServer = $true )
333
361
{
334
362
Write-Host " Start mock server"
335
- if ($needRunMockServer -eq $true ) {
363
+ if ($needRunMockServer -eq $true )
364
+ {
336
365
StartMockServer - rpSDKFolder $sdk.DirectoryPath
337
366
}
338
367
Write-Host " Execute mock test for $ ( $sdk.Name ) "
339
368
TestAndGenerateReport $sdk.DirectoryPath
340
369
Write-Host " Stop mock server"
341
- if ($needRunMockServer -eq $true ) {
370
+ if ($needRunMockServer -eq $true )
371
+ {
342
372
StopMockServer
343
373
}
344
374
}
0 commit comments