Skip to content
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 @@ -795,6 +795,10 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
} else {
methodNames.add(op.vendorExtensions.get("x-powershell-method-name"));
}

if (op.produces != null && op.produces.size() > 1) {
op.vendorExtensions.put("x-powershell-select-accept", true);
}
}

processedModelMaps.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}

{{/allParams}}
{{#vendorExtensions.x-powershell-select-accept}}
.PARAMETER ReturnType

Select the return type (optional): {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}

{{/vendorExtensions.x-powershell-select-accept}}
.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response
Expand All @@ -38,6 +44,11 @@ function {{{vendorExtensions.x-powershell-method-name}}} {
${<%paramName%>},
<%={{ }}=%>
{{/allParams}}
{{#vendorExtensions.x-powershell-select-accept}}
[String]
[ValidateSet({{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}})]
$ReturnType,
{{/vendorExtensions.x-powershell-select-accept}}
[Switch]
$WithHttpInfo
)
Expand All @@ -61,6 +72,13 @@ function {{{vendorExtensions.x-powershell-method-name}}} {
$LocalVarAccepts = @({{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}})

{{/hasProduces}}
{{#vendorExtensions.x-powershell-select-accept}}
if ($ReturnType) {
# use the return type (MIME) provided by the user
$LocalVarAccepts = @($ReturnType)
}

{{/vendorExtensions.x-powershell-select-accept}}
{{#hasConsumes}}
# HTTP header 'Content-Type'
$LocalVarContentTypes = @({{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
}

return @{
Response = DeserializeResponse -Response $Response -ReturnType $ReturnType
Response = DeserializeResponse -Response $Response -ReturnType $ReturnType -ContentTypes $Response.Headers["Content-Type"]
StatusCode = $Response.StatusCode
Headers = $Response.Headers
}
Expand Down Expand Up @@ -174,7 +174,10 @@ function DeserializeResponse {
[string]$ReturnType,
[Parameter(Mandatory)]
[AllowEmptyString()]
[string]$Response
[string]$Response,
[Parameter(Mandatory)]
[AllowEmptyCollection()]
[string[]]$ContentTypes
)

If ([string]::IsNullOrEmpty($ReturnType)) { # void response
Expand All @@ -183,7 +186,22 @@ function DeserializeResponse {
return ConvertFrom-Json $Response
} Elseif (@("String", "Boolean", "System.DateTime") -contains $ReturnType) { # string, boolean ,datetime
return $Response
} Else { # model
return ConvertFrom-Json $Response
} Else { # others (e.g. model, file)
if ($ContentTypes) {
$ContentType = $null
if ($ContentTypes.Count -gt 1) {
$ContentType = SelectContentTypeHeaders -ContentTypes $ContentTypes
} else {
$ContentType = $ContentTypes[0]
}

if (IsJsonMIME -MIME $ContentType) { # JSON
return ConvertFrom-Json $Response
} else { # XML, file, etc
return $Response
}
} else { # no content type in response header, returning raw response
return $Response
}
}
}
20 changes: 12 additions & 8 deletions samples/client/petstore/powershell-experimental/Test1.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $body = (Initialize-PSUser -Id 123 -Username "Username_example" -FirstName "Fi
$Id = 38369

#$result = Update-PSPetWithForm
try {
#try {
$pet = Initialize-PSPet -Id $Id -Name 'foo' -Category (
Initialize-PSCategory -Id $Id -Name 'bar'
) -PhotoUrls @(
Expand All @@ -29,14 +29,18 @@ try {
#Write-Host $pet
$Result = Add-PSPet -Pet $pet
Set-PSConfigurationApiKey -Id "api_key" -ApiKey "zzZZZZZZZZZZZZZ"
$Result2 = Get-PSPetById -petId ($Id + 10) -Verbose -WithHttpInfo #-testHeader "testing only" -testQuery "testing something here"
Write-Host $Result2.GetType()
} catch {
#Write-Host ("Exception occured when calling '': {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
#Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
}
$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"]
#} catch {
# Write-Host ("Exception occured when calling '': {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
# Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
#}

Write-Host "Before exit $($Result2.GetType())"
#$Result = Add-PSPet -Pet $pet -ReturnType "application/xml"
#Write-Host "Before exit $($Result2.GetType())"

#$result | Write-Host

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ No description available.
.PARAMETER Pet
Pet object that needs to be added to the store

.PARAMETER ReturnType

Select the return type (optional): application/xml, application/json

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response
Expand All @@ -31,6 +35,9 @@ function Add-PSPet {
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[PSCustomObject]
${Pet},
[String]
[ValidateSet("application/xml", "application/json")]
$ReturnType,
[Switch]
$WithHttpInfo
)
Expand All @@ -52,6 +59,11 @@ function Add-PSPet {
# HTTP header 'Accept' (if needed)
$LocalVarAccepts = @('application/xml', 'application/json')

if ($ReturnType) {
# use the return type (MIME) provided by the user
$LocalVarAccepts = @($ReturnType)
}

# HTTP header 'Content-Type'
$LocalVarContentTypes = @('application/json', 'application/xml')

Expand Down Expand Up @@ -175,6 +187,10 @@ No description available.
.PARAMETER Status
Status values that need to be considered for filter

.PARAMETER ReturnType

Select the return type (optional): application/xml, application/json

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response
Expand All @@ -190,6 +206,9 @@ function Find-PSPetsByStatus {
[ValidateSet("available", "pending", "sold")]
[String[]]
${Status},
[String]
[ValidateSet("application/xml", "application/json")]
$ReturnType,
[Switch]
$WithHttpInfo
)
Expand All @@ -211,6 +230,11 @@ function Find-PSPetsByStatus {
# HTTP header 'Accept' (if needed)
$LocalVarAccepts = @('application/xml', 'application/json')

if ($ReturnType) {
# use the return type (MIME) provided by the user
$LocalVarAccepts = @($ReturnType)
}

$LocalVarUri = '/pet/findByStatus'

if (!$Status) {
Expand Down Expand Up @@ -250,6 +274,10 @@ No description available.
.PARAMETER Tags
Tags to filter by

.PARAMETER ReturnType

Select the return type (optional): application/xml, application/json

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response
Expand All @@ -264,6 +292,9 @@ function Find-PSPetsByTags {
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[String[]]
${Tags},
[String]
[ValidateSet("application/xml", "application/json")]
$ReturnType,
[Switch]
$WithHttpInfo
)
Expand All @@ -285,6 +316,11 @@ function Find-PSPetsByTags {
# HTTP header 'Accept' (if needed)
$LocalVarAccepts = @('application/xml', 'application/json')

if ($ReturnType) {
# use the return type (MIME) provided by the user
$LocalVarAccepts = @($ReturnType)
}

$LocalVarUri = '/pet/findByTags'

if (!$Tags) {
Expand Down Expand Up @@ -324,6 +360,10 @@ No description available.
.PARAMETER PetId
ID of pet to return

.PARAMETER ReturnType

Select the return type (optional): application/xml, application/json

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response
Expand All @@ -338,6 +378,9 @@ function Get-PSPetById {
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[Int64]
${PetId},
[String]
[ValidateSet("application/xml", "application/json")]
$ReturnType,
[Switch]
$WithHttpInfo
)
Expand All @@ -359,6 +402,11 @@ function Get-PSPetById {
# HTTP header 'Accept' (if needed)
$LocalVarAccepts = @('application/xml', 'application/json')

if ($ReturnType) {
# use the return type (MIME) provided by the user
$LocalVarAccepts = @($ReturnType)
}

$LocalVarUri = '/pet/{petId}'
if (!$PetId) {
throw "Error! The required parameter `PetId` missing when calling getPetById."
Expand Down Expand Up @@ -401,6 +449,10 @@ No description available.
.PARAMETER Pet
Pet object that needs to be added to the store

.PARAMETER ReturnType

Select the return type (optional): application/xml, application/json

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response
Expand All @@ -415,6 +467,9 @@ function Update-PSPet {
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[PSCustomObject]
${Pet},
[String]
[ValidateSet("application/xml", "application/json")]
$ReturnType,
[Switch]
$WithHttpInfo
)
Expand All @@ -436,6 +491,11 @@ function Update-PSPet {
# HTTP header 'Accept' (if needed)
$LocalVarAccepts = @('application/xml', 'application/json')

if ($ReturnType) {
# use the return type (MIME) provided by the user
$LocalVarAccepts = @($ReturnType)
}

# HTTP header 'Content-Type'
$LocalVarContentTypes = @('application/json', 'application/xml')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ No description available.
.PARAMETER OrderId
ID of pet that needs to be fetched

.PARAMETER ReturnType

Select the return type (optional): application/xml, application/json

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response
Expand All @@ -167,6 +171,9 @@ function Get-PSOrderById {
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[Int64]
${OrderId},
[String]
[ValidateSet("application/xml", "application/json")]
$ReturnType,
[Switch]
$WithHttpInfo
)
Expand All @@ -188,6 +195,11 @@ function Get-PSOrderById {
# HTTP header 'Accept' (if needed)
$LocalVarAccepts = @('application/xml', 'application/json')

if ($ReturnType) {
# use the return type (MIME) provided by the user
$LocalVarAccepts = @($ReturnType)
}

$LocalVarUri = '/store/order/{orderId}'
if (!$OrderId) {
throw "Error! The required parameter `OrderId` missing when calling getOrderById."
Expand Down Expand Up @@ -225,6 +237,10 @@ No description available.
.PARAMETER Order
order placed for purchasing the pet

.PARAMETER ReturnType

Select the return type (optional): application/xml, application/json

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response
Expand All @@ -239,6 +255,9 @@ function Invoke-PSPlaceOrder {
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[PSCustomObject]
${Order},
[String]
[ValidateSet("application/xml", "application/json")]
$ReturnType,
[Switch]
$WithHttpInfo
)
Expand All @@ -260,6 +279,11 @@ function Invoke-PSPlaceOrder {
# HTTP header 'Accept' (if needed)
$LocalVarAccepts = @('application/xml', 'application/json')

if ($ReturnType) {
# use the return type (MIME) provided by the user
$LocalVarAccepts = @($ReturnType)
}

# HTTP header 'Content-Type'
$LocalVarContentTypes = @('application/json')

Expand Down
Loading