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] add nullable body support #6930

Merged
merged 1 commit into from
Jul 14, 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 @@ -221,7 +221,8 @@ function {{{vendorExtensions.x-powershell-method-name}}} {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "{{#returnType}}{{{.}}}{{/returnType}}"
-ReturnType "{{#returnType}}{{{.}}}{{/returnType}}" `
-IsBodyNullable {{#bodyParam}}{{#isNullable}}$true{{/isNullable}}{{^isNullable}}$false{{/isNullable}}{{/bodyParam}}{{^bodyParam}}$false{{/bodyParam}}

{{#vendorExtensions.x-ps-return-type-one-of}}
# process oneOf response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
[string]$Method,
[Parameter(Mandatory)]
[AllowEmptyString()]
[string]$ReturnType
[string]$ReturnType,
[Parameter(Mandatory)]
[bool]$IsBodyNullable
)

'Calling method: Invoke-{{{apiNamePrefix}}}ApiClient' | Write-Debug
Expand Down Expand Up @@ -85,8 +87,11 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
$RequestBody = $FormParameters
}

if ($Body) {
if ($Body -or $IsBodyNullable) {
$RequestBody = $Body
if ([string]::IsNullOrEmpty($RequestBody) -and $IsBodyNullable -eq $true) {
$RequestBody = "null"
}
}

{{#hasHttpSignatureMethods}}
Expand Down
9 changes: 5 additions & 4 deletions samples/client/petstore/powershell/Test1.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ $Id = 38369
) -Status Available

#Write-Host $pet
$Result = Add-PSPet -Pet $pet
#$Result = Add-PSPet -Pet $pet
$Result = Add-PSPet -Pet $null
Set-PSConfigurationApiKey -Id "api_key" -ApiKey "zzZZZZZZZZZZZZZ"
$Result2 = Get-PSPetById -petId ($Id) -Verbose -WithHttpInfo #-testHeader "testing only" -testQuery "testing something here"
Write-Host $Result2["Headers"]["Content-Type"]
$Result3 = Get-PSPetById -petId ($Id) -Verbose -WithHttpInfo -ReturnType "application/xml" #-testHeader "testing only" -testQuery "testing something here"
Write-Host $Result3["Headers"]["Content-Type"]
Write-Host $Result3["Response"]
#$Result3 = Get-PSPetById -petId ($Id) -Verbose -WithHttpInfo -ReturnType "application/xml" #-testHeader "testing only" -testQuery "testing something here"
#Write-Host $Result3["Headers"]["Content-Type"]
#Write-Host $Result3["Response"]
#} catch {
# Write-Host ("Exception occured when calling '': {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
# Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
Expand Down
24 changes: 16 additions & 8 deletions samples/client/petstore/powershell/src/PSPetstore/Api/PSPetApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ function Add-PSPet {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "Pet"
-ReturnType "Pet" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -165,7 +166,8 @@ function Remove-Pet {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType ""
-ReturnType "" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -252,7 +254,8 @@ function Find-PSPetsByStatus {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "Pet[]"
-ReturnType "Pet[]" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -338,7 +341,8 @@ function Find-PSPetsByTags {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "Pet[]"
-ReturnType "Pet[]" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -427,7 +431,8 @@ function Get-PSPetById {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "Pet"
-ReturnType "Pet" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -517,7 +522,8 @@ function Update-PSPet {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "Pet"
-ReturnType "Pet" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -610,7 +616,8 @@ function Update-PSPetWithForm {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType ""
-ReturnType "" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -706,7 +713,8 @@ function Invoke-PSUploadFile {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "ApiResponse"
-ReturnType "ApiResponse" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function Remove-PSOrder {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType ""
-ReturnType "" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -131,7 +132,8 @@ function Get-PSInventory {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "System.Collections.Hashtable"
-ReturnType "System.Collections.Hashtable" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -215,7 +217,8 @@ function Get-PSOrderById {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "Order"
-ReturnType "Order" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -304,7 +307,8 @@ function Invoke-PSPlaceOrder {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "Order"
-ReturnType "Order" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function New-PSUser {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType ""
-ReturnType "" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -153,7 +154,8 @@ function New-PSUsersWithArrayInput {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType ""
-ReturnType "" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -232,7 +234,8 @@ function New-PSUsersWithListInput {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType ""
-ReturnType "" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -306,7 +309,8 @@ function Remove-PSUser {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType ""
-ReturnType "" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -390,7 +394,8 @@ function Get-PSUserByName {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "User"
-ReturnType "User" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -486,7 +491,8 @@ function Invoke-PSLoginUser {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType "String"
-ReturnType "String" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -550,7 +556,8 @@ function Invoke-PSLogoutUser {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType ""
-ReturnType "" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down Expand Up @@ -639,7 +646,8 @@ function Update-PSUser {
-QueryParameters $LocalVarQueryParameters `
-FormParameters $LocalVarFormParameters `
-CookieParameters $LocalVarCookieParameters `
-ReturnType ""
-ReturnType "" `
-IsBodyNullable $false

if ($WithHttpInfo.IsPresent) {
return $LocalVarResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function Invoke-PSApiClient {
[string]$Method,
[Parameter(Mandatory)]
[AllowEmptyString()]
[string]$ReturnType
[string]$ReturnType,
[Parameter(Mandatory)]
[bool]$IsBodyNullable
)

'Calling method: Invoke-PSApiClient' | Write-Debug
Expand Down Expand Up @@ -91,8 +93,11 @@ function Invoke-PSApiClient {
$RequestBody = $FormParameters
}

if ($Body) {
if ($Body -or $IsBodyNullable) {
$RequestBody = $Body
if ([string]::IsNullOrEmpty($RequestBody) -and $IsBodyNullable -eq $true) {
$RequestBody = "null"
}
}

if ($SkipCertificateCheck -eq $true) {
Expand Down