Skip to content

Commit 64ade2c

Browse files
Ghufzwing328
andauthored
[powershell] Implemented the psdata property for module manifest file (#8048)
* Implemented the psdata property for module manifest file (Tags, LicenseUri, ProjectUri, IconUri, ReleaseNotes) * fix string.format * update doc Co-authored-by: William Cheng <[email protected]>
1 parent e040a5f commit 64ade2c

File tree

6 files changed

+103
-6
lines changed

6 files changed

+103
-6
lines changed

bin/configs/powershell.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ additionalProperties:
1010
powershellGalleryUrl: https://www.powershellgallery.com/packages/PSPetstore
1111
apiNamePrefix: PS
1212
powershellVersion: "5.0"
13+
licenseUri: https://www.apache.org/licenses/LICENSE-2.0.txt
14+
projectUri: https://github.com/OpenAPITools/openapi-generator
15+
releaseNotes: 'This is a sample project'
16+
tags: 'PetStore,powershell,sdk'

docs/generators/powershell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1111
|commonVerbs|PS common verb mappings. e.g. Delete=Remove:Patch=Update to map Delete with Remove and Patch with Update accordingly.| |null|
1212
|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.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>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.</dd></dl>|true|
1313
|discardReadOnly|Set discardReadonly to true to generate the Initialize cmdlet without readonly parameters| |null|
14+
|iconUri|A URL to an icon representing the generated PowerShell module| |null|
15+
|licenseUri|A URL to the license for the generated PowerShell module| |null|
1416
|packageGuid|GUID for PowerShell module (e.g. a27b908d-2a20-467f-bc32-af6f3a654ac5). A random GUID will be generated by default.| |null|
1517
|packageName|Client package name (e.g. PSTwitter).| |PSOpenAPITools|
1618
|packageVersion|Package version (e.g. 0.1.2).| |0.1.2|
1719
|powershellGalleryUrl|URL to the module in PowerShell Gallery (e.g. https://www.powershellgallery.com/packages/PSTwitter/).| |null|
20+
|projectUri|A URL to the main website for this project| |null|
21+
|releaseNotes|Release notes of the generated PowerShell module| |null|
22+
|tags|Tags applied to the generated PowerShell module. These help with module discovery in online galleries| |null|
1823
|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|
1924

2025
## IMPORT MAPPING

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
5555
protected HashSet methodNames; // store a list of method names to detect duplicates
5656
protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
5757
protected boolean discardReadOnly = false; // Discard the readonly property in initialize cmdlet
58+
protected String projectUri;
59+
protected String licenseUri;
60+
protected String releaseNotes;
61+
protected String tags;
62+
protected String iconUri;
5863

5964
/**
6065
* Constructs an instance of `PowerShellClientCodegen`.
@@ -501,6 +506,11 @@ public PowerShellClientCodegen() {
501506
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."));
502507
cliOptions.add(new CliOption(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC));
503508
cliOptions.add(new CliOption("discardReadOnly", "Set discardReadonly to true to generate the Initialize cmdlet without readonly parameters"));
509+
cliOptions.add(new CliOption("tags","Tags applied to the generated PowerShell module. These help with module discovery in online galleries"));
510+
cliOptions.add(new CliOption("projectUri","A URL to the main website for this project"));
511+
cliOptions.add(new CliOption("licenseUri","A URL to the license for the generated PowerShell module"));
512+
cliOptions.add(new CliOption("iconUri","A URL to an icon representing the generated PowerShell module"));
513+
cliOptions.add(new CliOption("releaseNotes","Release notes of the generated PowerShell module"));
504514
// option to change how we process + set the data in the 'additionalProperties' keyword.
505515
CliOption disallowAdditionalPropertiesIfNotPresentOpt = CliOption.newBoolean(
506516
CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT,
@@ -574,6 +584,27 @@ public boolean getDiscardReadOnly() {
574584
return this.discardReadOnly;
575585
}
576586

587+
public void setTags(String tags){
588+
this.tags = tags;
589+
}
590+
591+
public void setLicenseUri(String licenseUri){
592+
this.licenseUri = licenseUri;
593+
}
594+
595+
public void setProjectUri(String projectUri){
596+
this.projectUri = projectUri;
597+
}
598+
599+
public void setReleaseNotes(String releaseNotes){
600+
this.releaseNotes = releaseNotes;
601+
}
602+
603+
public void setIconUri(String iconUri){
604+
this.iconUri = iconUri;
605+
}
606+
607+
577608
@Override
578609
public void processOpts() {
579610
this.setLegacyDiscriminatorBehavior(false);
@@ -600,6 +631,44 @@ public void processOpts() {
600631
setDiscardReadOnly(convertPropertyToBooleanAndWriteBack("discardReadOnly"));
601632
} else {
602633
additionalProperties.put("discardReadOnly", discardReadOnly);
634+
}
635+
636+
if (additionalProperties.containsKey("tags")) {
637+
String[] entries = ((String) additionalProperties.get("tags")).split(",");
638+
String prefix = "";
639+
StringBuilder tagStr = new StringBuilder("@(");
640+
for (String entry : entries) {
641+
tagStr.append(prefix);
642+
prefix = ",";
643+
tagStr.append(String.format(Locale.ROOT, "'%s' ",entry));
644+
}
645+
tagStr.append(")");
646+
setTags(tagStr.toString());
647+
additionalProperties.put("tags",tagStr.toString());
648+
}
649+
650+
if (additionalProperties.containsKey("releaseNotes")) {
651+
setReleaseNotes((String) additionalProperties.get("releaseNotes"));
652+
} else {
653+
additionalProperties.put("releaseNotes", releaseNote);
654+
}
655+
656+
if (additionalProperties.containsKey("licenseUri")) {
657+
setLicenseUri((String) additionalProperties.get("licenseUri"));
658+
} else {
659+
additionalProperties.put("licenseUri", licenseUri);
660+
}
661+
662+
if (additionalProperties.containsKey("projectUri")) {
663+
setProjectUri((String) additionalProperties.get("projectUri"));
664+
} else {
665+
additionalProperties.put("projectUri", tags);
666+
}
667+
668+
if (additionalProperties.containsKey("iconUri")) {
669+
setIconUri((String) additionalProperties.get("iconUri"));
670+
} else {
671+
additionalProperties.put("iconUri", iconUri);
603672
}
604673

605674
if (StringUtils.isNotBlank(powershellGalleryUrl)) {

modules/openapi-generator/src/main/resources/powershell/Build.ps1.mustache

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ $Manifest = @{
4747
Author = '{{{author}}}'
4848
CompanyName = '{{{companyName}}}'
4949
Description = '{{{packageName}}} - the PowerShell module for {{{appName}}}'
50+
{{#tags}}
51+
Tags = {{{.}}}
52+
{{/tags}}
53+
{{#projectUri}}
54+
ProjectUri = '{{{.}}}'
55+
{{/projectUri}}
56+
{{#licenseUri}}
57+
LicenseUri = '{{{.}}}'
58+
{{/licenseUri}}
59+
{{#iconUri}}
60+
IconUri = '{{{.}}}'
61+
{{/iconUri}}
62+
{{#releaseNotes}}
63+
ReleaseNotes = '{{{.}}}'
64+
{{/releaseNotes}}
5065

5166
{{#psData}}
5267
PrivateData = @{

samples/client/petstore/powershell/Build.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ $Manifest = @{
5353
Author = 'OpenAPI Generator Team'
5454
CompanyName = 'openapitools.org'
5555
Description = 'PSPetstore - the PowerShell module for OpenAPI Petstore'
56+
Tags = @('PetStore' ,'powershell' ,'sdk' )
57+
ProjectUri = 'https://github.com/OpenAPITools/openapi-generator'
58+
LicenseUri = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
59+
ReleaseNotes = 'This is a sample project'
5660

5761
ModuleVersion = '0.1.2'
5862

samples/client/petstore/powershell/src/PSPetstore/PSPetstore.psd1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: OpenAPI Generator Team
55
#
6-
# Generated on: 6/4/20
6+
# Generated on: 30-11-2020
77
#
88

99
@{
@@ -33,7 +33,7 @@ Copyright = '(c) OpenAPI Generator Team. All rights reserved.'
3333
Description = 'PSPetstore - the PowerShell module for OpenAPI Petstore'
3434

3535
# Minimum version of the PowerShell engine required by this module
36-
PowerShellVersion = '3.0'
36+
PowerShellVersion = '5.0'
3737

3838
# Name of the PowerShell host required by this module
3939
# PowerShellHostName = ''
@@ -114,19 +114,19 @@ PrivateData = @{
114114
PSData = @{
115115

116116
# Tags applied to this module. These help with module discovery in online galleries.
117-
# Tags = @()
117+
Tags = 'PetStore', 'powershell', 'sdk'
118118

119119
# A URL to the license for this module.
120-
# LicenseUri = ''
120+
LicenseUri = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
121121

122122
# A URL to the main website for this project.
123-
# ProjectUri = ''
123+
ProjectUri = 'https://github.com/OpenAPITools/openapi-generator'
124124

125125
# A URL to an icon representing this module.
126126
# IconUri = ''
127127

128128
# ReleaseNotes of this module
129-
# ReleaseNotes = ''
129+
ReleaseNotes = 'This is a sample project'
130130

131131
} # End of PSData hashtable
132132

0 commit comments

Comments
 (0)