Skip to content

Commit

Permalink
better readme, type mapping, new option (#5740)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored Mar 29, 2020
1 parent 53a230a commit 77c1907
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bin/openapi3/powershell-experimental-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/powershell-experimental -i modules/openapi-generator/src/test/resources/3_0/powershell/petstore.yaml -g powershell-experimental -o samples/client/petstore/powershell-experimental --additional-properties packageGuid=a27b908d-2a20-467f-bc32-af6f3a654ac5,packageName=PSPetstore,apiNamePrefix=PS,packageVersion=0.1.2 -c ./bin/powershell-config.json $@"
ags="generate -t modules/openapi-generator/src/main/resources/powershell-experimental -i modules/openapi-generator/src/test/resources/3_0/powershell/petstore.yaml -g powershell-experimental -o samples/client/petstore/powershell-experimental --additional-properties powershellGalleryUrl=https://www.powershellgallery.com/packages/PSPetstore,packageGuid=a27b908d-2a20-467f-bc32-af6f3a654ac5,packageName=PSPetstore,apiNamePrefix=PS,packageVersion=0.1.2 -c ./bin/powershell-config.json $@"

java ${JAVA_OPTS} -jar ${executable} ${ags}
5 changes: 3 additions & 2 deletions docs/generators/powershell-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ sidebar_label: powershell-experimental

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|apiNamePrefix|Prefix that will be appended to all API names ('tags'). Default: empty string. e.g. Pet => Pet.| |null|
|apiNamePrefix|Prefix that will be appended to all PS objects. Default: empty string. e.g. Pet => PSPet.| |null|
|packageGuid|GUID for PowerShell module (e.g. a27b908d-2a20-467f-bc32-af6f3a654ac5). A random GUID will be generated by default.| |null|
|packageName|Client package name (e.g. org.openapitools.client).| |PSOpenAPITools|
|packageName|Client package name (e.g. PSTwitter).| |PSOpenAPITools|
|packageVersion|Package version (e.g. 0.1.2).| |0.1.2|
|powershellGalleryUrl|URL to the module in PowerShell Gallery (e.g. https://www.powershellgallery.com/packages/PSTwitter/).| |null|

## IMPORT MAPPING

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class PowerShellExperimentalClientCodegen extends DefaultCodegen implemen
protected String modelTestPath = "tests/Model";
protected HashSet nullablePrimitives;
protected HashSet powershellVerbs;
protected String powershellGalleryUrl;

/**
* Constructs an instance of `PowerShellExperimentalClientCodegen`.
Expand Down Expand Up @@ -308,19 +309,23 @@ public PowerShellExperimentalClientCodegen() {
typeMapping.put("long", "Int64");
typeMapping.put("double", "Double");
typeMapping.put("number", "Decimal");
typeMapping.put("date-time", "System.DateTime");
typeMapping.put("date", "System.DateTime");
typeMapping.put("object", "String");
typeMapping.put("object", "System.Hashtable");
typeMapping.put("file", "System.IO.FileInfo");
typeMapping.put("ByteArray", "System.Byte[]");
typeMapping.put("binary", "System.IO.FileInfo");
typeMapping.put("date", "System.DateTime");
typeMapping.put("date-time", "System.DateTime");
typeMapping.put("Date", "System.DateTime");
typeMapping.put("DateTime", "System.DateTime");
typeMapping.put("UUID", "String");
typeMapping.put("URI", "String");

cliOptions.clear();
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Client package name (e.g. org.openapitools.client).").defaultValue(this.packageName));
cliOptions.add(new CliOption("powershellGalleryUrl", "URL to the module in PowerShell Gallery (e.g. https://www.powershellgallery.com/packages/PSTwitter/)."));
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Client package name (e.g. PSTwitter).").defaultValue(this.packageName));
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Package version (e.g. 0.1.2).").defaultValue(this.packageVersion));
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."));
cliOptions.add(new CliOption(CodegenConstants.API_NAME_PREFIX, CodegenConstants.API_NAME_PREFIX_DESC));
cliOptions.add(new CliOption(CodegenConstants.API_NAME_PREFIX, "Prefix that will be appended to all PS objects. Default: empty string. e.g. Pet => PSPet."));

}

Expand Down Expand Up @@ -354,14 +359,30 @@ public void setPackageGuid(String packageGuid) {
this.packageGuid = packageGuid;
}

public void setPowershellGalleryUrl(String powershellGalleryUrl) {
this.powershellGalleryUrl = powershellGalleryUrl;
}

@Override
public void processOpts() {
super.processOpts();

if (additionalProperties.containsKey("powershellGalleryUrl")) {
setPowershellGalleryUrl((String) additionalProperties.get("powershellGalleryUrl"));
} else {
additionalProperties.put("powershellGalleryUrl", powershellGalleryUrl);
}

if (StringUtils.isNotBlank(powershellGalleryUrl)) {
additionalProperties.put("powershellGalleryId", powershellGalleryUrl.replaceFirst(".*/([^/?]+).*", "$1"));
//additionalProperties.put("powershellGalleryId", "something");
}

if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_GUID)) {
setPackageGuid((String) additionalProperties.get(CodegenConstants.OPTIONAL_PROJECT_GUID));
} else {
additionalProperties.put("packageGuid", packageGuid);
}
additionalProperties.put("packageGuid", packageGuid);

if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
this.setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ This PowerShell module is automatically generated by the [OpenAPI Generator](htt

<a name="installation"></a>
## Installation
Run the following command to build the PowerShell module locally:
- `Build.ps1`

Then import module from the .\src\{{{packageName}}} folder:
{{#powershellGalleryUrl}}
To install from PowerShell Gallery ({{{powershellGalleryUrl}}})
```powershell
Import-Module -Name {{{powershellGalleryId}}}
```
{{/powershellGalleryUrl}}

To install from the source, run the following command to build and install the PowerShell module locally:
```powershell
Build.ps1
Import-Module -Name '.\src\{{{packageName}}}'
```

To avoid function name collision, one can use `-Prefix`, e.g. `Import-Module -Name '.\src\{{{packageName}}}' -Prefix prefix`

To uninstall the module, simply run:
```powershell
Remove-Module -FullyQualifiedName @{ModuleName = "{{{packageName}}}"; ModuleVersion = "{{{packageVersion}}}"}
Expand Down
12 changes: 9 additions & 3 deletions samples/client/petstore/powershell-experimental/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ This PowerShell module is automatically generated by the [OpenAPI Generator](htt

<a name="installation"></a>
## Installation
Run the following command to build the PowerShell module locally:
- `Build.ps1`

Then import module from the .\src\PSPetstore folder:
To install from PowerShell Gallery (https://www.powershellgallery.com/packages/PSPetstore)
```powershell
Import-Module -Name PSPetstore
```

To install from the source, run the following command to build and install the PowerShell module locally:
```powershell
Build.ps1
Import-Module -Name '.\src\PSPetstore'
```

To avoid function name collision, one can use `-Prefix`, e.g. `Import-Module -Name '.\src\PSPetstore' -Prefix prefix`

To uninstall the module, simply run:
```powershell
Remove-Module -FullyQualifiedName @{ModuleName = "PSPetstore"; ModuleVersion = "0.1.2"}
Expand Down

0 comments on commit 77c1907

Please sign in to comment.