Pax8API/Public/New-Pax8RequestBody.ps1

function New-Pax8RequestBody {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [ArgumentCompleter({
            param($commandName, $parameterName, $wordToComplete)
            @($script:Pax8OperationMap.Values |
                Where-Object { $_.RequestBody } |
                ForEach-Object CommandName |
                Sort-Object -Unique |
                Where-Object { $_ -like "$wordToComplete*" })
        })]
        [string]$CommandName,

        [switch]$IncludeOptional,

        [switch]$IncludeReadOnly,

        [switch]$AsHashtable
    )

    if (-not $script:Pax8OperationMap.ContainsKey($CommandName)) {
        throw "Unknown Pax8 command '$CommandName'."
    }

    $operation = $script:Pax8OperationMap[$CommandName]
    if (-not $operation.RequestBody -or -not $operation.RequestBodySchema) {
        throw "Pax8 command '$CommandName' does not have an OpenAPI request body schema."
    }

    New-Pax8SchemaTemplate -Schema $operation.RequestBodySchema -IncludeOptional:$IncludeOptional -IncludeReadOnly:$IncludeReadOnly -AsHashtable:$AsHashtable
}