Skip to content

Commit 3d23b99

Browse files
authored
minor fix to powershell api doc (#8496)
1 parent b447e4f commit 3d23b99

5 files changed

Lines changed: 81 additions & 72 deletions

File tree

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,12 @@ private String constructExampleCode(CodegenParameter codegenParameter, HashMap<S
10821082
if (StringUtils.isEmpty(codegenParameter.example)) {
10831083
return "\"" + codegenParameter.example + "\"";
10841084
} else {
1085-
return "\"" + codegenParameter.paramName + "_example\"";
1085+
if (Boolean.TRUE.equals(codegenParameter.isEnum)) { // enum
1086+
List<Object> enumValues = (List<Object>) codegenParameter.allowableValues.get("values");
1087+
return "\"" + String.valueOf(enumValues.get(0)) + "\"";
1088+
} else {
1089+
return "\"" + codegenParameter.paramName + "_example\"";
1090+
}
10861091
}
10871092
} else if ("Boolean".equals(codegenParameter.dataType) ||
10881093
"System.Nullable[Boolean]".equals(codegenParameter.dataType)) { // boolean
@@ -1124,7 +1129,12 @@ private String constructExampleCode(CodegenProperty codegenProperty, HashMap<Str
11241129
if (StringUtils.isEmpty(codegenProperty.example)) {
11251130
return "\"" + codegenProperty.example + "\"";
11261131
} else {
1127-
return "\"" + codegenProperty.name + "_example\"";
1132+
if (Boolean.TRUE.equals(codegenProperty.isEnum)) { // enum
1133+
List<Object> enumValues = (List<Object>) codegenProperty.allowableValues.get("values");
1134+
return "\"" + String.valueOf(enumValues.get(0)) + "\"";
1135+
} else {
1136+
return "\"" + codegenProperty.name + "_example\"";
1137+
}
11281138
}
11291139
} else if ("Boolean".equals(codegenProperty.dataType) ||
11301140
"System.Nullable[Boolean]".equals(codegenProperty.dataType)) { // boolean
@@ -1173,7 +1183,7 @@ private String constructExampleCode(CodegenModel codegenModel, HashMap<String, C
11731183
processedModelMap.put(model, 1);
11741184
}
11751185

1176-
example = "(Initialize-" + codegenModel.name;
1186+
example = "(Initialize-" + codegenModel.name + " ";
11771187
List<String> propertyExamples = new ArrayList<>();
11781188
for (CodegenProperty codegenProperty : codegenModel.allVars) {
11791189
propertyExamples.add("-" + codegenProperty.name + " " + constructExampleCode(codegenProperty, modelMaps, processedModelMap));

modules/openapi-generator/src/main/resources/powershell/api_doc.mustache

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ Method | HTTP request | Description
2626
Import-Module -Name {{{packageName}}}
2727

2828
{{#hasAuthMethods}}
29-
$Configuration = Get-{{{packageName}}}Configuration
29+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
30+
$Configuration = Get-Configuration
3031
{{#authMethods}}
3132
{{#isBasic}}
3233
# Configure HTTP basic authorization: {{{name}}}
33-
$Configuration["Username"] = "YOUR_USERNAME";
34-
$Configuration["Password"] = "YOUR_PASSWORD";
34+
$Configuration.Username = "YOUR_USERNAME"
35+
$Configuration.Password = "YOUR_PASSWORD"
3536
{{/isBasic}}
3637
{{#isApiKey}}
3738
# Configure API key authorization: {{{name}}}
38-
$Configuration["ApiKey"]["{{{keyParamName}}}"] = "YOUR_API_KEY"
39+
$Configuration.ApiKey.{{{keyParamName}}} = "YOUR_API_KEY"
3940
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
40-
#$Configuration["ApiKeyPrefix"]["{{{keyParamName}}}"] = "Bearer"
41+
#$Configuration.ApiKeyPrefix.{{{keyParamName}}} = "Bearer"
4142
{{/isApiKey}}
4243
{{#isOAuth}}
4344
# Configure OAuth2 access token for authorization: {{{name}}}
44-
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
45+
$Configuration.AccessToken = "YOUR_ACCESS_TOKEN"
4546
{{/isOAuth}}
46-
4747
{{#isHttpSignature}}
4848
# Configure HttpSignature for authorization :{{name}}
4949
$httpSigningParams = @{
@@ -52,11 +52,10 @@ $httpSigningParams = @{
5252
HttpSigningHeader = @("(request-target)","Host","Date","Digest")
5353
HashAlgorithm = "sha256"
5454
}
55-
Set-{{{packageName}}}ConfigurationHttpSigning @httpSigningParams
56-
55+
Set-ConfigurationHttpSigning $httpSigningParams
5756
{{/isHttpSignature}}
58-
{{/authMethods}}
5957

58+
{{/authMethods}}
6059
{{/hasAuthMethods}}
6160
{{#allParams}}
6261
${{paramName}} = {{{vendorExtensions.x-powershell-example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}

samples/client/petstore/powershell/docs/PSPetApi.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ Add a new pet to the store
2525
```powershell
2626
Import-Module -Name PSPetstore
2727
28-
$Configuration = Get-PSPetstoreConfiguration
28+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
29+
$Configuration = Get-Configuration
2930
# Configure OAuth2 access token for authorization: petstore_auth
30-
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
31+
$Configuration.AccessToken = "YOUR_ACCESS_TOKEN"
3132
32-
33-
$Pet = (Initialize-Pet-Id 123 -Category (Initialize-Category-Id 123 -Name "Name_example") -Name "Name_example" -PhotoUrls @("PhotoUrls_example") -Tags @((Initialize-Tag-Id 123 -Name "Name_example")) -Status "Status_example") # Pet | Pet object that needs to be added to the store
33+
$Pet = (Initialize-Pet -Id 123 -Category (Initialize-Category -Id 123 -Name "Name_example") -Name "Name_example" -PhotoUrls @("PhotoUrls_example") -Tags @((Initialize-Tag -Id 123 -Name "Name_example")) -Status "available") # Pet | Pet object that needs to be added to the store
3434
3535
# Add a new pet to the store
3636
try {
@@ -74,10 +74,10 @@ Deletes a pet
7474
```powershell
7575
Import-Module -Name PSPetstore
7676
77-
$Configuration = Get-PSPetstoreConfiguration
77+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
78+
$Configuration = Get-Configuration
7879
# Configure OAuth2 access token for authorization: petstore_auth
79-
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
80-
80+
$Configuration.AccessToken = "YOUR_ACCESS_TOKEN"
8181
8282
$PetId = 987 # Int64 | Pet id to delete
8383
$ApiKey = "ApiKey_example" # String | (optional)
@@ -126,12 +126,12 @@ Multiple status values can be provided with comma separated strings
126126
```powershell
127127
Import-Module -Name PSPetstore
128128
129-
$Configuration = Get-PSPetstoreConfiguration
129+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
130+
$Configuration = Get-Configuration
130131
# Configure OAuth2 access token for authorization: petstore_auth
131-
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
132+
$Configuration.AccessToken = "YOUR_ACCESS_TOKEN"
132133
133-
134-
$Status = @("Status_example") # String[] | Status values that need to be considered for filter
134+
$Status = @("available") # String[] | Status values that need to be considered for filter
135135
136136
# Finds Pets by status
137137
try {
@@ -176,10 +176,10 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
176176
```powershell
177177
Import-Module -Name PSPetstore
178178
179-
$Configuration = Get-PSPetstoreConfiguration
179+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
180+
$Configuration = Get-Configuration
180181
# Configure OAuth2 access token for authorization: petstore_auth
181-
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
182-
182+
$Configuration.AccessToken = "YOUR_ACCESS_TOKEN"
183183
184184
$Tags = @("Inner_example") # String[] | Tags to filter by
185185
@@ -226,12 +226,12 @@ Returns a single pet
226226
```powershell
227227
Import-Module -Name PSPetstore
228228
229-
$Configuration = Get-PSPetstoreConfiguration
229+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
230+
$Configuration = Get-Configuration
230231
# Configure API key authorization: api_key
231-
$Configuration["ApiKey"]["api_key"] = "YOUR_API_KEY"
232+
$Configuration.ApiKey.api_key = "YOUR_API_KEY"
232233
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
233-
#$Configuration["ApiKeyPrefix"]["api_key"] = "Bearer"
234-
234+
#$Configuration.ApiKeyPrefix.api_key = "Bearer"
235235
236236
$PetId = 987 # Int64 | ID of pet to return
237237
@@ -276,12 +276,12 @@ Update an existing pet
276276
```powershell
277277
Import-Module -Name PSPetstore
278278
279-
$Configuration = Get-PSPetstoreConfiguration
279+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
280+
$Configuration = Get-Configuration
280281
# Configure OAuth2 access token for authorization: petstore_auth
281-
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
282-
282+
$Configuration.AccessToken = "YOUR_ACCESS_TOKEN"
283283
284-
$Pet = (Initialize-Pet-Id 123 -Category (Initialize-Category-Id 123 -Name "Name_example") -Name "Name_example" -PhotoUrls @("PhotoUrls_example") -Tags @((Initialize-Tag-Id 123 -Name "Name_example")) -Status "Status_example") # Pet | Pet object that needs to be added to the store
284+
$Pet = (Initialize-Pet -Id 123 -Category (Initialize-Category -Id 123 -Name "Name_example") -Name "Name_example" -PhotoUrls @("PhotoUrls_example") -Tags @((Initialize-Tag -Id 123 -Name "Name_example")) -Status "available") # Pet | Pet object that needs to be added to the store
285285
286286
# Update an existing pet
287287
try {
@@ -326,10 +326,10 @@ Updates a pet in the store with form data
326326
```powershell
327327
Import-Module -Name PSPetstore
328328
329-
$Configuration = Get-PSPetstoreConfiguration
329+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
330+
$Configuration = Get-Configuration
330331
# Configure OAuth2 access token for authorization: petstore_auth
331-
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
332-
332+
$Configuration.AccessToken = "YOUR_ACCESS_TOKEN"
333333
334334
$PetId = 987 # Int64 | ID of pet that needs to be updated
335335
$Name = "Name_example" # String | Updated name of the pet (optional)
@@ -380,10 +380,10 @@ uploads an image
380380
```powershell
381381
Import-Module -Name PSPetstore
382382
383-
$Configuration = Get-PSPetstoreConfiguration
383+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
384+
$Configuration = Get-Configuration
384385
# Configure OAuth2 access token for authorization: petstore_auth
385-
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
386-
386+
$Configuration.AccessToken = "YOUR_ACCESS_TOKEN"
387387
388388
$PetId = 987 # Int64 | ID of pet to update
389389
$AdditionalMetadata = "AdditionalMetadata_example" # String | Additional data to pass to server (optional)

samples/client/petstore/powershell/docs/PSStoreApi.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ Returns a map of status codes to quantities
6767
```powershell
6868
Import-Module -Name PSPetstore
6969
70-
$Configuration = Get-PSPetstoreConfiguration
70+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
71+
$Configuration = Get-Configuration
7172
# Configure API key authorization: api_key
72-
$Configuration["ApiKey"]["api_key"] = "YOUR_API_KEY"
73+
$Configuration.ApiKey.api_key = "YOUR_API_KEY"
7374
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
74-
#$Configuration["ApiKeyPrefix"]["api_key"] = "Bearer"
75-
75+
#$Configuration.ApiKeyPrefix.api_key = "Bearer"
7676
7777
7878
# Returns pet inventories by status
@@ -158,7 +158,7 @@ Place an order for a pet
158158
```powershell
159159
Import-Module -Name PSPetstore
160160
161-
$Order = (Initialize-Order-Id 123 -PetId 123 -Quantity 123 -ShipDate Get-Date -Status "Status_example" -Complete $false) # Order | order placed for purchasing the pet
161+
$Order = (Initialize-Order -Id 123 -PetId 123 -Quantity 123 -ShipDate Get-Date -Status "placed" -Complete $false) # Order | order placed for purchasing the pet
162162
163163
# Place an order for a pet
164164
try {

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ This can only be done by the logged in user.
2727
```powershell
2828
Import-Module -Name PSPetstore
2929
30-
$Configuration = Get-PSPetstoreConfiguration
30+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
31+
$Configuration = Get-Configuration
3132
# Configure API key authorization: auth_cookie
32-
$Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
33+
$Configuration.ApiKey.AUTH_KEY = "YOUR_API_KEY"
3334
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
34-
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
35+
#$Configuration.ApiKeyPrefix.AUTH_KEY = "Bearer"
3536
36-
37-
$User = (Initialize-User-Id 123 -Username "Username_example" -FirstName "FirstName_example" -LastName "LastName_example" -Email "Email_example" -Password "Password_example" -Phone "Phone_example" -UserStatus 123) # User | Created user object
37+
$User = (Initialize-User -Id 123 -Username "Username_example" -FirstName "FirstName_example" -LastName "LastName_example" -Email "Email_example" -Password "Password_example" -Phone "Phone_example" -UserStatus 123) # User | Created user object
3838
3939
# Create user
4040
try {
@@ -77,14 +77,14 @@ Creates list of users with given input array
7777
```powershell
7878
Import-Module -Name PSPetstore
7979
80-
$Configuration = Get-PSPetstoreConfiguration
80+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
81+
$Configuration = Get-Configuration
8182
# Configure API key authorization: auth_cookie
82-
$Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
83+
$Configuration.ApiKey.AUTH_KEY = "YOUR_API_KEY"
8384
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
84-
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
85-
85+
#$Configuration.ApiKeyPrefix.AUTH_KEY = "Bearer"
8686
87-
$User = @((Initialize-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
87+
$User = @((Initialize-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
8888
8989
# Creates list of users with given input array
9090
try {
@@ -127,12 +127,12 @@ Creates list of users with given input array
127127
```powershell
128128
Import-Module -Name PSPetstore
129129
130-
$Configuration = Get-PSPetstoreConfiguration
130+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
131+
$Configuration = Get-Configuration
131132
# Configure API key authorization: auth_cookie
132-
$Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
133+
$Configuration.ApiKey.AUTH_KEY = "YOUR_API_KEY"
133134
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
134-
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
135-
135+
#$Configuration.ApiKeyPrefix.AUTH_KEY = "Bearer"
136136
137137
$User = @() # User[] | List of user object
138138
@@ -179,12 +179,12 @@ This can only be done by the logged in user.
179179
```powershell
180180
Import-Module -Name PSPetstore
181181
182-
$Configuration = Get-PSPetstoreConfiguration
182+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
183+
$Configuration = Get-Configuration
183184
# Configure API key authorization: auth_cookie
184-
$Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
185+
$Configuration.ApiKey.AUTH_KEY = "YOUR_API_KEY"
185186
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
186-
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
187-
187+
#$Configuration.ApiKeyPrefix.AUTH_KEY = "Bearer"
188188
189189
$Username = "Username_example" # String | The name that needs to be deleted
190190
@@ -317,12 +317,12 @@ Logs out current logged in user session
317317
```powershell
318318
Import-Module -Name PSPetstore
319319
320-
$Configuration = Get-PSPetstoreConfiguration
320+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
321+
$Configuration = Get-Configuration
321322
# Configure API key authorization: auth_cookie
322-
$Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
323+
$Configuration.ApiKey.AUTH_KEY = "YOUR_API_KEY"
323324
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
324-
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
325-
325+
#$Configuration.ApiKeyPrefix.AUTH_KEY = "Bearer"
326326
327327
328328
# Logs out current logged in user session
@@ -366,12 +366,12 @@ This can only be done by the logged in user.
366366
```powershell
367367
Import-Module -Name PSPetstore
368368
369-
$Configuration = Get-PSPetstoreConfiguration
369+
# general setting of the PowerShell module, e.g. base URL, authentication, etc
370+
$Configuration = Get-Configuration
370371
# Configure API key authorization: auth_cookie
371-
$Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
372+
$Configuration.ApiKey.AUTH_KEY = "YOUR_API_KEY"
372373
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
373-
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
374-
374+
#$Configuration.ApiKeyPrefix.AUTH_KEY = "Bearer"
375375
376376
$Username = "Username_example" # String | name that need to be deleted
377377
$User = # User | Updated user object

0 commit comments

Comments
 (0)