Skip to content

Commit

Permalink
updated PetStore files
Browse files Browse the repository at this point in the history
  • Loading branch information
condorcorde committed Feb 6, 2024
1 parent 5e65471 commit 7572cc2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function Invoke-ApiClient {
}

# accept, content-type headers
$Accept = SelectHeaders -Headers $Accepts -Multiple
$Accept = SelectHeaders -Headers $Accepts -Multiple -JsonFirst
if ($Accept) {
$HeaderParameters['Accept'] = $Accept
}
Expand Down Expand Up @@ -122,8 +122,6 @@ function Invoke-ApiClient {
}
}



if ($Body -or $IsBodyNullable) {
$RequestBody = $Body
if ([string]::IsNullOrEmpty($RequestBody) -and $IsBodyNullable -eq $true) {
Expand Down Expand Up @@ -182,22 +180,38 @@ function Invoke-ApiClient {
}
}

# Select multiple types for Accept header
# Select JSON MIME if present, otherwise choose the first one if available for Content-Type header
# Filter MIME types for Accept:/Content-Type: headers
function SelectHeaders {
Param(
[Parameter(Mandatory)]
[AllowEmptyCollection()]
[String[]]$Headers,
[Parameter(Mandatory=$false)]
[switch]$Multiple
[switch]$Multiple,
[Parameter(Mandatory=$false)]
[switch]$JsonFirst
)

# if no MIME type is provided return null
if (!($Headers) -or $Headers.Count -eq 0) {
return $null
}

if ($Multiple) {
# return multiple MIME types (for Accept: header)
if ($JsonFirst) {
# sort input to return JSON MIME types first
$mimeHeaders = @()
$otherHeaders = @()
foreach ($Header in $Headers) {
if (IsJsonMIME -MIME $Header) {
$mimeHeaders += $Header
} else {
$otherHeaders += $Header
}
}
$Headers = $($mimeHeaders; $otherHeaders)
}
return [string]::Join(', ', $Headers) # join multiple types if they are provided
} else {
foreach ($Header in $Headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Invoke-PSApiClient {
}

# accept, content-type headers
$Accept = SelectHeaders -Headers $Accepts -Multiple
$Accept = SelectHeaders -Headers $Accepts -Multiple -JsonFirst
if ($Accept) {
$HeaderParameters['Accept'] = $Accept
}
Expand Down Expand Up @@ -121,8 +121,6 @@ function Invoke-PSApiClient {
}
}



if ($Body -or $IsBodyNullable) {
$RequestBody = $Body
if ([string]::IsNullOrEmpty($RequestBody) -and $IsBodyNullable -eq $true) {
Expand Down Expand Up @@ -198,22 +196,38 @@ function Invoke-PSApiClient {
}
}

# Select multiple types for Accept header
# Select JSON MIME if present, otherwise choose the first one if available for Content-Type header
# Filter MIME types for Accept:/Content-Type: headers
function SelectHeaders {
Param(
[Parameter(Mandatory)]
[AllowEmptyCollection()]
[String[]]$Headers,
[Parameter(Mandatory=$false)]
[switch]$Multiple
[switch]$Multiple,
[Parameter(Mandatory=$false)]
[switch]$JsonFirst
)

# if no MIME type is provided return null
if (!($Headers) -or $Headers.Count -eq 0) {
return $null
}

if ($Multiple) {
# return multiple MIME types (for Accept: header)
if ($JsonFirst) {
# sort input to return JSON MIME types first
$mimeHeaders = @()
$otherHeaders = @()
foreach ($Header in $Headers) {
if (IsJsonMIME -MIME $Header) {
$mimeHeaders += $Header
} else {
$otherHeaders += $Header
}
}
$Headers = $($mimeHeaders; $otherHeaders)
}
return [string]::Join(', ', $Headers) # join multiple types if they are provided
} else {
foreach ($Header in $Headers) {
Expand Down

0 comments on commit 7572cc2

Please sign in to comment.