diff --git a/src/Pode.psd1 b/src/Pode.psd1 index 566a31bd3..721a488ce 100644 --- a/src/Pode.psd1 +++ b/src/Pode.psd1 @@ -220,6 +220,7 @@ 'New-PodeOAStringProperty', 'New-PodeOABoolProperty', 'New-PodeOAObjectProperty', + 'New-PodeOASchemaProperty', 'ConvertTo-PodeOAParameter', 'Set-PodeOARouteInfo', 'Enable-PodeOpenApiViewer', diff --git a/src/Private/OpenApi.ps1 b/src/Private/OpenApi.ps1 index 92acfed7d..be4bc0f9a 100644 --- a/src/Private/OpenApi.ps1 +++ b/src/Private/OpenApi.ps1 @@ -130,6 +130,13 @@ function ConvertTo-PodeOASchemaProperty format = $Property.format } + # schema refs + if($Property.type -ieq 'schema') { + $schema = @{ + '$ref' = "#components/schemas/$($Property['schema'])" + } + } + # are we using an array? if ($Property.array) { $Property.array = $false diff --git a/src/Public/OpenApi.ps1 b/src/Public/OpenApi.ps1 index 59e58d07c..4f74667f0 100644 --- a/src/Public/OpenApi.ps1 +++ b/src/Public/OpenApi.ps1 @@ -1219,6 +1219,63 @@ function New-PodeOAObjectProperty return $param } +<# +.SYNOPSIS +Creates a OpenAPI schema reference property. + +.DESCRIPTION +Creates a new OpenAPI schema reference from another OpenAPI schema. + +.PARAMETER Name +The Name of the property. + +.PARAMETER Reference +An component schema name. + +.PARAMETER Description +A Description of the property. + +.PARAMETER Array +If supplied, the schema reference will be treated as an array. + +.EXAMPLE +New-PodeOASchemaProperty -Name 'Config' -ComponentSchema "MyConfigSchema" +#> +function New-PodeOASchemaProperty +{ + [CmdletBinding()] + param( + [Parameter()] + [string] + $Name, + + [Parameter(Mandatory=$true)] + [string] + $Reference, + + [Parameter()] + [string] + $Description, + + [switch] + $Array + ) + + if(!(Test-PodeOAComponentSchema -Name $Reference)) { + throw "The OpenApi component schema doesn't exist: $($Reference)" + } + + $param = @{ + name = $Name + type = 'schema' + schema = $Reference + array = $Array.IsPresent + description = $Description + } + + return $param +} + <# .SYNOPSIS Converts an OpenAPI property into a Request Parameter.