Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow referencing component schemas in component schemas #727

Merged
merged 7 commits into from
Apr 8, 2021
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
1 change: 1 addition & 0 deletions src/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
'New-PodeOAStringProperty',
'New-PodeOABoolProperty',
'New-PodeOAObjectProperty',
'New-PodeOASchemaProperty',
'ConvertTo-PodeOAParameter',
'Set-PodeOARouteInfo',
'Enable-PodeOpenApiViewer',
Expand Down
7 changes: 7 additions & 0 deletions src/Private/OpenApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions src/Public/OpenApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down