[PowerShell][Experimental] Better docstring (#5688)

* add docstring to powershell module

* add doc string
This commit is contained in:
William Cheng 2020-03-24 15:04:36 +08:00 committed by GitHub
parent 63c8f5f965
commit eac18a779d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 796 additions and 13 deletions

View File

@ -594,7 +594,7 @@ public class PowerShellExperimentalClientCodegen extends DefaultCodegen implemen
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
HashMap<String, CodegenModel> modelMaps = new HashMap<String, CodegenModel>();
HashMap<String, Boolean> processedModelMaps = new HashMap<String, Boolean>();
HashMap<String, Integer> processedModelMaps = new HashMap<String, Integer>();
for (Object o : allModels) {
HashMap<String, Object> h = (HashMap<String, Object>) o;
@ -672,7 +672,7 @@ public class PowerShellExperimentalClientCodegen extends DefaultCodegen implemen
return name;
}
private String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps, HashMap<String, Boolean> processedModelMap) {
private String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
if (codegenParameter.isListContainer) { // array
return "@(" + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + ")";
} else if (codegenParameter.isMapContainer) { // TODO: map, file type
@ -714,7 +714,7 @@ public class PowerShellExperimentalClientCodegen extends DefaultCodegen implemen
}
}
private String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps, HashMap<String, Boolean> processedModelMap) {
private String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
if (codegenProperty.isListContainer) { // array
return "@(" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + ")";
} else if (codegenProperty.isMapContainer) { // map
@ -756,15 +756,23 @@ public class PowerShellExperimentalClientCodegen extends DefaultCodegen implemen
}
}
private String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps, HashMap<String, Boolean> processedModelMap) {
private String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
String example;
// break infinite recursion. Return, in case a model is already processed in the current context.
String model = codegenModel.name;
if (processedModelMap.containsKey(model)) {
return "";
int count = processedModelMap.get(model);
if (count == 1) {
processedModelMap.put(model, 2);
} else if (count == 2) {
return "";
} else {
throw new RuntimeException("Invalid count when constructing example: " + count);
}
} else {
processedModelMap.put(model, 1);
}
processedModelMap.put(model, true);
example = "(New-" + codegenModel.name;
List<String> propertyExamples = new ArrayList<>();

View File

@ -1,6 +1,24 @@
{{> partial_header}}
{{#operations}}
{{#operation}}
<#
.SYNOPSIS
{{#summary}}{{{.}}}{{/summary}}{{^summary}}No summary available.{{/summary}}
.DESCRIPTION
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
{{#allParams}}
.PARAMETER {{{paramName}}}
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
{{/allParams}}
.OUTPUTS
{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}None{{/returnType}}
#>
function {{{vendorExtensions.x-powershell-method-name}}} {
[CmdletBinding()]
Param (

View File

@ -1,4 +1,17 @@
{{> partial_header}}
<#
.SYNOPSIS
Get the configuration object '{{apiNamePrefix}}Configuration'.
.DESCRIPTION
Get the configuration object '{{apiNamePrefix}}Configuration'.
.OUTPUTS
System.Collections.Hashtable
#>
function Get-{{apiNamePrefix}}Configuration {
$Configuration = $Script:Configuration
@ -36,6 +49,43 @@ function Get-{{apiNamePrefix}}Configuration {
}
<#
.SYNOPSIS
Set the configuration.
.DESCRIPTION
Set the configuration.
.PARAMETER BaseUrl
Base URL of the HTTP endpoints
.PARAMETER Username
Username in HTTP basic authentication
.PARAMETER Passowrd
Password in HTTP basic authentication
.PARAMETER ApiKey
API Keys for authentication/authorization
.PARAMETER ApiKeyPrefix
Prefix in the API Keys
.PARAMETER Cookie
Cookie for authentication/authorization
.PARAMETER AccessToken
Access token for authentication/authorization
.PARAMETER SkipCertificateCheck
Skip certificate verification
.OUTPUTS
System.Collections.Hashtable
#>
function Set-{{{apiNamePrefix}}}Configuration {
[CmdletBinding()]
@ -92,6 +142,25 @@ function Set-{{{apiNamePrefix}}}Configuration {
}
}
<#
.SYNOPSIS
Set the API Key.
.DESCRIPTION
Set the API Key.
.PARAMETER Id
ID of the security schema
.PARAMETER ApiKey
API Key
.OUTPUTS
None
#>
function Set-{{{apiNamePrefix}}}ConfigurationApiKey {
[CmdletBinding()]
Param(
@ -107,6 +176,25 @@ function Set-{{{apiNamePrefix}}}ConfigurationApiKey {
}
}
<#
.SYNOPSIS
Set the API Key prefix.
.DESCRIPTION
Set the API Key prefix.
.PARAMETER Id
ID of the security schema
.PARAMETER ApiKey
API Key prefix
.OUTPUTS
None
#>
function Set-{{{apiNamePrefix}}}ConfigurationApiKeyPrefix {
[CmdletBinding()]
Param(

View File

@ -1,6 +1,25 @@
{{> partial_header}}
{{#models}}
{{#model}}
<#
.SYNOPSIS
{{#summary}}{{{.}}}{{/summary}}{{^summary}}No summary available.{{/summary}}
.DESCRIPTION
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
{{#vars}}
.PARAMETER {{{name}}}
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
{{/vars}}
.OUTPUTS
{{{classname}}}<PSCustomObject>
#>
function New-{{{apiNamePrefix}}}{{{classname}}} {
[CmdletBinding()]
Param (

View File

@ -131,7 +131,7 @@ $Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
$User = @((New-User -Id 123 -Username "Username_example" -FirstName "FirstName_example" -LastName "LastName_example" -Email "Email_example" -Password "Password_example" -Phone "Phone_example" -UserStatus 123)) # User[] | List of user object
$User = @() # User[] | List of user object
# Creates list of users with given input array
try {
@ -368,7 +368,7 @@ $Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
$Username = "Username_example" # String | name that need to be deleted (default to null)
$User = (New-User -Id 123 -Username "Username_example" -FirstName "FirstName_example" -LastName "LastName_example" -Email "Email_example" -Password "Password_example" -Phone "Phone_example" -UserStatus 123) # User | Updated user object
$User = # User | Updated user object
# Updated user
try {

View File

@ -5,6 +5,22 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
Add a new pet to the store
.DESCRIPTION
No description available.
.PARAMETER Pet
Pet object that needs to be added to the store
.OUTPUTS
Pet
#>
function Add-PSPet {
[CmdletBinding()]
Param (
@ -57,6 +73,25 @@ function Add-PSPet {
}
}
<#
.SYNOPSIS
Deletes a pet
.DESCRIPTION
No description available.
.PARAMETER PetId
Pet id to delete
.PARAMETER ApiKey
No description available.
.OUTPUTS
None
#>
function Remove-Pet {
[CmdletBinding()]
Param (
@ -108,6 +143,22 @@ function Remove-Pet {
}
}
<#
.SYNOPSIS
Finds Pets by status
.DESCRIPTION
No description available.
.PARAMETER Status
Status values that need to be considered for filter
.OUTPUTS
Pet[]
#>
function Find-PSPetsByStatus {
[CmdletBinding()]
Param (
@ -156,6 +207,22 @@ function Find-PSPetsByStatus {
}
}
<#
.SYNOPSIS
Finds Pets by tags
.DESCRIPTION
No description available.
.PARAMETER Tags
Tags to filter by
.OUTPUTS
Pet[]
#>
function Find-PSPetsByTags {
[CmdletBinding()]
Param (
@ -204,6 +271,22 @@ function Find-PSPetsByTags {
}
}
<#
.SYNOPSIS
Find pet by ID
.DESCRIPTION
No description available.
.PARAMETER PetId
ID of pet to return
.OUTPUTS
Pet
#>
function Get-PSPetById {
[CmdletBinding()]
Param (
@ -254,6 +337,22 @@ function Get-PSPetById {
}
}
<#
.SYNOPSIS
Update an existing pet
.DESCRIPTION
No description available.
.PARAMETER Pet
Pet object that needs to be added to the store
.OUTPUTS
Pet
#>
function Update-PSPet {
[CmdletBinding()]
Param (
@ -306,6 +405,28 @@ function Update-PSPet {
}
}
<#
.SYNOPSIS
Updates a pet in the store with form data
.DESCRIPTION
No description available.
.PARAMETER PetId
ID of pet that needs to be updated
.PARAMETER Name
Updated name of the pet
.PARAMETER Status
Updated status of the pet
.OUTPUTS
None
#>
function Update-PSPetWithForm {
[CmdletBinding()]
Param (
@ -367,6 +488,28 @@ function Update-PSPetWithForm {
}
}
<#
.SYNOPSIS
uploads an image
.DESCRIPTION
No description available.
.PARAMETER PetId
ID of pet to update
.PARAMETER AdditionalMetadata
Additional data to pass to server
.PARAMETER File
file to upload
.OUTPUTS
ApiResponse
#>
function Invoke-PSUploadFile {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,22 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
Delete purchase order by ID
.DESCRIPTION
No description available.
.PARAMETER OrderId
ID of the order that needs to be deleted
.OUTPUTS
None
#>
function Invoke-PSDeleteOrder {
[CmdletBinding()]
Param (
@ -48,6 +64,19 @@ function Invoke-PSDeleteOrder {
}
}
<#
.SYNOPSIS
Returns pet inventories by status
.DESCRIPTION
No description available.
.OUTPUTS
Hashtable
#>
function Get-PSInventory {
[CmdletBinding()]
Param (
@ -91,6 +120,22 @@ function Get-PSInventory {
}
}
<#
.SYNOPSIS
Find purchase order by ID
.DESCRIPTION
No description available.
.PARAMETER OrderId
ID of pet that needs to be fetched
.OUTPUTS
Order
#>
function Get-PSOrderById {
[CmdletBinding()]
Param (
@ -137,6 +182,22 @@ function Get-PSOrderById {
}
}
<#
.SYNOPSIS
Place an order for a pet
.DESCRIPTION
No description available.
.PARAMETER Order
order placed for purchasing the pet
.OUTPUTS
Order
#>
function Invoke-PSPlaceOrder {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,22 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
Create user
.DESCRIPTION
No description available.
.PARAMETER User
Created user object
.OUTPUTS
None
#>
function Invoke-PSCreateUser {
[CmdletBinding()]
Param (
@ -57,6 +73,22 @@ function Invoke-PSCreateUser {
}
}
<#
.SYNOPSIS
Creates list of users with given input array
.DESCRIPTION
No description available.
.PARAMETER User
List of user object
.OUTPUTS
None
#>
function Invoke-PSCreateUsersWithArrayInput {
[CmdletBinding()]
Param (
@ -109,6 +141,22 @@ function Invoke-PSCreateUsersWithArrayInput {
}
}
<#
.SYNOPSIS
Creates list of users with given input array
.DESCRIPTION
No description available.
.PARAMETER User
List of user object
.OUTPUTS
None
#>
function Invoke-PSCreateUsersWithListInput {
[CmdletBinding()]
Param (
@ -161,6 +209,22 @@ function Invoke-PSCreateUsersWithListInput {
}
}
<#
.SYNOPSIS
Delete user
.DESCRIPTION
No description available.
.PARAMETER Username
The name that needs to be deleted
.OUTPUTS
None
#>
function Invoke-PSDeleteUser {
[CmdletBinding()]
Param (
@ -208,6 +272,22 @@ function Invoke-PSDeleteUser {
}
}
<#
.SYNOPSIS
Get user by user name
.DESCRIPTION
No description available.
.PARAMETER Username
The name that needs to be fetched. Use user1 for testing.
.OUTPUTS
User
#>
function Get-PSUserByName {
[CmdletBinding()]
Param (
@ -254,6 +334,25 @@ function Get-PSUserByName {
}
}
<#
.SYNOPSIS
Logs user into the system
.DESCRIPTION
No description available.
.PARAMETER Username
The user name for login
.PARAMETER Password
The password for login in clear text
.OUTPUTS
String
#>
function Invoke-PSLoginUser {
[CmdletBinding()]
Param (
@ -309,6 +408,19 @@ function Invoke-PSLoginUser {
}
}
<#
.SYNOPSIS
Logs out current logged in user session
.DESCRIPTION
No description available.
.OUTPUTS
None
#>
function Invoke-PSLogoutUser {
[CmdletBinding()]
Param (
@ -349,6 +461,25 @@ function Invoke-PSLogoutUser {
}
}
<#
.SYNOPSIS
Updated user
.DESCRIPTION
No description available.
.PARAMETER Username
name that need to be deleted
.PARAMETER User
Updated user object
.OUTPUTS
None
#>
function Update-PSUser {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,19 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
Get the configuration object 'PSConfiguration'.
.DESCRIPTION
Get the configuration object 'PSConfiguration'.
.OUTPUTS
System.Collections.Hashtable
#>
function Get-PSConfiguration {
$Configuration = $Script:Configuration
@ -34,10 +47,51 @@ function Get-PSConfiguration {
$Configuration["ApiKeyPrefix"] = @{}
}
if (!$Configuration.containsKey("SkipCertificateCheck")) {
$Configuration["SkipCertificateCheck"] = $false
}
Return $Configuration
}
<#
.SYNOPSIS
Set the configuration.
.DESCRIPTION
Set the configuration.
.PARAMETER BaseUrl
Base URL of the HTTP endpoints
.PARAMETER Username
Username in HTTP basic authentication
.PARAMETER Passowrd
Password in HTTP basic authentication
.PARAMETER ApiKey
API Keys for authentication/authorization
.PARAMETER ApiKeyPrefix
Prefix in the API Keys
.PARAMETER Cookie
Cookie for authentication/authorization
.PARAMETER AccessToken
Access token for authentication/authorization
.PARAMETER SkipCertificateCheck
Skip certificate verification
.OUTPUTS
System.Collections.Hashtable
#>
function Set-PSConfiguration {
[CmdletBinding()]
@ -54,6 +108,7 @@ function Set-PSConfiguration {
[AllowEmptyString()]
[string]$AccessToken,
[switch]$PassThru,
[bool]$SkipCertificateCheck,
[switch]$Force
)
@ -86,9 +141,32 @@ function Set-PSConfiguration {
If ($AccessToken) {
$Script:Configuration['AccessToken'] = $AccessToken
}
If ($SkipCertificateCheck) {
$Script:Configuration['SkipCertificateCheck'] = $SkipCertificateCheck
}
}
}
<#
.SYNOPSIS
Set the API Key.
.DESCRIPTION
Set the API Key.
.PARAMETER Id
ID of the security schema
.PARAMETER ApiKey
API Key
.OUTPUTS
None
#>
function Set-PSConfigurationApiKey {
[CmdletBinding()]
Param(
@ -104,6 +182,25 @@ function Set-PSConfigurationApiKey {
}
}
<#
.SYNOPSIS
Set the API Key prefix.
.DESCRIPTION
Set the API Key prefix.
.PARAMETER Id
ID of the security schema
.PARAMETER ApiKey
API Key prefix
.OUTPUTS
None
#>
function Set-PSConfigurationApiKeyPrefix {
[CmdletBinding()]
Param(

View File

@ -5,6 +5,29 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
No summary available.
.DESCRIPTION
Describes the result of uploading an image resource
.PARAMETER Code
No description available.
.PARAMETER Type
No description available.
.PARAMETER Message
No description available.
.OUTPUTS
ApiResponse<PSCustomObject>
#>
function New-PSApiResponse {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,26 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
No summary available.
.DESCRIPTION
A category for a pet
.PARAMETER Id
No description available.
.PARAMETER Name
No description available.
.OUTPUTS
Category<PSCustomObject>
#>
function New-PSCategory {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,26 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
No summary available.
.DESCRIPTION
No description available.
.PARAMETER Name
Updated name of the pet
.PARAMETER Status
Updated status of the pet
.OUTPUTS
InlineObject<PSCustomObject>
#>
function New-PSInlineObject {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,26 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
No summary available.
.DESCRIPTION
No description available.
.PARAMETER AdditionalMetadata
Additional data to pass to server
.PARAMETER File
file to upload
.OUTPUTS
InlineObject1<PSCustomObject>
#>
function New-PSInlineObject1 {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,38 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
No summary available.
.DESCRIPTION
An order for a pets from the pet store
.PARAMETER Id
No description available.
.PARAMETER PetId
No description available.
.PARAMETER Quantity
No description available.
.PARAMETER ShipDate
No description available.
.PARAMETER Status
Order Status
.PARAMETER Complete
No description available.
.OUTPUTS
Order<PSCustomObject>
#>
function New-PSOrder {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,38 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
No summary available.
.DESCRIPTION
A pet for sale in the pet store
.PARAMETER Id
No description available.
.PARAMETER Category
No description available.
.PARAMETER Name
No description available.
.PARAMETER PhotoUrls
No description available.
.PARAMETER Tags
No description available.
.PARAMETER Status
pet status in the store
.OUTPUTS
Pet<PSCustomObject>
#>
function New-PSPet {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,26 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
No summary available.
.DESCRIPTION
A tag for a pet
.PARAMETER Id
No description available.
.PARAMETER Name
No description available.
.OUTPUTS
Tag<PSCustomObject>
#>
function New-PSTag {
[CmdletBinding()]
Param (

View File

@ -5,6 +5,44 @@
# Generated by OpenAPI Generator: https://openapi-generator.tech
#
<#
.SYNOPSIS
No summary available.
.DESCRIPTION
A User who is purchasing from the pet store
.PARAMETER Id
No description available.
.PARAMETER Username
No description available.
.PARAMETER FirstName
No description available.
.PARAMETER LastName
No description available.
.PARAMETER Email
No description available.
.PARAMETER Password
No description available.
.PARAMETER Phone
No description available.
.PARAMETER UserStatus
User Status
.OUTPUTS
User<PSCustomObject>
#>
function New-PSUser {
[CmdletBinding()]
Param (

View File

@ -40,14 +40,17 @@ function Invoke-PSApiClient {
$Configuration = Get-PSConfiguration
$RequestUri = $Configuration["BaseUrl"] + $Uri
$SkipCertificateCheck = $Configuration["SkipCertificateCheck"]
# cookie parameters
foreach ($Parameter in $CookieParameters) {
if ($CookieParameters[$Parameter]) {
$HeaderParameters["Cookie"] = $CookieParameters[$Parameter]
foreach ($Parameter in $CookieParameters.GetEnumerator()) {
if ($Parameter.Name -eq "cookieAuth") {
$HeaderParameters["Cookie"] = $Parameter.Value
} else {
$HeaderParameters[$Parameter.Name] = $Parameter.Value
}
}
if ($CookieParametters -and $CookieParameters.Count -gt 1) {
if ($CookieParameters -and $CookieParameters.Count -gt 1) {
Write-Warning "Multipe cookie parameters found. Curently only the first one is supported/used"
}
@ -86,11 +89,21 @@ function Invoke-PSApiClient {
$RequestBody = $Body
}
$Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
if ($SkipCertificateCheck -eq $true) {
$Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
-Method $Method `
-Headers $HeaderParameters `
-Body $RequestBody `
-ErrorAction Stop `
-SkipCertificateCheck
} else {
$Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
-Method $Method `
-Headers $HeaderParameters `
-Body $RequestBody `
-ErrorAction Stop
}
return @{
Response = DeserializeResponse -Response $Response -ReturnType $ReturnType