Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PS][Experimental] use write verbose when setting authentication, better API doc #5804

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ public PowerShellExperimentalClientCodegen() {
}
}

// additional common verbs mapping
commonVerbs.put("Delete", "Remove");

powershellVerbs = new HashSet<String>(Arrays.asList(
"Add",
"Clear",
Expand Down Expand Up @@ -1014,7 +1011,7 @@ private String toMethodName(String operationId) {
for (Map.Entry<String, String> entry : commonVerbs.entrySet()) {
if (methodName.startsWith(entry.getKey())) {
methodName = entry.getValue() + "-" + apiNamePrefix + methodName.substring(entry.getKey().length());
LOGGER.info("Naming the method using the common verb (e.g. Create, Delete, Update): {} => {}", operationId, methodName);
LOGGER.info("Naming the method by mapping the common verbs (e.g. Create, Change) to PS verbs: {} => {}", operationId, methodName);
return methodName;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,19 @@ function {{{vendorExtensions.x-powershell-method-name}}} {
{{#isKeyInHeader}}
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{name}}}"]) {
$LocalVarHeaderParameters['{{{name}}}'] = $Configuration["ApiKey"]["{{{name}}}"]
Write-Verbose ("Using API key '{{{name}}}' in the header for authentication in {0}" -f $MyInvocation.MyCommand)
}
{{/isKeyInHeader}}
{{#isKeyInQuery}}
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{name}}}"]) {
$LocalVarQueryParameters['{{{name}}}'] = $Configuration["ApiKey"]["{{{name}}}"]
Write-Verbose ("Using API key `{{{name}}}` in the URL query for authentication in {0}" -f $MyInvocation.MyCommand)
}
{{/isKeyInQuery}}
{{#isKeyInCookie}}
if ($Configuration["Cookie"]) {
$LocalVarCookieParameters['{{{name}}}'] = $Configuration["Cookie"]
Write-Verbose ("Using API key `{{{name}}}` in the cookie for authentication in {0}" -f $MyInvocation.MyCommand)
}
{{/isKeyInCookie}}
{{/isApiKey}}
Expand All @@ -169,11 +172,13 @@ function {{{vendorExtensions.x-powershell-method-name}}} {
$LocalVarBytes = [System.Text.Encoding]::UTF8.GetBytes($Configuration["Username"] + ":" + $Configuration["Password"])
$LocalVarBase64Text =[Convert]::ToBase64String($LocalVarBytes)
$LocalVarHeaderParameters['Authorization'] = "Basic " + $LocalVarBase64Text
Write-Verbose ("Using HTTP basic authentication in {0}" -f $MyInvocation.MyCommand)
}
{{/isBasicBasic}}
{{#isBasicBearer}}
if ($Configuration["AccessToken"]) {
$LocalVarHeaderParameters['Authorization'] = "Bearer " + $Configuration["AccessToken"]
Write-Verbose ("Using Bearer authentication in {0}" -f $MyInvocation.MyCommand)
}
{{/isBasicBearer}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ ${{paramName}} = {{{vendorExtensions.x-powershell-example}}} # {{{dataType}}} |
try {
{{#returnType}}{{returnType}} $Result = {{/returnType}}{{{vendorExtensions.x-powershell-method-name}}}{{#allParams}} -{{paramName}} ${{paramName}}{{/allParams}}
} catch {
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
Write-Host ("Exception occured when calling {{{vendorExtensions.x-powershell-method-name}}}: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
}
```

Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/powershell-experimental/Test1.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ $Id = 38369
#$result = Update-PSPetWithForm
try {
Set-PSConfigurationApiKey -Id "api_key" -ApiKey "zzZZZZZZZZZZZZZ"
$result = Get-PSPetById -petId $Id #-testHeader "testing only" -testQuery "testing something here"
$result = Get-PSPetById -petId $Id -Verbose #-testHeader "testing only" -testQuery "testing something here"
} catch {
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
Write-Host ("Exception occured when calling '': {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
}

$result | Write-Host
#$result | Write-Host

#$result | Select-Object -Property "photoUrls" | ConvertTo-Json | Write-Host
#Write-Host "result =" + $result.photoUrls
Expand Down
32 changes: 16 additions & 16 deletions samples/client/petstore/powershell-experimental/docs/PSPetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ $Pet = (Initialize-Pet-Id 123 -Category (Initialize-Category-Id 123 -Name "Name_
try {
Pet $Result = Add-PSPet -Pet $Pet
} catch {
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
Write-Host ("Exception occured when calling Add-PSPet: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
}
```

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

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

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ $OrderId = "OrderId_example" # String | ID of the order that needs to be deleted
try {
Remove-PSOrder -OrderId $OrderId
} catch {
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
Write-Host ("Exception occured when calling Remove-PSOrder: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
}
```

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

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

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

Expand Down
32 changes: 16 additions & 16 deletions samples/client/petstore/powershell-experimental/docs/PSUserApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ $User = (Initialize-User-Id 123 -Username "Username_example" -FirstName "FirstNa
try {
New-PSUser -User $User
} catch {
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
Write-Host ("Exception occured when calling New-PSUser: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
}
```

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

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

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

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

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

Expand Down Expand Up @@ -324,8 +324,8 @@ $Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
try {
Invoke-PSLogoutUser
} catch {
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
Write-Host ("Exception occured when calling Invoke-PSLogoutUser: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
}
```

Expand Down Expand Up @@ -374,8 +374,8 @@ $User = # User | Updated user object
try {
Update-PSUser -Username $Username -User $User
} catch {
Write-Host ($_.ErrorDetails | ConvertFrom-Json)
Write-Host ($_.Exception.Response.Headers | ConvertTo-Json)
Write-Host ("Exception occured when calling Update-PSUser: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ function Get-PSPetById {

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

$LocalVarResult = Invoke-PSApiClient -Method 'GET' `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function Get-PSInventory {

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

$LocalVarResult = Invoke-PSApiClient -Method 'GET' `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function New-PSUser {

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

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

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

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

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

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

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

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

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

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

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

$LocalVarResult = Invoke-PSApiClient -Method 'PUT' `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: OpenAPI Generator Team
#
# Generated on: 4/1/20
# Generated on: 4/2/20
#

@{
Expand Down