Skip to content

Commit d6bfecf

Browse files
Ghufzwing328
andauthored
[powershell] Updated the Api doc with httpsiging script snippet. (#7499)
* Added the httpsigning code snippet for api doc * Updated the sample * update samples Co-authored-by: William Cheng <wing328hk@gmail.com>
1 parent 9ba9433 commit d6bfecf

15 files changed

Lines changed: 89 additions & 62 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ To install and run `Pester`, please execute the following commands in the termin
5454
```powershell
5555
Install-module -name Pester -force
5656

57-
Invoker-Pester
57+
Invoke-Pester
5858
```
5959

6060
For troubleshooting, please run `$DebugPreference = 'Continue'` to turn on debugging and disable it with `$DebugPreference = 'SilentlyContinue'` when done with the troubleshooting.

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ $Configuration["ApiKey"]["{{{keyParamName}}}"] = "YOUR_API_KEY"
4343
# Configure OAuth2 access token for authorization: {{{name}}}
4444
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
4545
{{/isOAuth}}
46+
47+
{{#isHttpSignature}}
48+
# Configure HttpSignature for authorization :{{name}}
49+
$httpSigningParams = @{
50+
KeyId = "xxxxxx1776876789ac747/xxxxxxx564612d31a62c01/xxxxxxxa1d7564612d31a66ee8"
51+
KeyFilePath = "C:\SecretKey.txt"
52+
HttpSigningHeader = @("(request-target)","Host","Date","Digest")
53+
HashAlgorithm = "sha256"
54+
}
55+
Set-{{{packageName}}}ConfigurationHttpSigning @httpSigningParams
56+
57+
{{/isHttpSignature}}
4658
{{/authMethods}}
4759

4860
{{/hasAuthMethods}}
@@ -54,7 +66,7 @@ ${{paramName}} = {{{vendorExtensions.x-powershell-example}}} # {{{dataType}}} |
5466
# {{{.}}}
5567
{{/summary}}
5668
try {
57-
{{#returnType}}{{returnType}} $Result = {{/returnType}}{{{vendorExtensions.x-powershell-method-name}}}{{#allParams}} -{{paramName}} ${{paramName}}{{/allParams}}
69+
$Result = {{{vendorExtensions.x-powershell-method-name}}}{{#allParams}} -{{paramName}} ${{paramName}}{{/allParams}}
5870
} catch {
5971
Write-Host ("Exception occured when calling {{{vendorExtensions.x-powershell-method-name}}}: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
6072
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
@@ -69,7 +81,7 @@ Name | Type | Description | Notes
6981
{{/allParams}}
7082

7183
### Return type
72-
84+
# cmdlet returns PSCustomObject, the return object contains the properties of below type
7385
{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{{returnType}}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}void (empty response body){{/returnType}}
7486

7587
### Authorization

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ Name | Type | Description | Notes
1212

1313
- Prepare the resource
1414
```powershell
15-
Initialize-{{{packageName}}}{{{classname}}} {{#vars}} -{{name}} {{example}}{{#hasMore}} `
15+
${{{classname}}} = Initialize-{{{packageName}}}{{{classname}}} {{#vars}} -{{name}} {{example}}{{#hasMore}} `
1616
{{/hasMore}}
1717
{{/vars}}
1818

1919
```
2020

2121
- Convert the resource to JSON
2222
```powershell
23-
${{className}} | Convert-ToJSON
23+
${{{classname}}} | ConvertTo-JSON
2424
```
2525

2626
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

samples/client/petstore/powershell/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ To install and run `Pester`, please execute the following commands in the termin
4444
```powershell
4545
Install-module -name Pester -force
4646
47-
Invoker-Pester
47+
Invoke-Pester
4848
```
4949

5050
For troubleshooting, please run `$DebugPreference = 'Continue'` to turn on debugging and disable it with `$DebugPreference = 'SilentlyContinue'` when done with the troubleshooting.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Name | Type | Description | Notes
1111

1212
- Prepare the resource
1313
```powershell
14-
Initialize-PSPetstoreApiResponse -Code null `
14+
$ApiResponse = Initialize-PSPetstoreApiResponse -Code null `
1515
-Type null `
1616
-Message null
1717
```
1818

1919
- Convert the resource to JSON
2020
```powershell
21-
$ | Convert-ToJSON
21+
$ApiResponse | ConvertTo-JSON
2222
```
2323

2424
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Name | Type | Description | Notes
1010

1111
- Prepare the resource
1212
```powershell
13-
Initialize-PSPetstoreCategory -Id null `
13+
$Category = Initialize-PSPetstoreCategory -Id null `
1414
-Name null
1515
```
1616

1717
- Convert the resource to JSON
1818
```powershell
19-
$ | Convert-ToJSON
19+
$Category | ConvertTo-JSON
2020
```
2121

2222
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Name | Type | Description | Notes
1010

1111
- Prepare the resource
1212
```powershell
13-
Initialize-PSPetstoreInlineObject -Name null `
13+
$InlineObject = Initialize-PSPetstoreInlineObject -Name null `
1414
-Status null
1515
```
1616

1717
- Convert the resource to JSON
1818
```powershell
19-
$ | Convert-ToJSON
19+
$InlineObject | ConvertTo-JSON
2020
```
2121

2222
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Name | Type | Description | Notes
1010

1111
- Prepare the resource
1212
```powershell
13-
Initialize-PSPetstoreInlineObject1 -AdditionalMetadata null `
13+
$InlineObject1 = Initialize-PSPetstoreInlineObject1 -AdditionalMetadata null `
1414
-File null
1515
```
1616

1717
- Convert the resource to JSON
1818
```powershell
19-
$ | Convert-ToJSON
19+
$InlineObject1 | ConvertTo-JSON
2020
```
2121

2222
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Name | Type | Description | Notes
1414

1515
- Prepare the resource
1616
```powershell
17-
Initialize-PSPetstoreOrder -Id null `
17+
$Order = Initialize-PSPetstoreOrder -Id null `
1818
-PetId null `
1919
-Quantity null `
2020
-ShipDate null `
@@ -24,7 +24,7 @@ Initialize-PSPetstoreOrder -Id null `
2424

2525
- Convert the resource to JSON
2626
```powershell
27-
$ | Convert-ToJSON
27+
$Order | ConvertTo-JSON
2828
```
2929

3030
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ $Configuration = Get-PSPetstoreConfiguration
2929
# Configure OAuth2 access token for authorization: petstore_auth
3030
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
3131
32+
3233
$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
3334
3435
# Add a new pet to the store
3536
try {
36-
Pet $Result = Add-PSPet -Pet $Pet
37+
$Result = Add-PSPet -Pet $Pet
3738
} catch {
3839
Write-Host ("Exception occured when calling Add-PSPet: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
3940
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
@@ -47,7 +48,7 @@ Name | Type | Description | Notes
4748
**Pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
4849

4950
### Return type
50-
51+
# cmdlet returns PSCustomObject, the return object contains the properties of below type
5152
[**Pet**](Pet.md)
5253

5354
### Authorization
@@ -77,12 +78,13 @@ $Configuration = Get-PSPetstoreConfiguration
7778
# Configure OAuth2 access token for authorization: petstore_auth
7879
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
7980
81+
8082
$PetId = 987 # Int64 | Pet id to delete
8183
$ApiKey = "ApiKey_example" # String | (optional)
8284
8385
# Deletes a pet
8486
try {
85-
Remove-Pet -PetId $PetId -ApiKey $ApiKey
87+
$Result = Remove-Pet -PetId $PetId -ApiKey $ApiKey
8688
} catch {
8789
Write-Host ("Exception occured when calling Remove-Pet: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
8890
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
@@ -97,7 +99,7 @@ Name | Type | Description | Notes
9799
**ApiKey** | **String**| | [optional]
98100

99101
### Return type
100-
102+
# cmdlet returns PSCustomObject, the return object contains the properties of below type
101103
void (empty response body)
102104

103105
### Authorization
@@ -128,11 +130,12 @@ $Configuration = Get-PSPetstoreConfiguration
128130
# Configure OAuth2 access token for authorization: petstore_auth
129131
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
130132
133+
131134
$Status = @("Status_example") # String[] | Status values that need to be considered for filter
132135
133136
# Finds Pets by status
134137
try {
135-
Pet[] $Result = Find-PSPetsByStatus -Status $Status
138+
$Result = Find-PSPetsByStatus -Status $Status
136139
} catch {
137140
Write-Host ("Exception occured when calling Find-PSPetsByStatus: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
138141
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
@@ -146,7 +149,7 @@ Name | Type | Description | Notes
146149
**Status** | [**String[]**](String.md)| Status values that need to be considered for filter |
147150

148151
### Return type
149-
152+
# cmdlet returns PSCustomObject, the return object contains the properties of below type
150153
[**Pet[]**](Pet.md)
151154

152155
### Authorization
@@ -177,11 +180,12 @@ $Configuration = Get-PSPetstoreConfiguration
177180
# Configure OAuth2 access token for authorization: petstore_auth
178181
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
179182
183+
180184
$Tags = @("Inner_example") # String[] | Tags to filter by
181185
182186
# Finds Pets by tags
183187
try {
184-
Pet[] $Result = Find-PSPetsByTags -Tags $Tags
188+
$Result = Find-PSPetsByTags -Tags $Tags
185189
} catch {
186190
Write-Host ("Exception occured when calling Find-PSPetsByTags: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
187191
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
@@ -195,7 +199,7 @@ Name | Type | Description | Notes
195199
**Tags** | [**String[]**](String.md)| Tags to filter by |
196200

197201
### Return type
198-
202+
# cmdlet returns PSCustomObject, the return object contains the properties of below type
199203
[**Pet[]**](Pet.md)
200204

201205
### Authorization
@@ -228,11 +232,12 @@ $Configuration["ApiKey"]["api_key"] = "YOUR_API_KEY"
228232
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
229233
#$Configuration["ApiKeyPrefix"]["api_key"] = "Bearer"
230234
235+
231236
$PetId = 987 # Int64 | ID of pet to return
232237
233238
# Find pet by ID
234239
try {
235-
Pet $Result = Get-PSPetById -PetId $PetId
240+
$Result = Get-PSPetById -PetId $PetId
236241
} catch {
237242
Write-Host ("Exception occured when calling Get-PSPetById: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
238243
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
@@ -246,7 +251,7 @@ Name | Type | Description | Notes
246251
**PetId** | **Int64**| ID of pet to return |
247252

248253
### Return type
249-
254+
# cmdlet returns PSCustomObject, the return object contains the properties of below type
250255
[**Pet**](Pet.md)
251256

252257
### Authorization
@@ -275,11 +280,12 @@ $Configuration = Get-PSPetstoreConfiguration
275280
# Configure OAuth2 access token for authorization: petstore_auth
276281
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
277282
283+
278284
$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
279285
280286
# Update an existing pet
281287
try {
282-
Pet $Result = Update-PSPet -Pet $Pet
288+
$Result = Update-PSPet -Pet $Pet
283289
} catch {
284290
Write-Host ("Exception occured when calling Update-PSPet: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
285291
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
@@ -293,7 +299,7 @@ Name | Type | Description | Notes
293299
**Pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
294300

295301
### Return type
296-
302+
# cmdlet returns PSCustomObject, the return object contains the properties of below type
297303
[**Pet**](Pet.md)
298304

299305
### Authorization
@@ -324,13 +330,14 @@ $Configuration = Get-PSPetstoreConfiguration
324330
# Configure OAuth2 access token for authorization: petstore_auth
325331
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
326332
333+
327334
$PetId = 987 # Int64 | ID of pet that needs to be updated
328335
$Name = "Name_example" # String | Updated name of the pet (optional)
329336
$Status = "Status_example" # String | Updated status of the pet (optional)
330337
331338
# Updates a pet in the store with form data
332339
try {
333-
Update-PSPetWithForm -PetId $PetId -Name $Name -Status $Status
340+
$Result = Update-PSPetWithForm -PetId $PetId -Name $Name -Status $Status
334341
} catch {
335342
Write-Host ("Exception occured when calling Update-PSPetWithForm: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
336343
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
@@ -346,7 +353,7 @@ Name | Type | Description | Notes
346353
**Status** | **String**| Updated status of the pet | [optional]
347354

348355
### Return type
349-
356+
# cmdlet returns PSCustomObject, the return object contains the properties of below type
350357
void (empty response body)
351358

352359
### Authorization
@@ -377,13 +384,14 @@ $Configuration = Get-PSPetstoreConfiguration
377384
# Configure OAuth2 access token for authorization: petstore_auth
378385
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
379386
387+
380388
$PetId = 987 # Int64 | ID of pet to update
381389
$AdditionalMetadata = "AdditionalMetadata_example" # String | Additional data to pass to server (optional)
382390
$File = 987 # System.IO.FileInfo | file to upload (optional)
383391
384392
# uploads an image
385393
try {
386-
ApiResponse $Result = Invoke-PSUploadFile -PetId $PetId -AdditionalMetadata $AdditionalMetadata -File $File
394+
$Result = Invoke-PSUploadFile -PetId $PetId -AdditionalMetadata $AdditionalMetadata -File $File
387395
} catch {
388396
Write-Host ("Exception occured when calling Invoke-PSUploadFile: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
389397
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
@@ -399,7 +407,7 @@ Name | Type | Description | Notes
399407
**File** | **System.IO.FileInfo****System.IO.FileInfo**| file to upload | [optional]
400408

401409
### Return type
402-
410+
# cmdlet returns PSCustomObject, the return object contains the properties of below type
403411
[**ApiResponse**](ApiResponse.md)
404412

405413
### Authorization

0 commit comments

Comments
 (0)