Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/configs/powershell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
5 changes: 5 additions & 0 deletions docs/generators/powershell.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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(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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{
Expand Down
4 changes: 4 additions & 0 deletions samples/client/petstore/powershell/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: OpenAPI Generator Team
#
# Generated on: 6/4/20
# Generated on: 30-11-2020
#

@{
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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

Expand Down