Skip to content

Commit

Permalink
Merge pull request #1401 from Badgerati/analzyer-warnings
Browse files Browse the repository at this point in the history
Ignore accepted PSAnalyzer warnings
  • Loading branch information
Badgerati authored Sep 28, 2024
2 parents 3ba7228 + f38bb32 commit 2e9d252
Show file tree
Hide file tree
Showing 25 changed files with 168 additions and 122 deletions.
4 changes: 3 additions & 1 deletion PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
'PSUseProcessBlockForPipelineCommand',
'PSAvoidUsingConvertToSecureStringWithPlainText',
'PSReviewUnusedParameter',
'PSAvoidAssignmentToAutomaticVariable'
'PSAvoidAssignmentToAutomaticVariable',
'PSUseBOMForUnicodeEncodedFile',
'PSAvoidTrailingWhitespace'
)

}
4 changes: 2 additions & 2 deletions examples/Web-Sse.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ Start-PodeServer -Threads 3 {
# open local sse connection, and send back data
Add-PodeRoute -Method Get -Path '/data' -ScriptBlock {
ConvertTo-PodeSseConnection -Name 'Data' -Scope Local
Send-PodeSseEvent -Id 1234 -EventType Action -Data 'hello, there!'
Send-PodeSseEvent -Id 1234 -EventType Action -Data 'hello, there!' -FromEvent
Start-Sleep -Seconds 3
Send-PodeSseEvent -Id 1337 -EventType BoldOne -Data 'general kenobi'
Send-PodeSseEvent -Id 1337 -EventType BoldOne -Data 'general kenobi' -FromEvent
}

# home page to get sse events
Expand Down
2 changes: 1 addition & 1 deletion src/Private/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ function Remove-PodeEmptyItemsFromArray {
param(
[Parameter()]
$Array
)
)
if ($null -eq $Array) {
return @()
}
Expand Down
2 changes: 1 addition & 1 deletion src/Private/Timers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function Start-PodeTimerRunspace {
}
}

Add-PodeRunspace -Type Timers -Name "Scheduler" -ScriptBlock $script
Add-PodeRunspace -Type Timers -Name 'Scheduler' -ScriptBlock $script
}

