| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Adds a tag to the OpenAPI document. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function adds a tag to the OpenAPI document using the provided parameters in the specified OpenAPI documents in |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance to which the OpenAPI tag 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 tag will be added. Default is 'default'. |
| | | 11 | | .PARAMETER Name |
| | | 12 | | The name of the tag. |
| | | 13 | | .PARAMETER Summary |
| | | 14 | | A short summary of the tag. |
| | | 15 | | .PARAMETER Description |
| | | 16 | | A description of the tag. |
| | | 17 | | .PARAMETER Parent |
| | | 18 | | The name of the parent tag, if this tag is a sub-tag. |
| | | 19 | | .PARAMETER Kind |
| | | 20 | | A machine-readable string to categorize what sort of tag it is. |
| | | 21 | | .PARAMETER ExternalDocs |
| | | 22 | | An OpenAPI External Documentation object associated with the tag. |
| | | 23 | | .PARAMETER Extensions |
| | | 24 | | A collection of OpenAPI extensions to add to the tag. |
| | | 25 | | .EXAMPLE |
| | | 26 | | # Add a tag to the default document |
| | | 27 | | Add-KrOpenApiTag -Name 'MyTag' -Description 'This is my tag.' ` |
| | | 28 | | -ExternalDocs (New-KrOpenApiExternalDoc -Description 'More info' -Url 'https://example.com/tag-info') |
| | | 29 | | Adds a tag named 'MyTag' with a description and external documentation link to the default OpenAPI document. |
| | | 30 | | .EXAMPLE |
| | | 31 | | # Add a tag to multiple documents |
| | | 32 | | Add-KrOpenApiTag -DocId @('Default', 'v2') -Name 'MultiDocTag' -Summary 'Tag for multiple docs' |
| | | 33 | | Adds a tag named 'MultiDocTag' with a summary to both the 'Default' and 'v2' OpenAPI documents. |
| | | 34 | | .NOTES |
| | | 35 | | This cmdlet is part of the OpenAPI module. |
| | | 36 | | #> |
| | | 37 | | function Add-KrOpenApiTag { |
| | | 38 | | [KestrunRuntimeApi('Definition')] |
| | | 39 | | param( |
| | | 40 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 41 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 42 | | [Parameter()] |
| | | 43 | | [string[]]$DocId = [Kestrun.OpenApi.OpenApiDocDescriptor]::DefaultDocumentationIds, |
| | | 44 | | |
| | | 45 | | [Parameter(Mandatory = $true)] |
| | | 46 | | [string]$Name, |
| | | 47 | | |
| | | 48 | | [Parameter()] |
| | | 49 | | [string]$Summary, |
| | | 50 | | |
| | | 51 | | [Parameter()] |
| | | 52 | | [string]$Description, |
| | | 53 | | |
| | | 54 | | [Parameter()] |
| | | 55 | | [string]$Parent, |
| | | 56 | | |
| | | 57 | | [Parameter()] |
| | | 58 | | [string]$Kind, |
| | | 59 | | |
| | | 60 | | [Parameter()] |
| | | 61 | | [Microsoft.OpenApi.OpenApiExternalDocs]$ExternalDocs, |
| | | 62 | | |
| | | 63 | | [Parameter()] |
| | | 64 | | [System.Collections.IDictionary]$Extensions |
| | | 65 | | ) |
| | | 66 | | begin { |
| | | 67 | | # Ensure the server instance is resolved |
| | 0 | 68 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 69 | | } |
| | | 70 | | process { |
| | | 71 | | # Add the server to the specified OpenAPI documents |
| | 0 | 72 | | foreach ($doc in $DocId) { |
| | 0 | 73 | | $docDescriptor = $Server.GetOrCreateOpenApiDocument($doc) |
| | | 74 | | |
| | 0 | 75 | | $null = $docDescriptor.AddTag($Name, $Description, $Summary, $Parent, $Kind, $ExternalDocs, $Extensions) |
| | | 76 | | } |
| | | 77 | | } |
| | | 78 | | } |