[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 <wing328hk@gmail.com>
This commit is contained in:
Ghufran Zahidi
2020-12-01 14:22:12 +05:30
committed by GitHub
parent e040a5fdde
commit 64ade2ce8f
6 changed files with 103 additions and 6 deletions

View File

@@ -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'

View File

@@ -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.|<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|
|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

View File

@@ -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 class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
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 class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
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 class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
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(Locale.ROOT, "'%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)) {

View File

@@ -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 = @{

View File

@@ -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'

View File

@@ -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