function Invoke-PodeInternalTimer {
Expand Down
1 change: 1 addition & 0 deletions src/Public/Access.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ The Name of the Access method.
if (Test-PodeAccessExists -Name 'Example') { }
#>
function Test-PodeAccessExists {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
Expand Down
1 change: 1 addition & 0 deletions src/Public/Authentication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ The Name of the Authentication method.
if (Test-PodeAuthExists -Name BasicAuth) { ... }
#>
function Test-PodeAuthExists {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
[OutputType([bool])]
param(
Expand Down
1 change: 1 addition & 0 deletions src/Public/Events.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ Use-PodeEvents
Use-PodeEvents -Path './my-events'
#>
function Use-PodeEvents {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
param(
[Parameter()]
Expand Down
4 changes: 3 additions & 1 deletion src/Public/FileWatchers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function Add-PodeFileWatcher {

# test if we have the file watcher already
if (Test-PodeFileWatcher -Name $Name) {
# A File Watcher named has already been defined
# A File Watcher named has already been defined
throw ($PodeLocale.fileWatcherAlreadyDefinedExceptionMessage -f $Name)
}

Expand Down Expand Up @@ -292,6 +292,7 @@ Removes all File Watchers.
Clear-PodeFileWatchers
#>
function Clear-PodeFileWatchers {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
param()

Expand All @@ -315,6 +316,7 @@ Use-PodeFileWatchers
Use-PodeFileWatchers -Path './my-watchers'
#>
function Use-PodeFileWatchers {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
param(
[Parameter()]
Expand Down
2 changes: 2 additions & 0 deletions src/Public/Flash.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Clears all of the flash messages currently stored in the session.
Clear-PodeFlashMessages
#>
function Clear-PodeFlashMessages {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
param()

Expand Down Expand Up @@ -127,6 +128,7 @@ Returns all of the names for each of the messages currently being stored. This d
Get-PodeFlashMessageNames
#>
function Get-PodeFlashMessageNames {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
[OutputType([System.Object[]])]
param()
Expand Down
4 changes: 3 additions & 1 deletion src/Public/Handlers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Add-PodeHandler {

# ensure handler isn't already set
if ($PodeContext.Server.Handlers[$Type].ContainsKey($Name)) {
# [Type] Name: Handler already defined
# [Type] Name: Handler already defined
throw ($PodeLocale.handlerAlreadyDefinedExceptionMessage -f $Type, $Name)
}

Expand Down Expand Up @@ -132,6 +132,7 @@ The Type of Handlers to remove.
Clear-PodeHandlers -Type Smtp
#>
function Clear-PodeHandlers {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
param(
[Parameter()]
Expand Down Expand Up @@ -167,6 +168,7 @@ Use-PodeHandlers
Use-PodeHandlers -Path './my-handlers'
#>
function Use-PodeHandlers {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
param(
[Parameter()]
Expand Down
1 change: 1 addition & 0 deletions src/Public/Logging.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ Clears all Logging methods that have been configured.
Clear-PodeLoggers
#>
function Clear-PodeLoggers {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
[CmdletBinding()]
param()

Expand Down
179 changes: 90 additions & 89 deletions src/Public/OpenApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,15 @@ function Add-PodeOAResponse {
$code = "$($StatusCode)"
}

# add the respones to the routes
foreach ($r in @($Route)) {
foreach ($tag in $DefinitionTag) {
if (! $r.OpenApi.Responses.$tag) {
$r.OpenApi.Responses.$tag = [ordered]@{}
# add the respones to the routes
foreach ($r in @($Route)) {
foreach ($tag in $DefinitionTag) {
if (! $r.OpenApi.Responses.$tag) {
$r.OpenApi.Responses.$tag = [ordered]@{}
}
$r.OpenApi.Responses.$tag[$code] = New-PodeOResponseInternal -DefinitionTag $tag -Params $PSBoundParameters
}
$r.OpenApi.Responses.$tag[$code] = New-PodeOResponseInternal -DefinitionTag $tag -Params $PSBoundParameters
}
}

if ($PassThru) {
return $Route
Expand Down Expand Up @@ -809,16 +809,16 @@ function Set-PodeOARequest {
$r.OpenApi.Parameters = @($Parameters)
}

if ($null -ne $RequestBody) {
# Only 'POST', 'PUT', 'PATCH' can have a request body
if (('POST', 'PUT', 'PATCH') -inotcontains $r.Method ) {
# {0} operations cannot have a Request Body.
throw ($PodeLocale.getRequestBodyNotAllowedExceptionMessage -f $r.Method)
if ($null -ne $RequestBody) {
# Only 'POST', 'PUT', 'PATCH' can have a request body
if (('POST', 'PUT', 'PATCH') -inotcontains $r.Method ) {
# {0} operations cannot have a Request Body.
throw ($PodeLocale.getRequestBodyNotAllowedExceptionMessage -f $r.Method)
}
$r.OpenApi.RequestBody = $RequestBody
}
$r.OpenApi.RequestBody = $RequestBody
}

}
}

if ($PassThru) {
return $Route
Expand Down Expand Up @@ -892,6 +892,7 @@ New-PodeOARequestBody -Content @{'multipart/form-data' =
function New-PodeOARequestBody {
[CmdletBinding(DefaultParameterSetName = 'BuiltIn' )]
[OutputType([hashtable])]
[OutputType([System.Collections.Specialized.OrderedDictionary])]
param(
[Parameter(Mandatory = $true, ParameterSetName = 'Reference')]
[string]
Expand Down Expand Up @@ -1360,27 +1361,27 @@ function ConvertTo-PodeOAParameter {
$prop['allowReserved'] = $AllowReserved.IsPresent
}

if ($Example ) {
$prop.example = $Example
}
elseif ($Examples) {
$prop.examples = $Examples
if ($Example ) {
$prop.example = $Example
}
elseif ($Examples) {
$prop.examples = $Examples
}
}
}
}
elseif ($PSCmdlet.ParameterSetName -ieq 'Reference') {
# return a reference
Test-PodeOAComponentInternal -Field parameters -DefinitionTag $DefinitionTag -Name $Reference -PostValidation
$prop = [ordered]@{
'$ref' = "#/components/parameters/$Reference"
}
foreach ($tag in $DefinitionTag) {
if ($PodeContext.Server.OpenAPI.Definitions[$tag].components.parameters.$Reference.In -eq 'Header' -and $PodeContext.Server.Security.autoHeaders) {
Add-PodeSecurityHeader -Name 'Access-Control-Allow-Headers' -Value $Reference -Append
elseif ($PSCmdlet.ParameterSetName -ieq 'Reference') {
# return a reference
Test-PodeOAComponentInternal -Field parameters -DefinitionTag $DefinitionTag -Name $Reference -PostValidation
$prop = [ordered]@{
'$ref' = "#/components/parameters/$Reference"
}
foreach ($tag in $DefinitionTag) {
if ($PodeContext.Server.OpenAPI.Definitions[$tag].components.parameters.$Reference.In -eq 'Header' -and $PodeContext.Server.Security.autoHeaders) {
Add-PodeSecurityHeader -Name 'Access-Control-Allow-Headers' -Value $Reference -Append
}
}
}
}
else {
else {

if (!$Name ) {
if ($Property.name) {
Expand Down Expand Up @@ -1633,17 +1634,17 @@ function Set-PodeOARouteInfo {

$DefinitionTag = Test-PodeOADefinitionTag -Tag $DefinitionTag

foreach ($r in @($Route)) {
if ((Compare-Object -ReferenceObject $r.OpenApi.DefinitionTag -DifferenceObject $DefinitionTag).Count -ne 0) {
if ($r.OpenApi.IsDefTagConfigured ) {
# Definition Tag for a Route cannot be changed.
throw ($PodeLocale.definitionTagChangeNotAllowedExceptionMessage)
}
else {
$r.OpenApi.DefinitionTag = $DefinitionTag
$r.OpenApi.IsDefTagConfigured = $true
foreach ($r in @($Route)) {
if ((Compare-Object -ReferenceObject $r.OpenApi.DefinitionTag -DifferenceObject $DefinitionTag).Count -ne 0) {
if ($r.OpenApi.IsDefTagConfigured ) {
# Definition Tag for a Route cannot be changed.
throw ($PodeLocale.definitionTagChangeNotAllowedExceptionMessage)
}
else {
$r.OpenApi.DefinitionTag = $DefinitionTag
$r.OpenApi.IsDefTagConfigured = $true
}
}
}

if ($OperationId) {
if ($Route.Count -gt 1) {
Expand Down Expand Up @@ -2712,28 +2713,28 @@ function Add-PodeOACallBack {

$DefinitionTag = Test-PodeOADefinitionTag -Tag $DefinitionTag

foreach ($r in @($Route)) {
foreach ($tag in $DefinitionTag) {
if ($Reference) {
Test-PodeOAComponentInternal -Field callbacks -DefinitionTag $tag -Name $Reference -PostValidation
if (!$Name) {
$Name = $Reference
}
if (! $r.OpenApi.CallBacks.ContainsKey($tag)) {
$r.OpenApi.CallBacks[$tag] = [ordered]@{}
}
$r.OpenApi.CallBacks[$tag].$Name = [ordered]@{
'$ref' = "#/components/callbacks/$Reference"
foreach ($r in @($Route)) {
foreach ($tag in $DefinitionTag) {
if ($Reference) {
Test-PodeOAComponentInternal -Field callbacks -DefinitionTag $tag -Name $Reference -PostValidation
if (!$Name) {
$Name = $Reference
}
if (! $r.OpenApi.CallBacks.ContainsKey($tag)) {
$r.OpenApi.CallBacks[$tag] = [ordered]@{}
}
$r.OpenApi.CallBacks[$tag].$Name = [ordered]@{
'$ref' = "#/components/callbacks/$Reference"
}
}
}
else {
if (! $r.OpenApi.CallBacks.ContainsKey($tag)) {
$r.OpenApi.CallBacks[$tag] = [ordered]@{}
else {
if (! $r.OpenApi.CallBacks.ContainsKey($tag)) {
$r.OpenApi.CallBacks[$tag] = [ordered]@{}
}
$r.OpenApi.CallBacks[$tag].$Name = New-PodeOAComponentCallBackInternal -Params $PSBoundParameters -DefinitionTag $tag
}
$r.OpenApi.CallBacks[$tag].$Name = New-PodeOAComponentCallBackInternal -Params $PSBoundParameters -DefinitionTag $tag
}
}
}

if ($PassThru) {
return $Route
Expand Down Expand Up @@ -3307,36 +3308,36 @@ function Add-PodeOAExternalRoute {
end {
$DefinitionTag = Test-PodeOADefinitionTag -Tag $DefinitionTag

switch ($PSCmdlet.ParameterSetName.ToLowerInvariant()) {
'builtin' {

# ensure the route has appropriate slashes
$Path = Update-PodeRouteSlash -Path $Path
$OpenApiPath = ConvertTo-PodeOpenApiRoutePath -Path $Path
$Path = Resolve-PodePlaceholder -Path $Path
$extRoute = @{
Method = $Method.ToLower()
Path = $Path
Local = $false
OpenApi = @{
Path = $OpenApiPath
Responses = $null
Parameters = $null
RequestBody = $null
callbacks = [ordered]@{}
Authentication = @()
Servers = $Servers
DefinitionTag = $DefinitionTag
}
}
foreach ($tag in $DefinitionTag) {
#add the default OpenApi responses
if ( $PodeContext.Server.OpenAPI.Definitions[$tag].hiddenComponents.defaultResponses) {
$extRoute.OpenApi.Responses = Copy-PodeObjectDeepClone -InputObject $PodeContext.Server.OpenAPI.Definitions[$tag].hiddenComponents.defaultResponses
}
if (! (Test-PodeOAComponentExternalPath -DefinitionTag $tag -Name $Path)) {
$PodeContext.Server.OpenAPI.Definitions[$tag].hiddenComponents.externalPath[$Path] = [ordered]@{}
switch ($PSCmdlet.ParameterSetName.ToLowerInvariant()) {
'builtin' {

# ensure the route has appropriate slashes
$Path = Update-PodeRouteSlash -Path $Path
$OpenApiPath = ConvertTo-PodeOpenApiRoutePath -Path $Path
$Path = Resolve-PodePlaceholder -Path $Path
$extRoute = @{
Method = $Method.ToLower()
Path = $Path
Local = $false
OpenApi = @{
Path = $OpenApiPath
Responses = $null
Parameters = $null
RequestBody = $null
callbacks = [ordered]@{}
Authentication = @()
Servers = $Servers
DefinitionTag = $DefinitionTag
}
}
foreach ($tag in $DefinitionTag) {
#add the default OpenApi responses
if ( $PodeContext.Server.OpenAPI.Definitions[$tag].hiddenComponents.defaultResponses) {
$extRoute.OpenApi.Responses = Copy-PodeObjectDeepClone -InputObject $PodeContext.Server.OpenAPI.Definitions[$tag].hiddenComponents.defaultResponses
}
if (! (Test-PodeOAComponentExternalPath -DefinitionTag $tag -Name $Path)) {
$PodeContext.Server.OpenAPI.Definitions[$tag].hiddenComponents.externalPath[$Path] = [ordered]@{}
}

$PodeContext.Server.OpenAPI.Definitions[$tag].hiddenComponents.externalPath.$Path[$Method] = $extRoute
}
Expand Down
Loading

0 comments on commit 2e9d252

Please sign in to comment.