diff --git a/Extract-function.ps1 b/Extract-function.ps1 new file mode 100644 index 000000000..4ab67ab56 --- /dev/null +++ b/Extract-function.ps1 @@ -0,0 +1,520 @@ +<# +.SYNOPSIS + Extracts functions from PowerShell scripts, supports merging them back, and provides backup/restore functionality. + +.DESCRIPTION + This script processes .ps1 files within the Private and Public subdirectories of the specified + source directory. It extracts functions into separate files (optionally preserving any "using namespace" + directives from the top of the file) and supports merging them back. Merge mode can operate per-extraction folder + (the default) or, if -MergeAll is specified, all extracted files within each target subdirectory are merged into a + single file (Private.ps1 or Public.ps1). Optionally, -StripHeaders removes the header portion from each function + file during merge. + + The script also automatically creates a backup of the Private and Public folders (unless running in restore mode) + and supports restoring from a specified backup (or the latest backup if none is specified). + +.PARAMETER SourceDirectory + The root directory containing the Private and Public subdirectories. Defaults to './src'. + +.PARAMETER Merge + Performs merge operations. In default mode, each extraction folder is merged into a file in its parent folder. + +.PARAMETER MergeAll + When used with -Merge, all extracted function files under each target subdirectory are merged into a single file + (Private.ps1 for the Private folder, and Public.ps1 for the Public folder). + +.PARAMETER StripHeaders + When used with -Merge or -MergeAll, removes header sections (as returned by Get-PrecedingHeader) from each function + file so that only the function body remains. + +.PARAMETER Restore + Restores a backup of the Private and Public subdirectories. Optionally, a backup folder name can be provided via + -BackupName; if omitted, the most recent backup is used. + +.PARAMETER BackupOnly + Creates a backup of the Private and Public subdirectories without performing any extraction or merge operations. + +.EXAMPLE + # Extract functions (with automatic backup) from scripts in ./src + .\YourScript.ps1 -SourceDirectory "./src" + +.EXAMPLE + # Merge extracted function files per extraction folder (default merge behavior) + .\YourScript.ps1 -SourceDirectory "./src" -Merge + +.EXAMPLE + # Merge all extracted function files in Private and Public into Private.ps1 and Public.ps1, + # and remove header sections from each function. + .\YourScript.ps1 -SourceDirectory "./src" -Merge -MergeAll -StripHeaders + +.EXAMPLE + # Restore the latest backup + .\YourScript.ps1 -SourceDirectory "./src" -Restore + +.EXAMPLE + # Restore from a specific backup folder + .\YourScript.ps1 -SourceDirectory "./src" -Restore -BackupName "20230425123045" +#> +[CmdletBinding(DefaultParameterSetName = 'Default')] +param ( + [Parameter(Mandatory = $false)] + [string]$SourceDirectory = './src', + + [Parameter(Mandatory = $true, ParameterSetName = 'Merge')] + [switch]$Merge, + + [Parameter(Mandatory = $false, ParameterSetName = 'Merge')] + [switch]$MergeAll, + + [Parameter(Mandatory = $false, ParameterSetName = 'Merge')] + [switch]$StripHeaders, + + [Parameter(Mandatory = $true, ParameterSetName = 'Restore')] + [switch]$Restore, + + [Parameter(Mandatory = $false, ParameterSetName = 'Restore')] + [string]$BackupName, + + [Parameter(Mandatory = $true, ParameterSetName = 'BackupOnly')] + [switch]$BackupOnly +) + +# Define the backup folder under the source. +$BackupFolder = Join-Path $SourceDirectory 'Backup' + +############################################################################### +# RESTORE MODE +if ($Restore) { + if (-not (Test-Path $BackupFolder)) { + Write-Error "No backup folder found under $SourceDirectory\Backup." + exit 1 + } + # If a backup name is provided, use that; otherwise, choose the most recent backup. + if ($BackupName) { + $backupToRestore = Join-Path $BackupFolder $BackupName + if (-not (Test-Path $backupToRestore)) { + Write-Error "Backup folder '$BackupName' not found under $BackupFolder." + exit 1 + } + } + else { + $backupToRestore = Get-ChildItem -Path $BackupFolder -Directory | Sort-Object CreationTime -Descending | Select-Object -First 1 + if (-not $backupToRestore) { + Write-Error "No backup subfolder found under $BackupFolder." + exit 1 + } + $backupToRestore = $backupToRestore.FullName + } + Write-Output "Restoring backup from '$backupToRestore' to '$SourceDirectory' ..." + + # Remove existing target directories ("Private" and "Public") + @('Private', 'Public') | ForEach-Object { + $target = Join-Path $SourceDirectory $_ + if (Test-Path $target) { + Remove-Item -Path $target -Recurse -Force + Write-Output "Removed existing directory: $target" + } + } + + # Copy backup content back to source (overwrite existing files) + Copy-Item -Path (Join-Path $backupToRestore '*') -Destination $SourceDirectory -Recurse -Force + Write-Output 'Restore complete.' + exit +} + +############################################################################### +# AUTOMATIC BACKUP (unless in Restore mode) +# (Automatically performed unless in restore mode.) +if (-not (Test-Path $BackupFolder)) { + New-Item -Path $BackupFolder -ItemType Directory | Out-Null +} +$timestamp = (Get-Date -Format 'yyyyMMddHHmmss') +$BackupSubFolder = Join-Path $BackupFolder $timestamp +New-Item -Path $BackupSubFolder -ItemType Directory | Out-Null + +# Determine target subdirectories: only 'Private' and 'Public' +$targetSubDirs = @('Private', 'Public') | ForEach-Object { + $fullPath = Join-Path $SourceDirectory $_ + if (Test-Path $fullPath -PathType Container) { $fullPath } +} +foreach ($sub in $targetSubDirs) { + $subName = Split-Path $sub -Leaf + $destBackup = Join-Path $BackupSubFolder $subName + Copy-Item -Path $sub -Destination $destBackup -Recurse -Force +} +Write-Output "Backup created at $BackupSubFolder" +if ($BackupOnly) { + exit +} + +############################################################################### +# HELPER FUNCTIONS + +function Get-PrecedingHeader { + param ( + [string[]]$Lines, + [int]$FunctionStartLine, # 1-indexed line number where the function starts + [int]$IndentSize = 4 # Settable indentation size (default: 4 spaces) + ) + + $headerLines = [System.Collections.Generic.List[string]]::new() + $i = $FunctionStartLine - 2 # Index of the line immediately before the function definition + + $inBlockComment = $false + $indentationLevel = -1 # Default detected indentation level (-1 means not detected) + $foundClosingComment = $false # Flag to detect #> (end of comment) + + while ($i -ge 0) { + $line = $Lines[$i] + $trimmed = $line.Trim() + + if ($trimmed -match '^\.SYNOPSIS') { + # If we find .SYNOPSIS, look at the next line for indentation reference + if ($i + 1 -lt $Lines.Length) { + $nextLine = $Lines[$i + 1] + if ($nextLine -match '^(\s+)') { + $indentationLevel = $matches[1].Length # Capture the number of spaces used + } + } + } + + # If indentation level was never detected, default to IndentSize + if ($indentationLevel -eq -1) { + $indentationLevel = $IndentSize + } + + if ($inBlockComment) { + if (![string]::IsNullOrWhiteSpace($line) -and -not ($line.StartsWith('.') -or $line.StartsWith('<#'))) { + # Ensure all non-dot-prefixed lines use IndentSize + if ($line -match '^\s*') { + $line = (' ' * $IndentSize) + $line.TrimStart() + } + } + $headerLines.Insert(0, $line) + + if ($trimmed -match '^<#') { + break + } + } + else { + if ($trimmed -eq '') { + # Remove empty lines **only if we've already found #>** + if ($foundClosingComment) { + $headerLines.Insert(0, $line) + } + } + elseif ($trimmed -match '^<#') { + $headerLines.Insert(0, $line) + break + } + elseif ($trimmed -match '^#>') { + $inBlockComment = $true + $foundClosingComment = $true # Set flag to remove extra empty lines after this + $headerLines.Insert(0, $line) + } + elseif ($trimmed -match '^#') { + if (![string]::IsNullOrWhiteSpace($line) -and -not ($line.StartsWith('.') -or $line.StartsWith('<#'))) { + # Ensure all non-dot-prefixed lines use IndentSize + if ($line -match '^\s*') { + $line = (' ' * $IndentSize) + $line.TrimStart() + } + } + $headerLines.Insert(0, $line) + } + else { + break + } + } + $i-- + } + return $headerLines +} + +function Remove-Comment { + param ( + [string]$Content + ) + # Remove block comments (<# ... #>) across multiple lines. + $content = [regex]::Replace($Content, '(?s)<#.*?#>', '') + # Remove single-line comments (lines starting with #). + $content = [regex]::Replace($content, '(?m)^\s*#.*$', '') + return $content.Trim() +} + + +# MERGE ALL MODE (with improved header stripping and using namespace handling) +if ($Merge -and $MergeAll) { + foreach ($subDir in $targetSubDirs) { + $targetName = Split-Path $subDir -Leaf + # Gather all extracted function files (recursively) in this subdirectory. + $allFunctionFiles = Get-ChildItem -Path $subDir -Recurse -File -Filter '*.ps1' + + # Initialize a hash table for unique using namespace lines and an array for processed contents. + $usingNamespaces = @{} + $processedContents = @() + + foreach ($file in ($allFunctionFiles | Sort-Object FullName)) { + $content = Get-Content -Path $file.FullName -Raw + $lines = $content -split [Environment]::NewLine + + # Remove leading lines that start with 'using namespace' + $index = 0 + while ($index -lt $lines.Count -and $lines[$index].Trim() -match '^using\s+namespace') { + $usingLine = $lines[$index].Trim() + $usingNamespaces[$usingLine] = $true + $index++ + } + # Rebuild the file content without the using namespace lines. + if ($index -lt $lines.Count) { + $newContent = $lines[$index..($lines.Count - 1)] -join [Environment]::NewLine + } + else { + $newContent = '' + } + # If the StripHeaders switch is set, remove the header from the content. + if ($StripHeaders) { + $newContent = Remove-Comment $newContent + } + $processedContents += $newContent + } + + # Build the unique using namespace block (preserving the original order). + $usingBlock = ($usingNamespaces.Keys) -join [Environment]::NewLine + + # Merge all processed contents with a blank line between them. + $mergedBody = $processedContents -join ([Environment]::NewLine + [Environment]::NewLine) + if ($usingBlock.Trim().Length -gt 0) { + $mergedContent = "$usingBlock$([Environment]::NewLine)$([Environment]::NewLine)$mergedBody" + } + else { + $mergedContent = $mergedBody + } + + $mergedFilePath = Join-Path $subDir "$targetName.ps1" + Set-Content -Path $mergedFilePath -Value $mergedContent.TrimEnd() -Encoding UTF8 + Write-Output "Merged all function files in '$subDir' into '$mergedFilePath'" + + # Remove all extraction folders (child directories) under this target subdirectory. + Get-ChildItem -Path $subDir -Directory | ForEach-Object { + Remove-Item -Path $_.FullName -Recurse -Force + Write-Output "Removed extraction folder: $($_.FullName)" + } + } +} + + +############################################################################### +# Determine the target subdirectories ("Private" and "Public") within the source. +$targetSubDirs = @('Private', 'Public') | ForEach-Object { + $fullPath = Join-Path $SourceDirectory $_ + if (Test-Path $fullPath -PathType Container) { $fullPath } +} +if (-not $targetSubDirs) { + Write-Error "No 'Private' or 'Public' subdirectories found under $SourceDirectory" + exit 1 +} + +############################################################################### +# MAIN OPERATION +if ($Merge) { + if ($MergeAll) { + foreach ($subDir in $targetSubDirs) { + $targetName = Split-Path $subDir -Leaf + # Gather all extracted function files (recursively) in this subdirectory. + $allFunctionFiles = Get-ChildItem -Path $subDir -Recurse -File -Filter '*.ps1' + + # Initialize a hash table for unique using namespace lines and an array for processed contents. + $usingNamespaces = @{} + $processedContents = @() + + foreach ($file in ($allFunctionFiles | Sort-Object FullName)) { + $content = Get-Content -Path $file.FullName -Raw + $lines = $content -split [Environment]::NewLine + + # Remove leading lines that start with 'using namespace' + $index = 0 + while ($index -lt $lines.Count -and $lines[$index].Trim() -match '^using\s+namespace') { + $usingLine = $lines[$index].Trim() + $usingNamespaces[$usingLine] = $true + $index++ + } + # Rebuild the file content without the using namespace lines. + if ($index -lt $lines.Count) { + $newContent = $lines[$index..($lines.Count - 1)] -join [Environment]::NewLine + } + else { + $newContent = '' + } + # If the StripHeaders switch is set, remove the header from the content. + if ($StripHeaders) { + $newContent = Remove-Header $newContent + } + $processedContents += $newContent + } + + # Build the unique using namespace block. + $usingBlock = ($usingNamespaces.Keys) -join [Environment]::NewLine + + # Merge all processed contents with a blank line between them. + $mergedBody = $processedContents -join ([Environment]::NewLine + [Environment]::NewLine) + if ($usingBlock.Trim().Length -gt 0) { + $mergedContent = "$usingBlock$([Environment]::NewLine)$([Environment]::NewLine)$mergedBody" + } + else { + $mergedContent = $mergedBody + } + + $mergedFilePath = Join-Path $subDir "$targetName.ps1" + Set-Content -Path $mergedFilePath -Value $mergedContent.TrimEnd() -Encoding UTF8 + Write-Output "Merged all function files in '$subDir' into '$mergedFilePath'" + + # Remove all extraction folders (child directories) under this target subdirectory. + Get-ChildItem -Path $subDir -Directory | ForEach-Object { + Remove-Item -Path $_.FullName -Recurse -Force + Write-Output "Removed extraction folder: $($_.FullName)" + } + } + } + else { + # EXISTING MERGE MODE: Merge extracted function files per extraction folder. + foreach ($subDir in $targetSubDirs) { + Get-ChildItem -Path $subDir -Recurse -Directory | ForEach-Object { + $currentDir = $_.FullName + # Process only directories that contain one or more .ps1 files. + $ps1Files = Get-ChildItem -Path $currentDir -Filter '*.ps1' -File + if ($ps1Files.Count -gt 0) { + # Initialize a hash table for unique using namespace lines. + $usingNamespaces = @{} + + # Array to store the processed content of each function file. + $processedContents = @() + + foreach ($file in ($ps1Files | Sort-Object Name)) { + $content = Get-Content -Path $file.FullName -Raw + $lines = $content -split [Environment]::NewLine + + # Remove leading lines that start with 'using namespace' + $index = 0 + while ($index -lt $lines.Count -and $lines[$index].Trim() -match '^using\s+namespace') { + $usingLine = $lines[$index].Trim() + $usingNamespaces[$usingLine] = $true + $index++ + } + # Rebuild the file content without the using namespace lines. + if ($index -lt $lines.Count) { + $newContent = $lines[$index..($lines.Count - 1)] -join [Environment]::NewLine + } + else { + $newContent = '' + } + $processedContents += $newContent + } + + # Build the unique using namespace block (preserving the original order). + $usingBlock = ($usingNamespaces.Keys) -join [Environment]::NewLine + + # Merge the processed contents with a blank line between them. + $mergedBody = $processedContents -join ([Environment]::NewLine + [Environment]::NewLine) + + # Prepend the using block if any were found. + if ($usingBlock.Trim().Length -gt 0) { + $mergedContent = "$usingBlock$([Environment]::NewLine)$([Environment]::NewLine)$mergedBody" + } + else { + $mergedContent = $mergedBody + } + + $mergedFileName = "$($_.Name).ps1" + $mergedFilePath = Join-Path $_.Parent.FullName $mergedFileName + Write-Output "Merging folder '$currentDir' into '$mergedFilePath'" + + Set-Content -Path $mergedFilePath -Value $mergedContent.TrimEnd() -Encoding UTF8 + + Remove-Item -Path $currentDir -Recurse -Force + Write-Output "Removed extraction folder: $currentDir" + } + } + } + } +} +else { + # EXTRACTION MODE: Process .ps1 files in the Private and Public subdirectories. + foreach ($subDir in $targetSubDirs) { + Get-ChildItem -Path $subDir -File -Filter '*.ps1' | + # Exclude any file that is already in an extraction folder (its parent folder matches its BaseName) + Where-Object { $_.Directory.Name -ne $_.BaseName } | + ForEach-Object { + $FilePath = $_.FullName + $BaseName = $_.BaseName + $FileDirectory = $_.DirectoryName + + # Create a destination folder with the same name as the file. + $DestinationFolder = Join-Path $FileDirectory $BaseName + if (!(Test-Path $DestinationFolder -PathType Container)) { + New-Item -Path $DestinationFolder -ItemType Directory | Out-Null + } + + # Read the file's content. + $Content = Get-Content -Path $FilePath -Raw + $Lines = Get-Content -Path $FilePath + + # Check for multiple "using namespace" lines at the top. + $usingNamespaces = @() + $idx = 0 + while ($idx -lt $Lines.Count -and $Lines[$idx].Trim() -match '^using\s+namespace') { + $lineUsing = $Lines[$idx].Trim() + if ($usingNamespaces -notcontains $lineUsing) { + $usingNamespaces += $lineUsing + } + $idx++ + } + $usingBlock = $null + if ($usingNamespaces.Count -gt 0) { + $usingBlock = $usingNamespaces -join [Environment]::NewLine + } + + # Parse the file for functions using AST. + $null = $Error.Clear() + $Tokens = $null + $Ast = [System.Management.Automation.Language.Parser]::ParseInput($Content, [ref]$Tokens, [ref]$null) + $FunctionAsts = $Ast.FindAll({ param($node) $node -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $true) + + if ($FunctionAsts.Count -eq 0) { + Write-Warning "No functions found in file: $FilePath" + } + else { + foreach ($funcAst in $FunctionAsts) { + $startLine = $funcAst.Extent.StartLineNumber + $headerLines = Get-PrecedingHeader -Lines $Lines -FunctionStartLine $startLine + $headerText = $headerLines -join [Environment]::NewLine + $functionText = $funcAst.Extent.Text.Trim() + + if ($headerText.Trim().Length -gt 0) { + $fullText = "$headerText$([Environment]::NewLine)$functionText" + } + else { + $fullText = $functionText + } + + # Prepend the using namespace block if present. + if ($usingBlock) { + $fullText = "$usingBlock$([Environment]::NewLine)$fullText" + } + + $functionName = $funcAst.Name + if ([string]::IsNullOrWhiteSpace($functionName)) { + $functionName = 'UnknownFunction' + } + # Create the function file. + $functionFile = Join-Path $DestinationFolder "$functionName.ps1" + Set-Content -Path $functionFile -Value $fullText -Encoding UTF8 + Write-Output "Extracted: $functionName -> $functionFile" + } + } + + # Remove the original file after extraction. + Remove-Item -Path $FilePath -Force + Write-Output "Removed original file: $FilePath" + } + } +} \ No newline at end of file diff --git a/examples/OpenApi-TuttiFrutti.ps1 b/examples/OpenApi-TuttiFrutti.ps1 index e80ff8023..d5c739e60 100644 --- a/examples/OpenApi-TuttiFrutti.ps1 +++ b/examples/OpenApi-TuttiFrutti.ps1 @@ -162,7 +162,7 @@ Some useful links: New-PodeOAStringProperty -Name 'shipDate' -Format Date-Time | New-PodeOAStringProperty -Name 'status' -Description 'Order Status' -Example 'approved' -Enum @('placed', 'approved', 'delivered') | New-PodeOABoolProperty -Name 'complete' | - New-PodeOASchemaProperty -Name 'Address' -Reference 'Address' | + New-PodeOAComponentSchemaProperty -Name 'Address' -Reference 'Address' | New-PodeOAObjectProperty -Name 'Order' -XmlName 'order' -AdditionalProperties (New-PodeOAStringProperty ) | Add-PodeOAComponentSchema -Name 'Order' @@ -196,10 +196,10 @@ Some useful links: New-PodeOAObjectProperty -Name 'Pet' -XmlName 'pet' -Properties ( New-PodeOAIntProperty -Name 'id'-Format Int64 -Example @(10, 2, 4) -ReadOnly | New-PodeOAStringProperty -Name 'name' -Example 'doggie' -Required | - New-PodeOASchemaProperty -Name 'category' -Reference 'Category' | + New-PodeOAComponentSchemaProperty -Name 'category' -Reference 'Category' | New-PodeOAStringProperty -Name 'petType' -Example 'dog' -Required | New-PodeOAStringProperty -Name 'photoUrls' -Array | - New-PodeOASchemaProperty -Name 'tags' -Reference 'Tag' | + New-PodeOAComponentSchemaProperty -Name 'tags' -Reference 'Tag' | New-PodeOAStringProperty -Name 'status' -Description 'pet status in the store' -Enum @('available', 'pending', 'sold') )) @@ -226,7 +226,7 @@ Some useful links: New-PodeOAStringProperty -Name 'name' | New-PodeOAStringProperty -Name 'type' | - New-PodeOASchemaProperty -Name 'children' -Array -Reference 'StructPart' | + New-PodeOAComponentSchemaProperty -Name 'children' -Array -Reference 'StructPart' | New-PodeOAObjectProperty | Add-PodeOAComponentSchema -Name 'StructPart' @@ -252,10 +252,10 @@ Some useful links: New-PodeOAObjectProperty -Name 'Pet' -XmlName 'pet' } -Properties @( (New-PodeOAIntProperty -Name 'id'-Format Int64 -Example 10 -ReadOnly), (New-PodeOAStringProperty -Name 'name' -Example 'doggie' -Required), - (New-PodeOASchemaProperty -Name 'category' -Component 'Category'), + (New-PodeOAComponentSchemaProperty -Name 'category' -Component 'Category'), (New-PodeOAStringProperty -Name 'petType' -Example 'dog' -Required), (New-PodeOAStringProperty -Name 'photoUrls' -Array), - (New-PodeOASchemaProperty -Name 'tags' -Component 'Tag') + (New-PodeOAComponentSchemaProperty -Name 'tags' -Component 'Tag') (New-PodeOAStringProperty -Name 'status' -Description 'pet status in the store' -Enum @('available', 'pending', 'sold')) )) #> @@ -309,7 +309,7 @@ Some useful links: Set-PodeOARouteInfo -Summary 'Find pets by ID' -Description 'Returns pets based on ID' -OperationId 'getPetsById' -PassThru | Set-PodeOARequest -PassThru -Parameters @( ( New-PodeOAStringProperty -Name 'id' -Description 'ID of pet to use' -array | ConvertTo-PodeOAParameter -In Path -Style Simple -Required )) | - Add-PodeOAResponse -StatusCode 200 -Description 'pet response' -Content (@{ '*/*' = New-PodeOASchemaProperty -Reference 'Pet' -array }) -PassThru | + Add-PodeOAResponse -StatusCode 200 -Description 'pet response' -Content (@{ '*/*' = New-PodeOAComponentSchemaProperty -Reference 'Pet' -array }) -PassThru | Add-PodeOAResponse -Default -Description 'error payload' -Content (@{ 'text/html' = 'ApiResponse' }) -PassThru @@ -746,7 +746,7 @@ Some useful links: New-PodeOAStringProperty -name 'id' -format 'uuid' | New-PodeOAObjectProperty -name 'address' -NoProperties | New-PodeOAStringProperty -name 'children' -array | - New-PodeOASchemaProperty -Name 'addresses' -Reference 'Address' -Array | + New-PodeOAComponentSchemaProperty -Name 'addresses' -Reference 'Address' -Array | New-PodeOAObjectProperty }) | Add-PodeOAResponse -StatusCode 200 -Description 'Successful operation' -PassThru | Add-PodeOAResponse -StatusCode 400 -Description 'Invalid ID supplied' -PassThru | diff --git a/src/Pode.Internal.psm1 b/src/Pode.Internal.psm1 index dcb516be0..21ad4b6d6 100644 --- a/src/Pode.Internal.psm1 +++ b/src/Pode.Internal.psm1 @@ -5,13 +5,17 @@ $root = Split-Path -Parent -Path $MyInvocation.MyCommand.Path $sysfuncs = Get-ChildItem Function: # load private functions -Get-ChildItem "$($root)/Private/*.ps1" | ForEach-Object { . ([System.IO.Path]::GetFullPath($_)) } +Get-ChildItem -Path "$($root)/Private/*.ps1" -Recurse | ForEach-Object { . ([System.IO.Path]::GetFullPath($_)) } # load public functions -Get-ChildItem "$($root)/Public/*.ps1" | ForEach-Object { . ([System.IO.Path]::GetFullPath($_)) } +Get-ChildItem -Path "$($root)/Public/*.ps1" -Recurse | ForEach-Object { . ([System.IO.Path]::GetFullPath($_)) } + # get functions from memory and compare to existing to find new functions added $funcs = Get-ChildItem Function: | Where-Object { $sysfuncs -notcontains $_ } # export the module's public functions -Export-ModuleMember -Function ($funcs.Name) \ No newline at end of file +Export-ModuleMember -Function ($funcs.Name) + +# Ensure backward compatibility by creating aliases for legacy Pode OpenAPI function names. +New-PodeFunctionAlias \ No newline at end of file diff --git a/src/Pode.psm1 b/src/Pode.psm1 index 34a812c3a..dff58ad35 100644 --- a/src/Pode.psm1 +++ b/src/Pode.psm1 @@ -75,14 +75,14 @@ try { $moduleManifestPath = Join-Path -Path $root -ChildPath 'Pode.psd1' # Import the module manifest to access its properties - $moduleManifest = Import-PowerShellDataFile -Path $moduleManifestPath -ErrorAction Stop + $PodeManifest = Import-PowerShellDataFile -Path $moduleManifestPath -ErrorAction Stop $podeDll = [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq 'Pode' } if ($podeDll) { - if ( $moduleManifest.ModuleVersion -ne '$version$') { - $moduleVersion = ([version]::new($moduleManifest.ModuleVersion + '.0')) + if ( $PodeManifest.ModuleVersion -ne '$version$') { + $moduleVersion = ([version]::new($PodeManifest.ModuleVersion + '.0')) if ($podeDll.GetName().Version -ne $moduleVersion) { # An existing incompatible Pode.DLL version {0} is loaded. Version {1} is required. Open a new Powershell/pwsh session and retry. throw ($PodeLocale.incompatiblePodeDllExceptionMessage -f $podeDll.GetName().Version, $moduleVersion) @@ -112,7 +112,7 @@ try { } # load private functions - Get-ChildItem "$($root)/Private/*.ps1" | ForEach-Object { . ([System.IO.Path]::GetFullPath($_)) } + Get-ChildItem "$($root)/Private/*.ps1" -Recurse | ForEach-Object { . ([System.IO.Path]::GetFullPath($_)) } # only import public functions $sysfuncs = Get-ChildItem Function: @@ -121,7 +121,10 @@ try { $sysaliases = Get-ChildItem Alias: # load public functions - Get-ChildItem "$($root)/Public/*.ps1" | ForEach-Object { . ([System.IO.Path]::GetFullPath($_)) } + Get-ChildItem "$($root)/Public/*.ps1" -Recurse | ForEach-Object { . ([System.IO.Path]::GetFullPath($_)) } + + # Ensure backward compatibility by creating aliases for legacy Pode OpenAPI function names. + New-PodeFunctionAlias # get functions from memory and compare to existing to find new functions added $funcs = Get-ChildItem Function: | Where-Object { $sysfuncs -notcontains $_ } @@ -141,6 +144,6 @@ catch { } finally { # Cleanup temporary variables - Remove-Variable -Name 'tmpPodeLocale', 'localesPath', 'moduleManifest', 'root', 'version', 'libsPath', 'netFolder', 'podeDll', 'sysfuncs', 'sysaliases', 'funcs', 'aliases', 'moduleManifestPath', 'moduleVersion' -ErrorAction SilentlyContinue + Remove-Variable -Name 'tmpPodeLocale', 'localesPath', 'root', 'version', 'libsPath', 'netFolder', 'podeDll', 'sysfuncs', 'sysaliases', 'funcs', 'aliases', 'moduleManifestPath', 'moduleVersion' -ErrorAction SilentlyContinue } diff --git a/src/Private/Helpers.ps1 b/src/Private/Helpers.ps1 index 804e5e7d2..47b3646b7 100644 --- a/src/Private/Helpers.ps1 +++ b/src/Private/Helpers.ps1 @@ -3278,30 +3278,6 @@ function Test-PodePlaceholder { } -<# -.SYNOPSIS -Retrieves the PowerShell module manifest object for the specified module. - -.DESCRIPTION -This function constructs the path to a PowerShell module manifest file (.psd1) located in the parent directory of the script root. It then imports the module manifest file to access its properties and returns the manifest object. This can be useful for scripts that need to dynamically discover and utilize module metadata, such as version, dependencies, and exported functions. - -.PARAMETERS -This function does not accept any parameters. - -.EXAMPLE -$manifest = Get-PodeModuleManifest -This example calls the `Get-PodeModuleManifest` function to retrieve the module manifest object and stores it in the variable `$manifest`. - -#> -function Get-PodeModuleManifest { - # Construct the path to the module manifest (.psd1 file) - $moduleManifestPath = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Pode.psd1' - - # Import the module manifest to access its properties - $moduleManifest = Import-PowerShellDataFile -Path $moduleManifestPath - return $moduleManifest -} - <# .SYNOPSIS Tests the running PowerShell version for compatibility with Pode, identifying end-of-life (EOL) and untested versions. @@ -3335,8 +3311,7 @@ function Test-PodeVersionPwshEOL { param( [switch] $ReportUntested ) - $moduleManifest = Get-PodeModuleManifest - if ($moduleManifest.ModuleVersion -eq '$version$') { + if ($PodeManifest.ModuleVersion -eq '$version$') { return @{ eol = $false supported = $true @@ -3344,7 +3319,7 @@ function Test-PodeVersionPwshEOL { } $psVersion = $PSVersionTable.PSVersion - $eolVersions = $moduleManifest.PrivateData.PwshVersions.Untested -split ',' + $eolVersions = $PodeManifest.PrivateData.PwshVersions.Untested -split ',' $isEol = "$($psVersion.Major).$($psVersion.Minor)" -in $eolVersions if ($isEol) { @@ -3352,7 +3327,7 @@ function Test-PodeVersionPwshEOL { Write-PodeHost ($PodeLocale.eolPowerShellWarningMessage -f $PodeVersion, $PSVersion) -ForegroundColor Yellow } - $SupportedVersions = $moduleManifest.PrivateData.PwshVersions.Supported -split ',' + $SupportedVersions = $PodeManifest.PrivateData.PwshVersions.Supported -split ',' $isSupported = "$($psVersion.Major).$($psVersion.Minor)" -in $SupportedVersions if ((! $isSupported) -and (! $isEol) -and $ReportUntested) { @@ -3966,3 +3941,50 @@ function ConvertTo-PodeSleep { function Test-PodeIsISEHost { return ((Test-PodeIsWindows) -and ('Windows PowerShell ISE Host' -eq $Host.Name)) } + + + +<# +.SYNOPSIS + Creates aliases for Pode OpenAPI functions to support legacy naming conventions. + +.DESCRIPTION + This function sets up the following aliases in the current script scope: + - New-PodeOASchemaProperty as an alias for New-PodeOAComponentSchemaProperty. + - Enable-PodeOpenApiViewer as an alias for Enable-PodeOAViewer. + - Enable-PodeOA as an alias for Enable-PodeOpenApi. + - Get-PodeOpenApiDefinition as an alias for Get-PodeOADefinition. + The function helps maintain backward compatibility and simplifies calling Pode OpenAPI functions. + +.PARAMETER None + This function does not accept any parameters. + +.OUTPUTS + None. The function creates aliases and does not output any objects. + +.EXAMPLE + PS C:\> New-PodeFunctionAlias + The function creates the necessary aliases for Pode OpenAPI functions in the current session. + +.NOTES + This function is part of the Pode project and adheres to the coding standards defined in the Pode GitHub Repository. + Internal function subject to change. +#> +function New-PodeFunctionAlias { + # Alias + if (!(Test-Path Alias:New-PodeOASchemaProperty)) { + New-Alias New-PodeOASchemaProperty -Value New-PodeOAComponentSchemaProperty -Scope Script + } + + if (!(Test-Path Alias:Enable-PodeOpenApiViewer)) { + New-Alias Enable-PodeOpenApiViewer -Value Enable-PodeOAViewer -Scope Script + } + + if (!(Test-Path Alias:Enable-PodeOA)) { + New-Alias Enable-PodeOA -Value Enable-PodeOpenApi -Scope Script + } + + if (!(Test-Path Alias:Get-PodeOpenApiDefinition)) { + New-Alias Get-PodeOpenApiDefinition -Value Get-PodeOADefinition -Scope Script + } +} diff --git a/src/Public/OAComponents.ps1 b/src/Public/OAComponents.ps1 index a829f5274..7a49d94f6 100644 --- a/src/Public/OAComponents.ps1 +++ b/src/Public/OAComponents.ps1 @@ -950,16 +950,4 @@ function Remove-PodeOAComponent { $PodeContext.Server.OpenAPI.Definitions[$tag].components[$field ].remove($Name) } } -} - -if (!(Test-Path Alias:Enable-PodeOpenApiViewer)) { - New-Alias Enable-PodeOpenApiViewer -Value Enable-PodeOAViewer -} - -if (!(Test-Path Alias:Enable-PodeOA)) { - New-Alias Enable-PodeOA -Value Enable-PodeOpenApi -} - -if (!(Test-Path Alias:Get-PodeOpenApiDefinition)) { - New-Alias Get-PodeOpenApiDefinition -Value Get-PodeOADefinition -} +} \ No newline at end of file diff --git a/src/Public/OAProperties.ps1 b/src/Public/OAProperties.ps1 index 322bc2f21..ae4adc834 100644 --- a/src/Public/OAProperties.ps1 +++ b/src/Public/OAProperties.ps1 @@ -2072,9 +2072,4 @@ function New-PodeOAComponentSchemaProperty { return $param } } -} - - -if (!(Test-Path Alias:New-PodeOASchemaProperty)) { - New-Alias New-PodeOASchemaProperty -Value New-PodeOAComponentSchemaProperty } \ No newline at end of file diff --git a/src/Public/Utilities.ps1 b/src/Public/Utilities.ps1 index e193bbbc3..f89f54123 100644 --- a/src/Public/Utilities.ps1 +++ b/src/Public/Utilities.ps1 @@ -1367,27 +1367,10 @@ This function does not accept any parameters. .OUTPUTS System.String Returns a string indicating the version of the Pode module or '[dev]' if on a development version. - -.EXAMPLE -PS> $moduleManifest = @{ ModuleVersion = '1.2.3' } -PS> Get-PodeVersion - -Returns 'v1.2.3'. - -.EXAMPLE -PS> $moduleManifest = @{ ModuleVersion = '$version$' } -PS> Get-PodeVersion - -Returns '[dev]'. - -.NOTES -This function assumes that $moduleManifest is a hashtable representing the loaded module manifest, with a key of ModuleVersion. - #> function Get-PodeVersion { - $moduleManifest = Get-PodeModuleManifest - if ($moduleManifest.ModuleVersion -ne '$version$') { - return "v$($moduleManifest.ModuleVersion)" + if ($PodeManifest.ModuleVersion -ne '$version$') { + return "v$($PodeManifest.ModuleVersion)" } else { return '[dev]' diff --git a/tests/unit/OpenApi.Tests.ps1 b/tests/unit/OpenApi.Tests.ps1 index b62b29b89..f72474521 100644 --- a/tests/unit/OpenApi.Tests.ps1 +++ b/tests/unit/OpenApi.Tests.ps1 @@ -1797,7 +1797,7 @@ Describe 'OpenApi' { } - Context 'New-PodeOASchemaProperty' { + Context 'New-PodeOAComponentSchemaProperty' { BeforeEach { Add-PodeOAComponentSchema -Name 'Cat' -Schema ( New-PodeOAObjectProperty -Properties @( @@ -1807,12 +1807,12 @@ Describe 'OpenApi' { } # Check if the function exists - It 'New-PodeOASchemaProperty function exists' { - Get-Command New-PodeOASchemaProperty | Should -Not -Be $null + It 'New-PodeOAComponentSchemaProperty function exists' { + Get-Command New-PodeOAComponentSchemaProperty | Should -Not -Be $null } It 'Standard' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Reference 'Cat' + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Reference 'Cat' $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 0 $result.type | Should -Be 'schema' @@ -1821,15 +1821,15 @@ Describe 'OpenApi' { } It 'ArrayNoSwitchesUniqueItems' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -Array -MinItems 2 -MaxItems 4 -UniqueItems + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -Array -MinItems 2 -MaxItems 4 -UniqueItems $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 1 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result.array | Should -BeTrue $result.uniqueItems | Should -BeTrue $result.minItems | Should -BeTrue @@ -1837,15 +1837,15 @@ Describe 'OpenApi' { } It 'ArrayDeprecatedUniqueItems' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -Deprecated -Array -MinItems 2 -MaxItems 4 -UniqueItems + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -Deprecated -Array -MinItems 2 -MaxItems 4 -UniqueItems $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 1 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result.deprecated | Should -Be $true $result.array | Should -BeTrue $result.uniqueItems | Should -BeTrue @@ -1853,15 +1853,15 @@ Describe 'OpenApi' { $result.maxItems | Should -BeTrue } It 'ArrayNullableUniqueItems' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -Nullable -Array -MinItems 2 -MaxItems 4 -UniqueItems + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -Nullable -Array -MinItems 2 -MaxItems 4 -UniqueItems $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 2 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result['nullable'] | Should -Be $true $result.array | Should -BeTrue $result.uniqueItems | Should -BeTrue @@ -1869,15 +1869,15 @@ Describe 'OpenApi' { $result.maxItems | Should -BeTrue } It 'ArrayWriteOnlyUniqueItems' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -WriteOnly -Array -MinItems 2 -MaxItems 4 -UniqueItems + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -WriteOnly -Array -MinItems 2 -MaxItems 4 -UniqueItems $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 2 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result['writeOnly'] | Should -Be $true $result.array | Should -BeTrue $result.uniqueItems | Should -BeTrue @@ -1885,15 +1885,15 @@ Describe 'OpenApi' { $result.maxItems | Should -BeTrue } It 'ArrayReadOnlyUniqueItems' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -ReadOnly -Array -MinItems 2 -MaxItems 4 -UniqueItems + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -ReadOnly -Array -MinItems 2 -MaxItems 4 -UniqueItems $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 2 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result['readOnly'] | Should -Be $true $result.array | Should -BeTrue $result.uniqueItems | Should -BeTrue @@ -1902,75 +1902,75 @@ Describe 'OpenApi' { } It 'ArrayNoSwitches' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -Array -MinItems 2 -MaxItems 4 + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -Array -MinItems 2 -MaxItems 4 $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 1 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result.array | Should -BeTrue $result.minItems | Should -BeTrue $result.maxItems | Should -BeTrue } It 'ArrayDeprecated' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -Deprecated -Array -MinItems 2 -MaxItems 4 + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -Deprecated -Array -MinItems 2 -MaxItems 4 $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 1 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result.deprecated | Should -Be $true $result.array | Should -BeTrue $result.minItems | Should -BeTrue $result.maxItems | Should -BeTrue } It 'ArrayNullable' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -Nullable -Array -MinItems 2 -MaxItems 4 + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -Nullable -Array -MinItems 2 -MaxItems 4 $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 2 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result['nullable'] | Should -Be $true $result.array | Should -BeTrue $result.minItems | Should -BeTrue $result.maxItems | Should -BeTrue } It 'ArrayWriteOnly' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -WriteOnly -Array -MinItems 2 -MaxItems 4 + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -WriteOnly -Array -MinItems 2 -MaxItems 4 $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 2 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result['writeOnly'] | Should -Be $true $result.array | Should -BeTrue $result.minItems | Should -BeTrue $result.maxItems | Should -BeTrue } It 'ArrayReadOnly' { - $result = New-PodeOASchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOASchemaProperty' -Reference 'Cat' ` - -Example 'Example for New-PodeOASchemaProperty' -ReadOnly -Array -MinItems 2 -MaxItems 4 + $result = New-PodeOAComponentSchemaProperty -Name 'testSchema' -Description 'Test for New-PodeOAComponentSchemaProperty' -Reference 'Cat' ` + -Example 'Example for New-PodeOAComponentSchemaProperty' -ReadOnly -Array -MinItems 2 -MaxItems 4 $result | Should -Not -BeNullOrEmpty #$result.Count | Should -Be 2 $result.type | Should -Be 'schema' $result.name | Should -Be 'testSchema' $result.schema | Should -Be 'Cat' - $result.description | Should -Be 'Test for New-PodeOASchemaProperty' - $result['example'] | Should -Be 'Example for New-PodeOASchemaProperty' + $result.description | Should -Be 'Test for New-PodeOAComponentSchemaProperty' + $result['example'] | Should -Be 'Example for New-PodeOAComponentSchemaProperty' $result['readOnly'] | Should -Be $true $result.array | Should -BeTrue $result.minItems | Should -BeTrue @@ -3352,10 +3352,10 @@ Describe 'OpenApi' { $Pet = New-PodeOAObjectProperty -Name 'Pet' -XmlName 'pet' -Properties ( (New-PodeOAIntProperty -Name 'id'-Format Int64 -Example 10 -ReadOnly ), (New-PodeOAStringProperty -Name 'name' -Example 'doggie' -Required) , - (New-PodeOASchemaProperty -Name 'category' -Reference 'Category' ), + (New-PodeOAComponentSchemaProperty -Name 'category' -Reference 'Category' ), (New-PodeOAStringProperty -Name 'petType' -Example 'dog' -Required) , (New-PodeOAStringProperty -Name 'photoUrls' -Array) , - (New-PodeOASchemaProperty -Name 'tags' -Reference 'Tag') , + (New-PodeOAComponentSchemaProperty -Name 'tags' -Reference 'Tag') , (New-PodeOAStringProperty -Name 'status' -Description 'pet status in the store' -Enum @('available', 'pending', 'sold')) ) $Pet.type | Should -be 'object' @@ -3407,10 +3407,10 @@ Describe 'OpenApi' { It 'By Pipeline' { $Pet = New-PodeOAIntProperty -Name 'id'-Format Int64 -Example 10 -ReadOnly | New-PodeOAStringProperty -Name 'name' -Example 'doggie' -Required | - New-PodeOASchemaProperty -Name 'category' -Reference 'Category' | + New-PodeOAComponentSchemaProperty -Name 'category' -Reference 'Category' | New-PodeOAStringProperty -Name 'petType' -Example 'dog' -Required | New-PodeOAStringProperty -Name 'photoUrls' -Array | - New-PodeOASchemaProperty -Name 'tags' -Reference 'Tag' | + New-PodeOAComponentSchemaProperty -Name 'tags' -Reference 'Tag' | New-PodeOAStringProperty -Name 'status' -Description 'pet status in the store' -Enum @('available', 'pending', 'sold') | New-PodeOAObjectProperty -Name 'Pet' -XmlName 'pet' $Pet.type | Should -be 'object'