Skip to content

Commit eac18a7

Browse files
authored
[PowerShell][Experimental] Better docstring (#5688)
* add docstring to powershell module * add doc string
1 parent 63c8f5f commit eac18a7

18 files changed

Lines changed: 796 additions & 13 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public String toParamName(String name) {
594594
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
595595
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
596596
HashMap<String, CodegenModel> modelMaps = new HashMap<String, CodegenModel>();
597-
HashMap<String, Boolean> processedModelMaps = new HashMap<String, Boolean>();
597+
HashMap<String, Integer> processedModelMaps = new HashMap<String, Integer>();
598598

599599
for (Object o : allModels) {
600600
HashMap<String, Object> h = (HashMap<String, Object>) o;
@@ -672,7 +672,7 @@ public String toVarName(String name) {
672672
return name;
673673
}
674674

675-
private String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps, HashMap<String, Boolean> processedModelMap) {
675+
private String constructExampleCode(CodegenParameter codegenParameter, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
676676
if (codegenParameter.isListContainer) { // array
677677
return "@(" + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + ")";
678678
} else if (codegenParameter.isMapContainer) { // TODO: map, file type
@@ -714,7 +714,7 @@ private String constructExampleCode(CodegenParameter codegenParameter, HashMap<S
714714
}
715715
}
716716

717-
private String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps, HashMap<String, Boolean> processedModelMap) {
717+
private String constructExampleCode(CodegenProperty codegenProperty, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
718718
if (codegenProperty.isListContainer) { // array
719719
return "@(" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + ")";
720720
} else if (codegenProperty.isMapContainer) { // map
@@ -756,15 +756,23 @@ private String constructExampleCode(CodegenProperty codegenProperty, HashMap<Str
756756
}
757757
}
758758

759-
private String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps, HashMap<String, Boolean> processedModelMap) {
759+
private String constructExampleCode(CodegenModel codegenModel, HashMap<String, CodegenModel> modelMaps, HashMap<String, Integer> processedModelMap) {
760760
String example;
761761

762762
// break infinite recursion. Return, in case a model is already processed in the current context.
763763
String model = codegenModel.name;
764764
if (processedModelMap.containsKey(model)) {
765-
return "";
765+
int count = processedModelMap.get(model);
766+
if (count == 1) {
767+
processedModelMap.put(model, 2);
768+
} else if (count == 2) {
769+
return "";
770+
} else {
771+
throw new RuntimeException("Invalid count when constructing example: " + count);
772+
}
773+
} else {
774+
processedModelMap.put(model, 1);
766775
}
767-
processedModelMap.put(model, true);
768776

769777
example = "(New-" + codegenModel.name;
770778
List<String> propertyExamples = new ArrayList<>();

modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
{{> partial_header}}
22
{{#operations}}
33
{{#operation}}
4+
<#
5+
.SYNOPSIS
6+
7+
{{#summary}}{{{.}}}{{/summary}}{{^summary}}No summary available.{{/summary}}
8+
9+
.DESCRIPTION
10+
11+
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
12+
13+
{{#allParams}}
14+
.PARAMETER {{{paramName}}}
15+
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
16+
17+
{{/allParams}}
18+
.OUTPUTS
19+
20+
{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}None{{/returnType}}
21+
#>
422
function {{{vendorExtensions.x-powershell-method-name}}} {
523
[CmdletBinding()]
624
Param (

modules/openapi-generator/src/main/resources/powershell-experimental/configuration.mustache

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
{{> partial_header}}
2+
<#
3+
.SYNOPSIS
4+
5+
Get the configuration object '{{apiNamePrefix}}Configuration'.
6+
7+
.DESCRIPTION
8+
9+
Get the configuration object '{{apiNamePrefix}}Configuration'.
10+
11+
.OUTPUTS
12+
13+
System.Collections.Hashtable
14+
#>
215
function Get-{{apiNamePrefix}}Configuration {
316
417
$Configuration = $Script:Configuration
@@ -36,6 +49,43 @@ function Get-{{apiNamePrefix}}Configuration {
3649

3750
}
3851

52+
<#
53+
.SYNOPSIS
54+
55+
Set the configuration.
56+
57+
.DESCRIPTION
58+
59+
Set the configuration.
60+
61+
.PARAMETER BaseUrl
62+
Base URL of the HTTP endpoints
63+
64+
.PARAMETER Username
65+
Username in HTTP basic authentication
66+
67+
.PARAMETER Passowrd
68+
Password in HTTP basic authentication
69+
70+
.PARAMETER ApiKey
71+
API Keys for authentication/authorization
72+
73+
.PARAMETER ApiKeyPrefix
74+
Prefix in the API Keys
75+
76+
.PARAMETER Cookie
77+
Cookie for authentication/authorization
78+
79+
.PARAMETER AccessToken
80+
Access token for authentication/authorization
81+
82+
.PARAMETER SkipCertificateCheck
83+
Skip certificate verification
84+
85+
.OUTPUTS
86+
87+
System.Collections.Hashtable
88+
#>
3989
function Set-{{{apiNamePrefix}}}Configuration {
4090
4191
[CmdletBinding()]
@@ -92,6 +142,25 @@ function Set-{{{apiNamePrefix}}}Configuration {
92142
}
93143
}
94144

145+
<#
146+
.SYNOPSIS
147+
148+
Set the API Key.
149+
150+
.DESCRIPTION
151+
152+
Set the API Key.
153+
154+
.PARAMETER Id
155+
ID of the security schema
156+
157+
.PARAMETER ApiKey
158+
API Key
159+
160+
.OUTPUTS
161+
162+
None
163+
#>
95164
function Set-{{{apiNamePrefix}}}ConfigurationApiKey {
96165
[CmdletBinding()]
97166
Param(
@@ -107,6 +176,25 @@ function Set-{{{apiNamePrefix}}}ConfigurationApiKey {
107176
}
108177
}
109178

179+
<#
180+
.SYNOPSIS
181+
182+
Set the API Key prefix.
183+
184+
.DESCRIPTION
185+
186+
Set the API Key prefix.
187+
188+
.PARAMETER Id
189+
ID of the security schema
190+
191+
.PARAMETER ApiKey
192+
API Key prefix
193+
194+
.OUTPUTS
195+
196+
None
197+
#>
110198
function Set-{{{apiNamePrefix}}}ConfigurationApiKeyPrefix {
111199
[CmdletBinding()]
112200
Param(

modules/openapi-generator/src/main/resources/powershell-experimental/model.mustache

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
{{> partial_header}}
22
{{#models}}
33
{{#model}}
4+
<#
5+
.SYNOPSIS
6+
7+
{{#summary}}{{{.}}}{{/summary}}{{^summary}}No summary available.{{/summary}}
8+
9+
.DESCRIPTION
10+
11+
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
12+
13+
{{#vars}}
14+
.PARAMETER {{{name}}}
15+
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
16+
17+
{{/vars}}
18+
.OUTPUTS
19+
20+
{{{classname}}}<PSCustomObject>
21+
#>
22+
423
function New-{{{apiNamePrefix}}}{{{classname}}} {
524
[CmdletBinding()]
625
Param (

samples/client/petstore/powershell-experimental/docs/PSUserApi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ $Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
131131
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
132132
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
133133
134-
$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
134+
$User = @() # User[] | List of user object
135135
136136
# Creates list of users with given input array
137137
try {
@@ -368,7 +368,7 @@ $Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
368368
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
369369
370370
$Username = "Username_example" # String | name that need to be deleted (default to null)
371-
$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
371+
$User = # User | Updated user object
372372
373373
# Updated user
374374
try {

0 commit comments

Comments
 (0)