Skip to content

Commit c21fe3c

Browse files
wing328michaelpro1
authored andcommitted
use write verbose in auth, better api doc (OpenAPITools#5804)
1 parent 9ad1250 commit c21fe3c

File tree

11 files changed

+61
-51
lines changed

11 files changed

+61
-51
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,6 @@ public PowerShellExperimentalClientCodegen() {
253253
}
254254
}
255255

256-
// additional common verbs mapping
257-
commonVerbs.put("Delete", "Remove");
258-
259256
powershellVerbs = new HashSet<String>(Arrays.asList(
260257
"Add",
261258
"Clear",
@@ -1014,7 +1011,7 @@ private String toMethodName(String operationId) {
10141011
for (Map.Entry<String, String> entry : commonVerbs.entrySet()) {
10151012
if (methodName.startsWith(entry.getKey())) {
10161013
methodName = entry.getValue() + "-" + apiNamePrefix + methodName.substring(entry.getKey().length());
1017-
LOGGER.info("Naming the method using the common verb (e.g. Create, Delete, Update): {} => {}", operationId, methodName);
1014+
LOGGER.info("Naming the method by mapping the common verbs (e.g. Create, Change) to PS verbs: {} => {}", operationId, methodName);
10181015
return methodName;
10191016
}
10201017
}

modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,19 @@ function {{{vendorExtensions.x-powershell-method-name}}} {
151151
{{#isKeyInHeader}}
152152
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{name}}}"]) {
153153
$LocalVarHeaderParameters['{{{name}}}'] = $Configuration["ApiKey"]["{{{name}}}"]
154+
Write-Verbose ("Using API key '{{{name}}}' in the header for authentication in {0}" -f $MyInvocation.MyCommand)
154155
}
155156
{{/isKeyInHeader}}
156157
{{#isKeyInQuery}}
157158
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{name}}}"]) {
158159
$LocalVarQueryParameters['{{{name}}}'] = $Configuration["ApiKey"]["{{{name}}}"]
160+
Write-Verbose ("Using API key `{{{name}}}` in the URL query for authentication in {0}" -f $MyInvocation.MyCommand)
159161
}
160162
{{/isKeyInQuery}}
161163
{{#isKeyInCookie}}
162164
if ($Configuration["Cookie"]) {
163165
$LocalVarCookieParameters['{{{name}}}'] = $Configuration["Cookie"]
166+
Write-Verbose ("Using API key `{{{name}}}` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand)
164167
}
165168
{{/isKeyInCookie}}
166169
{{/isApiKey}}
@@ -169,11 +172,13 @@ function {{{vendorExtensions.x-powershell-method-name}}} {
169172
$LocalVarBytes = [System.Text.Encoding]::UTF8.GetBytes($Configuration["Username"] + ":" + $Configuration["Password"])
170173
$LocalVarBase64Text =[Convert]::ToBase64String($LocalVarBytes)
171174
$LocalVarHeaderParameters['Authorization'] = "Basic " + $LocalVarBase64Text
175+
Write-Verbose ("Using HTTP basic authentication in {0}" -f $MyInvocation.MyCommand)
172176
}
173177
{{/isBasicBasic}}
174178
{{#isBasicBearer}}
175179
if ($Configuration["AccessToken"]) {
176180
$LocalVarHeaderParameters['Authorization'] = "Bearer " + $Configuration["AccessToken"]
181+
Write-Verbose ("Using Bearer authentication in {0}" -f $MyInvocation.MyCommand)
177182
}
178183
{{/isBasicBearer}}
179184

modules/openapi-generator/src/main/resources/powershell-experimental/api_doc.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ ${{paramName}} = {{{vendorExtensions.x-powershell-example}}} # {{{dataType}}} |
5656
try {
5757
{{#returnType}}{{returnType}} $Result = {{/returnType}}{{{vendorExtensions.x-powershell-method-name}}}{{#allParams}} -{{paramName}} ${{paramName}}{{/allParams}}
5858
} catch {
59-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
60-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
59+
Write-Host ("Exception occured when calling {{{vendorExtensions.x-powershell-method-name}}}: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
60+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
6161
}
6262
```
6363

samples/client/petstore/powershell-experimental/Test1.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ $Id = 38369
1818
#$result = Update-PSPetWithForm
1919
try {
2020
Set-PSConfigurationApiKey -Id "api_key" -ApiKey "zzZZZZZZZZZZZZZ"
21-
$result = Get-PSPetById -petId $Id #-testHeader "testing only" -testQuery "testing something here"
21+
$result = Get-PSPetById -petId $Id -Verbose #-testHeader "testing only" -testQuery "testing something here"
2222
} catch {
23-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
24-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
23+
Write-Host ("Exception occured when calling '': {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
24+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
2525
}
2626

27-
$result | Write-Host
27+
#$result | Write-Host
2828

2929
#$result | Select-Object -Property "photoUrls" | ConvertTo-Json | Write-Host
3030
#Write-Host "result =" + $result.photoUrls

samples/client/petstore/powershell-experimental/docs/PSPetApi.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ $Pet = (Initialize-Pet-Id 123 -Category (Initialize-Category-Id 123 -Name "Name_
3535
try {
3636
Pet $Result = Add-PSPet -Pet $Pet
3737
} catch {
38-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
39-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
38+
Write-Host ("Exception occured when calling Add-PSPet: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
39+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
4040
}
4141
```
4242

@@ -84,8 +84,8 @@ $ApiKey = "ApiKey_example" # String | (optional) (default to null)
8484
try {
8585
Remove-Pet -PetId $PetId -ApiKey $ApiKey
8686
} catch {
87-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
88-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
87+
Write-Host ("Exception occured when calling Remove-Pet: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
88+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
8989
}
9090
```
9191

@@ -134,8 +134,8 @@ $Status = @("Status_example") # String[] | Status values that need to be conside
134134
try {
135135
Pet[] $Result = Find-PSPetsByStatus -Status $Status
136136
} catch {
137-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
138-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
137+
Write-Host ("Exception occured when calling Find-PSPetsByStatus: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
138+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
139139
}
140140
```
141141

@@ -183,8 +183,8 @@ $Tags = @("Inner_example") # String[] | Tags to filter by (default to null)
183183
try {
184184
Pet[] $Result = Find-PSPetsByTags -Tags $Tags
185185
} catch {
186-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
187-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
186+
Write-Host ("Exception occured when calling Find-PSPetsByTags: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
187+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
188188
}
189189
```
190190

@@ -234,8 +234,8 @@ $PetId = 987 # Int64 | ID of pet to return (default to null)
234234
try {
235235
Pet $Result = Get-PSPetById -PetId $PetId
236236
} catch {
237-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
238-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
237+
Write-Host ("Exception occured when calling Get-PSPetById: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
238+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
239239
}
240240
```
241241

@@ -281,8 +281,8 @@ $Pet = (Initialize-Pet-Id 123 -Category (Initialize-Category-Id 123 -Name "Name_
281281
try {
282282
Pet $Result = Update-PSPet -Pet $Pet
283283
} catch {
284-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
285-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
284+
Write-Host ("Exception occured when calling Update-PSPet: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
285+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
286286
}
287287
```
288288

@@ -332,8 +332,8 @@ $Status = "Status_example" # String | Updated status of the pet (optional) (defa
332332
try {
333333
Update-PSPetWithForm -PetId $PetId -Name $Name -Status $Status
334334
} catch {
335-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
336-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
335+
Write-Host ("Exception occured when calling Update-PSPetWithForm: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
336+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
337337
}
338338
```
339339

@@ -385,8 +385,8 @@ $File = 987 # System.IO.FileInfo | file to upload (optional) (default to null)
385385
try {
386386
ApiResponse $Result = Invoke-PSUploadFile -PetId $PetId -AdditionalMetadata $AdditionalMetadata -File $File
387387
} catch {
388-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
389-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
388+
Write-Host ("Exception occured when calling Invoke-PSUploadFile: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
389+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
390390
}
391391
```
392392

samples/client/petstore/powershell-experimental/docs/PSStoreApi.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ $OrderId = "OrderId_example" # String | ID of the order that needs to be deleted
2929
try {
3030
Remove-PSOrder -OrderId $OrderId
3131
} catch {
32-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
33-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
32+
Write-Host ("Exception occured when calling Remove-PSOrder: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
33+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
3434
}
3535
```
3636

@@ -78,8 +78,8 @@ $Configuration["ApiKey"]["api_key"] = "YOUR_API_KEY"
7878
try {
7979
System.Collections.Hashtable $Result = Get-PSInventory
8080
} catch {
81-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
82-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
81+
Write-Host ("Exception occured when calling Get-PSInventory: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
82+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
8383
}
8484
```
8585

@@ -120,8 +120,8 @@ $OrderId = 987 # Int64 | ID of pet that needs to be fetched (default to null)
120120
try {
121121
Order $Result = Get-PSOrderById -OrderId $OrderId
122122
} catch {
123-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
124-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
123+
Write-Host ("Exception occured when calling Get-PSOrderById: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
124+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
125125
}
126126
```
127127

@@ -163,8 +163,8 @@ $Order = (Initialize-Order-Id 123 -PetId 123 -Quantity 123 -ShipDate Get-Date -S
163163
try {
164164
Order $Result = Invoke-PSPlaceOrder -Order $Order
165165
} catch {
166-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
167-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
166+
Write-Host ("Exception occured when calling Invoke-PSPlaceOrder: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
167+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
168168
}
169169
```
170170

samples/client/petstore/powershell-experimental/docs/PSUserApi.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ $User = (Initialize-User-Id 123 -Username "Username_example" -FirstName "FirstNa
3939
try {
4040
New-PSUser -User $User
4141
} catch {
42-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
43-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
42+
Write-Host ("Exception occured when calling New-PSUser: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
43+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
4444
}
4545
```
4646

@@ -88,8 +88,8 @@ $User = @((Initialize-User-Id 123 -Username "Username_example" -FirstName "First
8888
try {
8989
New-PSUsersWithArrayInput -User $User
9090
} catch {
91-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
92-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
91+
Write-Host ("Exception occured when calling New-PSUsersWithArrayInput: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
92+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
9393
}
9494
```
9595

@@ -137,8 +137,8 @@ $User = @() # User[] | List of user object
137137
try {
138138
New-PSUsersWithListInput -User $User
139139
} catch {
140-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
141-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
140+
Write-Host ("Exception occured when calling New-PSUsersWithListInput: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
141+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
142142
}
143143
```
144144

@@ -188,8 +188,8 @@ $Username = "Username_example" # String | The name that needs to be deleted (def
188188
try {
189189
Remove-PSUser -Username $Username
190190
} catch {
191-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
192-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
191+
Write-Host ("Exception occured when calling Remove-PSUser: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
192+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
193193
}
194194
```
195195

@@ -231,8 +231,8 @@ $Username = "Username_example" # String | The name that needs to be fetched. Use
231231
try {
232232
User $Result = Get-PSUserByName -Username $Username
233233
} catch {
234-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
235-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
234+
Write-Host ("Exception occured when calling Get-PSUserByName: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
235+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
236236
}
237237
```
238238

@@ -276,8 +276,8 @@ $Password = "Password_example" # String | The password for login in clear text (
276276
try {
277277
String $Result = Invoke-PSLoginUser -Username $Username -Password $Password
278278
} catch {
279-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
280-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
279+
Write-Host ("Exception occured when calling Invoke-PSLoginUser: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
280+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
281281
}
282282
```
283283

@@ -324,8 +324,8 @@ $Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
324324
try {
325325
Invoke-PSLogoutUser
326326
} catch {
327-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
328-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
327+
Write-Host ("Exception occured when calling Invoke-PSLogoutUser: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
328+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
329329
}
330330
```
331331

@@ -374,8 +374,8 @@ $User = # User | Updated user object
374374
try {
375375
Update-PSUser -Username $Username -User $User
376376
} catch {
377-
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
378-
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
377+
Write-Host ("Exception occured when calling Update-PSUser: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
378+
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
379379
}
380380
```
381381

samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSPetApi.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ function Get-PSPetById {
320320

321321
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["api_key"]) {
322322
$LocalVarHeaderParameters['api_key'] = $Configuration["ApiKey"]["api_key"]
323+
Write-Verbose ("Using API key 'api_key' in the header for authentication in {0}" -f $MyInvocation.MyCommand)
323324
}
324325

325326
$LocalVarResult = Invoke-PSApiClient -Method 'GET' `

samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSStoreApi.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function Get-PSInventory {
103103

104104
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["api_key"]) {
105105
$LocalVarHeaderParameters['api_key'] = $Configuration["ApiKey"]["api_key"]
106+
Write-Verbose ("Using API key 'api_key' in the header for authentication in {0}" -f $MyInvocation.MyCommand)
106107
}
107108

108109
$LocalVarResult = Invoke-PSApiClient -Method 'GET' `

samples/client/petstore/powershell-experimental/src/PSPetstore/API/PSUserApi.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function New-PSUser {
5656

5757
if ($Configuration["Cookie"]) {
5858
$LocalVarCookieParameters['auth_cookie'] = $Configuration["Cookie"]
59+
Write-Verbose ("Using API key `auth_cookie` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand)
5960
}
6061

6162
$LocalVarResult = Invoke-PSApiClient -Method 'POST' `
@@ -124,6 +125,7 @@ function New-PSUsersWithArrayInput {
124125

125126
if ($Configuration["Cookie"]) {
126127
$LocalVarCookieParameters['auth_cookie'] = $Configuration["Cookie"]
128+
Write-Verbose ("Using API key `auth_cookie` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand)
127129
}
128130

129131
$LocalVarResult = Invoke-PSApiClient -Method 'POST' `
@@ -192,6 +194,7 @@ function New-PSUsersWithListInput {
192194

193195
if ($Configuration["Cookie"]) {
194196
$LocalVarCookieParameters['auth_cookie'] = $Configuration["Cookie"]
197+
Write-Verbose ("Using API key `auth_cookie` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand)
195198
}
196199

197200
$LocalVarResult = Invoke-PSApiClient -Method 'POST' `
@@ -255,6 +258,7 @@ function Remove-PSUser {
255258

256259
if ($Configuration["Cookie"]) {
257260
$LocalVarCookieParameters['auth_cookie'] = $Configuration["Cookie"]
261+
Write-Verbose ("Using API key `auth_cookie` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand)
258262
}
259263

260264
$LocalVarResult = Invoke-PSApiClient -Method 'DELETE' `
@@ -444,6 +448,7 @@ function Invoke-PSLogoutUser {
444448

445449
if ($Configuration["Cookie"]) {
446450
$LocalVarCookieParameters['auth_cookie'] = $Configuration["Cookie"]
451+
Write-Verbose ("Using API key `auth_cookie` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand)
447452
}
448453

449454
$LocalVarResult = Invoke-PSApiClient -Method 'GET' `
@@ -522,6 +527,7 @@ function Update-PSUser {
522527

523528
if ($Configuration["Cookie"]) {
524529
$LocalVarCookieParameters['auth_cookie'] = $Configuration["Cookie"]
530+
Write-Verbose ("Using API key `auth_cookie` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand)
525531
}
526532

527533
$LocalVarResult = Invoke-PSApiClient -Method 'PUT' `

samples/client/petstore/powershell-experimental/src/PSPetstore/PSPetstore.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: OpenAPI Generator Team
55
#
6-
# Generated on: 4/1/20
6+
# Generated on: 4/2/20
77
#
88

99
@{

0 commit comments

Comments
 (0)