| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Builds the OpenAPI document for the specified Kestrun server. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function builds the OpenAPI document for the specified Kestrun server using the discovered components. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance for which the OpenAPI document will be built. |
| | | 8 | | If not specified, the function will attempt to resolve the current server context. |
| | | 9 | | .PARAMETER DocId |
| | | 10 | | The ID of the OpenAPI document to build. Default is 'default'. |
| | | 11 | | .EXAMPLE |
| | | 12 | | # Build the OpenAPI document for the default document ID |
| | | 13 | | Build-KrOpenApiDocument -Server $myServer -DocId 'default' |
| | | 14 | | .OUTPUTS |
| | | 15 | | Kestrun.OpenApi.OpenApiDocumentDescriptor |
| | | 16 | | #> |
| | | 17 | | function Build-KrOpenApiDocument { |
| | | 18 | | [KestrunRuntimeApi('Everywhere')] |
| | | 19 | | param( |
| | | 20 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 21 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 22 | | [Parameter()] |
| | | 23 | | [string]$DocId = [Kestrun.Authentication.IOpenApiAuthenticationOptions]::DefaultSchemeName |
| | | 24 | | ) |
| | | 25 | | begin { |
| | | 26 | | # Ensure the server instance is resolved |
| | 0 | 27 | | $Server = Resolve-KestrunServer -Server $Server |
| | 0 | 28 | | Write-KrLog -Level Information -Logger $Server.Logger -Message 'Building OpenAPI document...' |
| | | 29 | | } |
| | | 30 | | process { |
| | 0 | 31 | | if ( -not $Server.OpenApiDocumentDescriptor.ContainsKey($DocId)) { |
| | 0 | 32 | | throw "OpenAPI document with ID '$DocId' does not exist on the server." |
| | | 33 | | } |
| | 0 | 34 | | Get-KrAnnotatedFunctionsLoaded |
| | 0 | 35 | | $doc = $Server.OpenApiDocumentDescriptor[$DocId] |
| | 0 | 36 | | $doc.GenerateDoc() |
| | | 37 | | } |
| | | 38 | | } |