| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Sets the schema name used for autogenerated OpenAPI client-error responses. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | Configures the OpenAPI descriptor to use a custom schema component name for |
| | | 6 | | autogenerated client-error responses (for example 400, 406, 415, 422). |
| | | 7 | | .PARAMETER DocId |
| | | 8 | | One or more OpenAPI document IDs to configure. Defaults to the default document IDs. |
| | | 9 | | .PARAMETER Name |
| | | 10 | | Schema component name to use for autogenerated client-error responses. |
| | | 11 | | .PARAMETER ContentType |
| | | 12 | | One or more content types to use for autogenerated client-error responses. |
| | | 13 | | Defaults to application/problem+json. |
| | | 14 | | .PARAMETER WhatIf |
| | | 15 | | Shows what would happen if the cmdlet runs. The cmdlet is not run. |
| | | 16 | | .PARAMETER Confirm |
| | | 17 | | Prompts you for confirmation before running the cmdlet. |
| | | 18 | | .EXAMPLE |
| | | 19 | | Set-KrOpenApiErrorSchema -Name 'ApiError' |
| | | 20 | | |
| | | 21 | | Uses 'ApiError' for autogenerated client-error response schemas in the default OpenAPI document. |
| | | 22 | | .EXAMPLE |
| | | 23 | | Set-KrOpenApiErrorSchema -DocId @('Default','v2') -Name 'ApiError' |
| | | 24 | | |
| | | 25 | | Uses 'ApiError' for both Default and v2 OpenAPI documents. |
| | | 26 | | .EXAMPLE |
| | | 27 | | Set-KrOpenApiErrorSchema -Name 'ApiError' -ContentType @('application/json','application/problem+json') |
| | | 28 | | |
| | | 29 | | Uses 'ApiError' and emits autogenerated client-error responses for both JSON media types. |
| | | 30 | | .NOTES |
| | | 31 | | Set this before building/exporting OpenAPI output for predictable component naming. |
| | | 32 | | #> |
| | | 33 | | function Set-KrOpenApiErrorSchema { |
| | | 34 | | [KestrunRuntimeApi('Definition')] |
| | | 35 | | [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')] |
| | | 36 | | param( |
| | | 37 | | [Parameter()] |
| | | 38 | | [string[]]$DocId = [Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultDocumentationIds, |
| | | 39 | | |
| | | 40 | | [Parameter(Mandatory)] |
| | | 41 | | [ValidateNotNullOrEmpty()] |
| | | 42 | | [string]$Name, |
| | | 43 | | |
| | | 44 | | [Parameter()] |
| | | 45 | | [ValidateNotNullOrEmpty()] |
| | 0 | 46 | | [string[]]$ContentType = @([Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultAutoErrorResponseContentType) |
| | | 47 | | ) |
| | | 48 | | |
| | 0 | 49 | | $Server = Resolve-KestrunServer |
| | | 50 | | |
| | 0 | 51 | | foreach ($doc in $DocId) { |
| | 0 | 52 | | if ($PSCmdlet.ShouldProcess("OpenAPI document '$doc'", "Set auto error schema '$Name' with content types: $($Con |
| | 0 | 53 | | $descriptor = $Server.GetOrCreateOpenApiDocument($doc) |
| | 0 | 54 | | $descriptor.AutoErrorResponseSchemaId = $Name |
| | 0 | 55 | | $descriptor.AutoErrorResponseContentTypes = $ContentType |
| | | 56 | | } |
| | | 57 | | } |
| | | 58 | | } |