| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Adds or updates the OpenAPI Info section in the specified OpenAPI documents. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function adds or updates the OpenAPI Info section using the provided parameters in the specified OpenAPI docume |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance to which the OpenAPI Info will be added. |
| | | 8 | | If not specified, the function will attempt to resolve the current server context. |
| | | 9 | | .PARAMETER DocId |
| | | 10 | | An array of OpenAPI document IDs to which the Info will be added. Default is 'default'. |
| | | 11 | | .PARAMETER Title |
| | | 12 | | The title of the API. |
| | | 13 | | .PARAMETER Version |
| | | 14 | | The version of the API. |
| | | 15 | | .PARAMETER Summary |
| | | 16 | | A short summary of the API. |
| | | 17 | | .PARAMETER Description |
| | | 18 | | A detailed description of the API. |
| | | 19 | | .PARAMETER TermsOfService |
| | | 20 | | A URI to the Terms of Service for the API. |
| | | 21 | | .EXAMPLE |
| | | 22 | | # Add or update the OpenAPI Info section in the default document |
| | | 23 | | Add-KrOpenApiInfo -Title 'My API' -Version '1.0.0' -Description 'This is my API.' ` |
| | | 24 | | -Summary 'A brief summary of my API.' -TermsOfService 'https://example.com/terms' |
| | | 25 | | .NOTES |
| | | 26 | | This cmdlet is part of the OpenAPI module. |
| | | 27 | | #> |
| | | 28 | | function Add-KrOpenApiInfo { |
| | | 29 | | [KestrunRuntimeApi('Everywhere')] |
| | | 30 | | param( |
| | | 31 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 32 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 33 | | [Parameter()] |
| | | 34 | | [string[]]$DocId = [Kestrun.Authentication.IOpenApiAuthenticationOptions]::DefaultDocumentationIds, |
| | | 35 | | [Parameter(Mandatory)] |
| | | 36 | | [string]$Title, |
| | | 37 | | [Parameter(Mandatory)] |
| | | 38 | | [string]$Version, |
| | | 39 | | [Parameter()] |
| | | 40 | | [string]$Summary, |
| | | 41 | | [Parameter()] |
| | | 42 | | [string]$Description, |
| | | 43 | | [Parameter()] |
| | | 44 | | [uri]$TermsOfService |
| | | 45 | | ) |
| | | 46 | | begin { |
| | | 47 | | # Ensure the server instance is resolved |
| | 0 | 48 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 49 | | } |
| | | 50 | | process { |
| | | 51 | | # Add the server to the specified OpenAPI documents |
| | 0 | 52 | | foreach ($doc in $DocId) { |
| | 0 | 53 | | $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc) |
| | 0 | 54 | | if ($null -eq $docDescriptor.Document.Info) { |
| | | 55 | | # Initialize the Info object if null |
| | 0 | 56 | | $docDescriptor.Document.Info = [Microsoft.OpenApi.OpenApiInfo]::new() |
| | | 57 | | } |
| | 0 | 58 | | if ($PsBoundParameters.ContainsKey('Title')) { |
| | 0 | 59 | | $docDescriptor.Document.Info.Title = $Title |
| | | 60 | | } |
| | 0 | 61 | | if ($PsBoundParameters.ContainsKey('Version')) { |
| | 0 | 62 | | $docDescriptor.Document.Info.Version = $Version |
| | | 63 | | } |
| | 0 | 64 | | if ($PsBoundParameters.ContainsKey('Summary')) { |
| | 0 | 65 | | $docDescriptor.Document.Info.Summary = $Summary |
| | | 66 | | } |
| | 0 | 67 | | if ($PsBoundParameters.ContainsKey('Description')) { |
| | 0 | 68 | | $docDescriptor.Document.Info.Description = $Description |
| | | 69 | | } |
| | 0 | 70 | | if ($PsBoundParameters.ContainsKey('TermsOfService')) { |
| | 0 | 71 | | $docDescriptor.Document.Info.TermsOfService = $TermsOfService |
| | | 72 | | } |
| | | 73 | | } |
| | | 74 | | } |
| | | 75 | | } |