From ba2f1ce4f26b30947ec11991b62acf40547a03e1 Mon Sep 17 00:00:00 2001 From: Ghufz <18732053+Ghufz@users.noreply.github.com> Date: Mon, 30 Nov 2020 11:52:54 +0530 Subject: [PATCH 1/3] Implemented the psdata property for module manifest file (Tags, LicenseUri, ProjectUri, IconUri, ReleaseNotes) --- bin/configs/powershell.yaml | 4 ++ .../languages/PowerShellClientCodegen.java | 69 +++++++++++++++++++ .../resources/powershell/Build.ps1.mustache | 15 ++++ samples/client/petstore/powershell/Build.ps1 | 4 ++ .../powershell/src/PSPetstore/PSPetstore.psd1 | 12 ++-- 5 files changed, 98 insertions(+), 6 deletions(-) diff --git a/bin/configs/powershell.yaml b/bin/configs/powershell.yaml index 62a6dab02e14..c31d09aa13c3 100644 --- a/bin/configs/powershell.yaml +++ b/bin/configs/powershell.yaml @@ -10,3 +10,7 @@ additionalProperties: powershellGalleryUrl: https://www.powershellgallery.com/packages/PSPetstore apiNamePrefix: PS powershellVersion: "5.0" + licenseUri: https://www.apache.org/licenses/LICENSE-2.0.txt + projectUri: https://github.com/OpenAPITools/openapi-generator + releaseNotes: 'This is a sample project' + tags: 'PetStore,powershell,sdk' diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java index fa012ed2d52a..18c3e4ff6e35 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java @@ -55,6 +55,11 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo protected HashSet methodNames; // store a list of method names to detect duplicates protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup protected boolean discardReadOnly = false; // Discard the readonly property in initialize cmdlet + protected String projectUri; + protected String licenseUri; + protected String releaseNotes; + protected String tags; + protected String iconUri; /** * Constructs an instance of `PowerShellClientCodegen`. @@ -501,6 +506,11 @@ public PowerShellClientCodegen() { cliOptions.add(new CliOption("commonVerbs", "PS common verb mappings. e.g. Delete=Remove:Patch=Update to map Delete with Remove and Patch with Update accordingly.")); cliOptions.add(new CliOption(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC)); cliOptions.add(new CliOption("discardReadOnly", "Set discardReadonly to true to generate the Initialize cmdlet without readonly parameters")); + cliOptions.add(new CliOption("tags","Tags applied to the generated PowerShell module. These help with module discovery in online galleries")); + cliOptions.add(new CliOption("projectUri","A URL to the main website for this project")); + cliOptions.add(new CliOption("licenseUri","A URL to the license for the generated PowerShell module")); + cliOptions.add(new CliOption("iconUri","A URL to an icon representing the generated PowerShell module")); + cliOptions.add(new CliOption("releaseNotes","Release notes of the generated PowerShell module")); // option to change how we process + set the data in the 'additionalProperties' keyword. CliOption disallowAdditionalPropertiesIfNotPresentOpt = CliOption.newBoolean( CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT, @@ -574,6 +584,27 @@ public boolean getDiscardReadOnly() { return this.discardReadOnly; } + public void setTags(String tags){ + this.tags = tags; + } + + public void setLicenseUri(String licenseUri){ + this.licenseUri = licenseUri; + } + + public void setProjectUri(String projectUri){ + this.projectUri = projectUri; + } + + public void setReleaseNotes(String releaseNotes){ + this.releaseNotes = releaseNotes; + } + + public void setIconUri(String iconUri){ + this.iconUri = iconUri; + } + + @Override public void processOpts() { this.setLegacyDiscriminatorBehavior(false); @@ -600,6 +631,44 @@ public void processOpts() { setDiscardReadOnly(convertPropertyToBooleanAndWriteBack("discardReadOnly")); } else { additionalProperties.put("discardReadOnly", discardReadOnly); + } + + if (additionalProperties.containsKey("tags")) { + String[] entries = ((String) additionalProperties.get("tags")).split(","); + String prefix = ""; + StringBuilder tagStr = new StringBuilder("@("); + for (String entry : entries) { + tagStr.append(prefix); + prefix = ","; + tagStr.append(String.format("'%s' ",entry)); + } + tagStr.append(")"); + setTags(tagStr.toString()); + additionalProperties.put("tags",tagStr.toString()); + } + + if (additionalProperties.containsKey("releaseNotes")) { + setReleaseNotes((String) additionalProperties.get("releaseNotes")); + } else { + additionalProperties.put("releaseNotes", releaseNote); + } + + if (additionalProperties.containsKey("licenseUri")) { + setLicenseUri((String) additionalProperties.get("licenseUri")); + } else { + additionalProperties.put("licenseUri", licenseUri); + } + + if (additionalProperties.containsKey("projectUri")) { + setProjectUri((String) additionalProperties.get("projectUri")); + } else { + additionalProperties.put("projectUri", tags); + } + + if (additionalProperties.containsKey("iconUri")) { + setIconUri((String) additionalProperties.get("iconUri")); + } else { + additionalProperties.put("iconUri", iconUri); } if (StringUtils.isNotBlank(powershellGalleryUrl)) { diff --git a/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache b/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache index 31fd8a32a838..794195948588 100644 --- a/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache @@ -47,6 +47,21 @@ $Manifest = @{ Author = '{{{author}}}' CompanyName = '{{{companyName}}}' Description = '{{{packageName}}} - the PowerShell module for {{{appName}}}' + {{#tags}} + Tags = {{{.}}} + {{/tags}} + {{#projectUri}} + ProjectUri = '{{{.}}}' + {{/projectUri}} + {{#licenseUri}} + LicenseUri = '{{{.}}}' + {{/licenseUri}} + {{#iconUri}} + IconUri = '{{{.}}}' + {{/iconUri}} + {{#releaseNotes}} + ReleaseNotes = '{{{.}}}' + {{/releaseNotes}} {{#psData}} PrivateData = @{ diff --git a/samples/client/petstore/powershell/Build.ps1 b/samples/client/petstore/powershell/Build.ps1 index c6cc0b75d958..d892ed4513ea 100644 --- a/samples/client/petstore/powershell/Build.ps1 +++ b/samples/client/petstore/powershell/Build.ps1 @@ -53,6 +53,10 @@ $Manifest = @{ Author = 'OpenAPI Generator Team' CompanyName = 'openapitools.org' Description = 'PSPetstore - the PowerShell module for OpenAPI Petstore' + Tags = @('PetStore' ,'powershell' ,'sdk' ) + ProjectUri = 'https://github.com/OpenAPITools/openapi-generator' + LicenseUri = 'https://www.apache.org/licenses/LICENSE-2.0.txt' + ReleaseNotes = 'This is a sample project' ModuleVersion = '0.1.2' diff --git a/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psd1 b/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psd1 index 4322e265be2b..6329693a91fe 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psd1 +++ b/samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psd1 @@ -3,7 +3,7 @@ # # Generated by: OpenAPI Generator Team # -# Generated on: 6/4/20 +# Generated on: 30-11-2020 # @{ @@ -33,7 +33,7 @@ Copyright = '(c) OpenAPI Generator Team. All rights reserved.' Description = 'PSPetstore - the PowerShell module for OpenAPI Petstore' # Minimum version of the PowerShell engine required by this module -PowerShellVersion = '3.0' +PowerShellVersion = '5.0' # Name of the PowerShell host required by this module # PowerShellHostName = '' @@ -114,19 +114,19 @@ PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - # Tags = @() + Tags = 'PetStore', 'powershell', 'sdk' # A URL to the license for this module. - # LicenseUri = '' + LicenseUri = 'https://www.apache.org/licenses/LICENSE-2.0.txt' # A URL to the main website for this project. - # ProjectUri = '' + ProjectUri = 'https://github.com/OpenAPITools/openapi-generator' # A URL to an icon representing this module. # IconUri = '' # ReleaseNotes of this module - # ReleaseNotes = '' + ReleaseNotes = 'This is a sample project' } # End of PSData hashtable From e061b0613aa6e1b36c0a85b3d28907a347d8b018 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 30 Nov 2020 21:46:34 +0800 Subject: [PATCH 2/3] fix string.format --- .../openapitools/codegen/languages/PowerShellClientCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java index 18c3e4ff6e35..379147ccb2af 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java @@ -640,7 +640,7 @@ public void processOpts() { for (String entry : entries) { tagStr.append(prefix); prefix = ","; - tagStr.append(String.format("'%s' ",entry)); + tagStr.append(String.format(Locale.ROOT, "'%s' ",entry)); } tagStr.append(")"); setTags(tagStr.toString()); From 3b9bacc673e91c729afcb1701b74fab77eae80fd Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 1 Dec 2020 12:44:26 +0800 Subject: [PATCH 3/3] update doc --- docs/generators/powershell.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/generators/powershell.md b/docs/generators/powershell.md index fc4a2d0f4432..a7040b189fc2 100644 --- a/docs/generators/powershell.md +++ b/docs/generators/powershell.md @@ -11,10 +11,15 @@ These options may be applied as additional-properties (cli) or configOptions (pl |commonVerbs|PS common verb mappings. e.g. Delete=Remove:Patch=Update to map Delete with Remove and Patch with Update accordingly.| |null| |disallowAdditionalPropertiesIfNotPresent|Specify the behavior when the 'additionalProperties' keyword is not present in the OAS document. If false: the 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications. If true: when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.This setting is currently ignored for OAS 2.0 documents: 1) When the 'additionalProperties' keyword is not present in a 2.0 schema, additional properties are NOT allowed. 2) Boolean values of the 'additionalProperties' keyword are ignored. It's as if additional properties are NOT allowed.Note: the root cause are issues #1369 and #1371, which must be resolved in the swagger-parser project.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is automatically set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.
|true| |discardReadOnly|Set discardReadonly to true to generate the Initialize cmdlet without readonly parameters| |null| +|iconUri|A URL to an icon representing the generated PowerShell module| |null| +|licenseUri|A URL to the license for the generated PowerShell module| |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. 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| +|projectUri|A URL to the main website for this project| |null| +|releaseNotes|Release notes of the generated PowerShell module| |null| +|tags|Tags applied to the generated PowerShell module. These help with module discovery in online galleries| |null| |useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and onlye one match in oneOf's schemas) will be skipped.| |null| ## IMPORT MAPPING