Skip to content

Commit 50b8795

Browse files
committed
add guid option to powershell generator
1 parent b5e061e commit 50b8795

17 files changed

Lines changed: 124 additions & 83 deletions

File tree

bin/powershell-petstore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fi
2626

2727
# if you've executed sbt assembly previously it will use that instead.
2828
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29-
ags="generate -t modules/swagger-codegen/src/main/resources/powershell -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l powershell -o samples/client/petstore/powershell_test $@"
29+
ags="generate -t modules/swagger-codegen/src/main/resources/powershell -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l powershell -o samples/client/petstore/powershell_test --additional-properties packageGuid=a27b908d-2a20-467f-bc32-af6f3a654ac5 $@"
3030

3131
java ${JAVA_OPTS} -jar ${executable} ${ags}

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PowerShellClientCodegen.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
import java.util.List;
1616
import java.util.Map;
1717

18+
import static java.util.UUID.randomUUID;
19+
1820
public class PowerShellClientCodegen extends DefaultCodegen implements CodegenConfig {
1921
static Logger LOGGER = LoggerFactory.getLogger(PowerShellClientCodegen.class);
20-
/*
21-
protected String groupId = "io.swagger";
22-
protected String artifactId = "kotlin-client";
23-
protected String artifactVersion = "1.0.0";
24-
*/
22+
23+
private String packageGuid = "{" + randomUUID().toString().toUpperCase() + "}";
24+
2525
protected String sourceFolder = "src";
2626
protected String packageName = "IO.Swagger";
2727
protected String apiDocPath = "docs/";
@@ -167,6 +167,7 @@ public PowerShellClientCodegen() {
167167

168168
cliOptions.clear();
169169
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Client package name (e.g. io.swagger.client).").defaultValue(this.packageName));
170+
cliOptions.add(new CliOption(CodegenConstants.OPTIONAL_PROJECT_GUID, "GUID for PowerShell module (e.g. a27b908d-2a20-467f-bc32-af6f3a654ac5). A random GUID will be generated by default."));
170171
//cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, "Client package's organization (i.e. maven groupId).").defaultValue(groupId));
171172
//cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, "Client artifact id (name of generated jar).").defaultValue(artifactId));
172173
//cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, "Client package version.").defaultValue(artifactVersion));
@@ -183,19 +184,7 @@ public String getName() {
183184
public String getHelp() {
184185
return "Generates a PowerShell client.";
185186
}
186-
/*
187-
public void setArtifactId(String artifactId) {
188-
this.artifactId = artifactId;
189-
}
190187

191-
public void setArtifactVersion(String artifactVersion) {
192-
this.artifactVersion = artifactVersion;
193-
}
194-
195-
public void setGroupId(String groupId) {
196-
this.groupId = groupId;
197-
}
198-
*/
199188
public void setPackageName(String packageName) {
200189
this.packageName = packageName;
201190
}
@@ -204,10 +193,19 @@ public void setSourceFolder(String sourceFolder) {
204193
this.sourceFolder = sourceFolder;
205194
}
206195

196+
public void setPackageGuid(String packageGuid) {
197+
this.packageGuid = packageGuid;
198+
}
199+
207200
@Override
208201
public void processOpts() {
209202
super.processOpts();
210203

204+
if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_GUID)) {
205+
setPackageGuid((String) additionalProperties.get(CodegenConstants.OPTIONAL_PROJECT_GUID));
206+
}
207+
additionalProperties.put("packageGuid", packageGuid);
208+
211209
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
212210
this.setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
213211
} else {

modules/swagger-codegen/src/main/resources/powershell/Build.ps1.mustache

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
function Get-FunctionsToExport {
2-
[CmdletBinding()]
3-
Param (
4-
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
5-
[ValidateNotNullOrEmpty()]
6-
[Alias('FullName')]
7-
$Path
8-
)
9-
10-
Process {
11-
$Token = $null
12-
$ParserErr = $null
13-
14-
$Ast = [System.Management.Automation.Language.Parser]::ParseFile(
15-
$Path,
16-
[ref]$Token,
17-
[ref]$ParserErr
18-
)
19-
20-
if ($ParserErr) {
21-
throw $ParserErr
1+
function Get-FunctionsToExport {
2+
[CmdletBinding()]
3+
Param (
4+
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
5+
[ValidateNotNullOrEmpty()]
6+
[Alias('FullName')]
7+
$Path
8+
)
9+
10+
Process {
11+
$Token = $null
12+
$ParserErr = $null
13+
14+
$Ast = [System.Management.Automation.Language.Parser]::ParseFile(
15+
$Path,
16+
[ref]$Token,
17+
[ref]$ParserErr
18+
)
19+
20+
if ($ParserErr) {
21+
throw $ParserErr
2222
} else {
23-
foreach ($name in 'Begin', 'Process', 'End') {
24-
foreach ($Statement in $Ast."${name}Block".Statements) {
25-
if (
26-
[String]::IsNullOrWhiteSpace($Statement.Name) -or
27-
$Statement.Extent.ToString() -notmatch
28-
('function\W+{0}' -f $Statement.Name)
29-
) {
30-
continue
31-
}
32-
33-
$Statement.Name
23+
foreach ($name in 'Begin', 'Process', 'End') {
24+
foreach ($Statement in $Ast."${name}Block".Statements) {
25+
if (
26+
[String]::IsNullOrWhiteSpace($Statement.Name) -or
27+
$Statement.Extent.ToString() -notmatch
28+
('function\W+{0}' -f $Statement.Name)
29+
) {
30+
continue
31+
}
32+
33+
$Statement.Name
3434
}
3535
}
36-
}
37-
}
36+
}
37+
}
3838
}
3939

4040
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
@@ -58,7 +58,7 @@ $Manifest = @{
5858
Description = '{{{packageName}}} - the PowerShell module for {{{appName}}}'
5959
6060
RootModule = '{{{packageName}}}.psm1'
61-
Guid = 'a27b908d-2a20-467f-bc32-af6f3a654ac5' # Has to be static, otherwise each new build will be considered different module
61+
Guid = '{{packageGuid}}' # Has to be static, otherwise each new build will be considered different module
6262
6363
PowerShellVersion = '3.0'
6464

samples/client/petstore/powershell_test/Build.ps1

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
1+
function Get-FunctionsToExport {
2+
[CmdletBinding()]
3+
Param (
4+
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
5+
[ValidateNotNullOrEmpty()]
6+
[Alias('FullName')]
7+
$Path
8+
)
9+
10+
Process {
11+
$Token = $null
12+
$ParserErr = $null
13+
14+
$Ast = [System.Management.Automation.Language.Parser]::ParseFile(
15+
$Path,
16+
[ref]$Token,
17+
[ref]$ParserErr
18+
)
19+
20+
if ($ParserErr) {
21+
throw $ParserErr
22+
} else {
23+
foreach ($name in 'Begin', 'Process', 'End') {
24+
foreach ($Statement in $Ast."${name}Block".Statements) {
25+
if (
26+
[String]::IsNullOrWhiteSpace($Statement.Name) -or
27+
$Statement.Extent.ToString() -notmatch
28+
('function\W+{0}' -f $Statement.Name)
29+
) {
30+
continue
31+
}
32+
33+
$Statement.Name
34+
}
35+
}
36+
}
37+
}
38+
}
39+
140
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
241
$ClientPath = ("$ScriptDir\..\..\petstore\csharp\SwaggerClient" | Resolve-Path).ProviderPath
3-
$PublicPath = "$ScriptDir\src\IO.Swagger\Public"
42+
$FunctionPath = 'API', 'Model' | ForEach-Object {Join-Path "$ScriptDir\src\IO.Swagger\" $_}
443
$BinPath = "$ScriptDir\src\IO.Swagger\Bin"
544

645
Start-Process -FilePath "$ClientPath\build.bat" -WorkingDirectory $ClientPath -Wait -NoNewWindow
@@ -27,9 +66,7 @@ $Manifest = @{
2766
Join-Path $_.Directory.Name $_.Name
2867
}
2968

30-
FunctionsToExport = Get-ChildItem "$PublicPath\*.ps1" | ForEach-Object {
31-
$_.BaseName
32-
}
69+
FunctionsToExport = $FunctionPath | Get-ChildItem -Filter *.ps1 | Get-FunctionsToExport
3370

3471
VariablesToExport = @()
3572
AliasesToExport = @()

samples/client/petstore/powershell_test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This PowerShell module is automatically generated by the [Swagger Codegen](https
66

77
- API version: 1.0.0
88
- SDK version:
9-
- Build date: 2017-06-12T00:52:17.472+08:00
9+
- Build date: 2017-06-14T01:15:54.164+08:00
1010
- Build package: io.swagger.codegen.languages.PowerShellClientCodegen
1111

1212
<a name="frameworks-supported"></a>

samples/client/petstore/powershell_test/docs/Pet.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Name | Type | Description | Notes
66
**id** | **Int64** | | [optional] [default to null]
77
**category** | [**IO.Swagger.Model.Category**](Category.md) | | [optional] [default to null]
88
**name** | **String** | | [default to null]
9-
**photoUrls** | **[String]** | | [default to null]
10-
**tags** | [**[IO.Swagger.Model.Tag]**](Tag.md) | | [optional] [default to null]
9+
**photoUrls** | **String** | | [default to null]
10+
**tags** | [**IO.Swagger.Model.Tag**](Tag.md) | | [optional] [default to null]
1111
**status** | **String** | pet status in the store | [optional] [default to null]
1212

1313
[[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_test/docs/PetApi.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void (empty response body)
144144

145145
<a name="findpetsbystatus"></a>
146146
# **FindPetsByStatus**
147-
> [IO.Swagger.Model.Pet] FindPetsByStatus ([String] status)
147+
> IO.Swagger.Model.Pet FindPetsByStatus (String status)
148148
149149
Finds Pets by status
150150

@@ -168,12 +168,12 @@ namespace Example
168168
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
169169

170170
var apiInstance = new PetApi();
171-
var status = new [String](); // [String] | Status values that need to be considered for filter
171+
var status = new String(); // String | Status values that need to be considered for filter
172172
173173
try
174174
{
175175
// Finds Pets by status
176-
[IO.Swagger.Model.Pet] result = apiInstance.FindPetsByStatus(status);
176+
IO.Swagger.Model.Pet result = apiInstance.FindPetsByStatus(status);
177177
Debug.WriteLine(result);
178178
}
179179
catch (Exception e)
@@ -189,11 +189,11 @@ namespace Example
189189

190190
Name | Type | Description | Notes
191191
------------- | ------------- | ------------- | -------------
192-
**status** | [**[String]**](String.md)| Status values that need to be considered for filter |
192+
**status** | [**String**](String.md)| Status values that need to be considered for filter |
193193

194194
### Return type
195195

196-
[**[IO.Swagger.Model.Pet]**](Pet.md)
196+
[**IO.Swagger.Model.Pet**](Pet.md)
197197

198198
### Authorization
199199

@@ -208,7 +208,7 @@ Name | Type | Description | Notes
208208

209209
<a name="findpetsbytags"></a>
210210
# **FindPetsByTags**
211-
> [IO.Swagger.Model.Pet] FindPetsByTags ([String] tags)
211+
> IO.Swagger.Model.Pet FindPetsByTags (String tags)
212212
213213
Finds Pets by tags
214214

@@ -232,12 +232,12 @@ namespace Example
232232
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
233233

234234
var apiInstance = new PetApi();
235-
var tags = new [String](); // [String] | Tags to filter by
235+
var tags = new String(); // String | Tags to filter by
236236
237237
try
238238
{
239239
// Finds Pets by tags
240-
[IO.Swagger.Model.Pet] result = apiInstance.FindPetsByTags(tags);
240+
IO.Swagger.Model.Pet result = apiInstance.FindPetsByTags(tags);
241241
Debug.WriteLine(result);
242242
}
243243
catch (Exception e)
@@ -253,11 +253,11 @@ namespace Example
253253

254254
Name | Type | Description | Notes
255255
------------- | ------------- | ------------- | -------------
256-
**tags** | [**[String]**](String.md)| Tags to filter by |
256+
**tags** | [**String**](String.md)| Tags to filter by |
257257

258258
### Return type
259259

260-
[**[IO.Swagger.Model.Pet]**](Pet.md)
260+
[**IO.Swagger.Model.Pet**](Pet.md)
261261

262262
### Authorization
263263

samples/client/petstore/powershell_test/docs/UserApi.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ No authorization required
7676

7777
<a name="createuserswitharrayinput"></a>
7878
# **CreateUsersWithArrayInput**
79-
> void CreateUsersWithArrayInput ([IO.Swagger.Model.User] body)
79+
> void CreateUsersWithArrayInput (IO.Swagger.Model.User body)
8080
8181
Creates list of users with given input array
8282

@@ -97,7 +97,7 @@ namespace Example
9797
public void main()
9898
{
9999
var apiInstance = new UserApi();
100-
var body = new [IO.Swagger.Model.User](); // [IO.Swagger.Model.User] | List of user object
100+
var body = new IO.Swagger.Model.User(); // IO.Swagger.Model.User | List of user object
101101
102102
try
103103
{
@@ -117,7 +117,7 @@ namespace Example
117117

118118
Name | Type | Description | Notes
119119
------------- | ------------- | ------------- | -------------
120-
**body** | [**[IO.Swagger.Model.User]**](User.md)| List of user object |
120+
**body** | [**IO.Swagger.Model.User**](User.md)| List of user object |
121121

122122
### Return type
123123

@@ -136,7 +136,7 @@ No authorization required
136136

137137
<a name="createuserswithlistinput"></a>
138138
# **CreateUsersWithListInput**
139-
> void CreateUsersWithListInput ([IO.Swagger.Model.User] body)
139+
> void CreateUsersWithListInput (IO.Swagger.Model.User body)
140140
141141
Creates list of users with given input array
142142

@@ -157,7 +157,7 @@ namespace Example
157157
public void main()
158158
{
159159
var apiInstance = new UserApi();
160-
var body = new [IO.Swagger.Model.User](); // [IO.Swagger.Model.User] | List of user object
160+
var body = new IO.Swagger.Model.User(); // IO.Swagger.Model.User | List of user object
161161
162162
try
163163
{
@@ -177,7 +177,7 @@ namespace Example
177177

178178
Name | Type | Description | Notes
179179
------------- | ------------- | ------------- | -------------
180-
**body** | [**[IO.Swagger.Model.User]**](User.md)| List of user object |
180+
**body** | [**IO.Swagger.Model.User**](User.md)| List of user object |
181181

182182
### Return type
183183

samples/client/petstore/powershell_test/src/IO.Swagger/API/PetApi.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Invoke-PetApiFindPetsByStatus {
4242
[CmdletBinding()]
4343
Param (
4444
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
45-
[[String]]
45+
[String]
4646
${status}
4747
)
4848

@@ -60,7 +60,7 @@ function Invoke-PetApiFindPetsByTags {
6060
[CmdletBinding()]
6161
Param (
6262
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
63-
[[String]]
63+
[String]
6464
${tags}
6565
)
6666

0 commit comments

Comments
 (0)