forked from loafle/openapi-generator-original
[PowerShell] discard readonly properties in Initialize cmdlets (#6754)
* ValidatePattern having double quote(") throws exception on running Build.ps1 * fix tab with space * [powershell-experimental] : http signature auth * fix the tab issue * merge cnflict fix for powershell experimental * Htpp signing : added support for ecdsa * Update modules/openapi-generator/src/main/resources/powershell/configuration.mustache Co-authored-by: Sebastien Rosset <serosset@cisco.com> * Update modules/openapi-generator/src/main/resources/powershell/configuration.mustache Co-authored-by: Sebastien Rosset <serosset@cisco.com> * Update modules/openapi-generator/src/main/resources/powershell/configuration.mustache Co-authored-by: Sebastien Rosset <serosset@cisco.com> * Update modules/openapi-generator/src/main/resources/powershell/configuration.mustache Co-authored-by: Sebastien Rosset <serosset@cisco.com> * Update modules/openapi-generator/src/main/resources/powershell/configuration.mustache Co-authored-by: Sebastien Rosset <serosset@cisco.com> * HttpSigningHeader accepts any header available in request to calculate the signature. * Update modules/openapi-generator/src/main/resources/powershell/http_signature_auth.mustache Co-authored-by: Sebastien Rosset <serosset@cisco.com> * Incorporated the review comments * addressed the merge conflict * discard readonly property in initialize cmdlets * update doc * update powershell sample Co-authored-by: Ghufran Zahidi <gzahidi@cisco.com> Co-authored-by: Sebastien Rosset <serosset@cisco.com> Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
parent
6b877efe1f
commit
13fe079901
@ -7,6 +7,7 @@ sidebar_label: powershell
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|apiNamePrefix|Prefix that will be appended to all PS objects. Default: empty string. e.g. Pet => PSPet.| |null|
|
||||
|commonVerbs|PS common verb mappings. e.g. Delete=Remove:Patch=Update to map Delete with Remove and Patch with Update accordingly.| |null|
|
||||
|discardReadOnly|Set discardReadonly to true to generate the Initialize cmdlet without readonly parameters| |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|
|
||||
|
@ -54,6 +54,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
protected Map<String, String> commonVerbs; // verbs not in the official ps verb list but can be mapped to one of the verbs
|
||||
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
|
||||
|
||||
/**
|
||||
* Constructs an instance of `PowerShellClientCodegen`.
|
||||
@ -499,6 +500,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_NAME_PREFIX, "Prefix that will be appended to all PS objects. Default: empty string. e.g. Pet => PSPet."));
|
||||
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"));
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
@ -543,6 +545,14 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return this.useOneOfDiscriminatorLookup;
|
||||
}
|
||||
|
||||
public void setDiscardReadOnly(boolean discardReadOnly) {
|
||||
this.discardReadOnly = discardReadOnly;
|
||||
}
|
||||
|
||||
public boolean getDiscardReadOnly() {
|
||||
return this.discardReadOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
this.setLegacyDiscriminatorBehavior(false);
|
||||
@ -565,6 +575,12 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
additionalProperties.put(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, useOneOfDiscriminatorLookup);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey("discardReadOnly")) {
|
||||
setDiscardReadOnly(convertPropertyToBooleanAndWriteBack("discardReadOnly"));
|
||||
} else {
|
||||
additionalProperties.put("discardReadOnly", discardReadOnly);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(powershellGalleryUrl)) {
|
||||
// get the last segment of the URL
|
||||
// e.g. https://www.powershellgallery.com/packages/PSTwitter => PSTwitter
|
||||
@ -905,9 +921,19 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> _model = (Map<String, Object>) _mo;
|
||||
CodegenModel model = (CodegenModel) _model.get("model");
|
||||
CodegenProperty lastWritableProperty = null;
|
||||
|
||||
for (CodegenProperty cp : model.allVars) {
|
||||
cp.vendorExtensions.put("x-powershell-data-type", getPSDataType(cp));
|
||||
if(this.discardReadOnly && !cp.isReadOnly) {
|
||||
lastWritableProperty = cp;
|
||||
}
|
||||
}
|
||||
|
||||
// Mark the last readonly false property
|
||||
if(this.discardReadOnly && lastWritableProperty != null) {
|
||||
lastWritableProperty.vendorExtensions.put("x-lastWritable", true);
|
||||
model.allVars.set(model.allVars.indexOf(lastWritableProperty), lastWritableProperty);
|
||||
}
|
||||
|
||||
// if oneOf contains "null" type
|
||||
|
@ -8,9 +8,16 @@
|
||||
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
|
||||
|
||||
{{#allVars}}
|
||||
{{^discardReadOnly}}
|
||||
.PARAMETER {{{name}}}
|
||||
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
|
||||
|
||||
{{/discardReadOnly}}
|
||||
{{#discardReadOnly}}
|
||||
{{^isReadOnly}}
|
||||
.PARAMETER {{{name}}}
|
||||
{{#description}}{{{description}}}{{/description}}{{^description}}No description available.{{/description}}
|
||||
{{/isReadOnly}}
|
||||
{{/discardReadOnly}}
|
||||
{{/allVars}}
|
||||
.OUTPUTS
|
||||
|
||||
@ -20,6 +27,26 @@
|
||||
function Initialize-{{{apiNamePrefix}}}{{{classname}}} {
|
||||
[CmdletBinding()]
|
||||
Param (
|
||||
{{#discardReadOnly}}
|
||||
{{#allVars}}
|
||||
{{^isReadOnly}}
|
||||
[Parameter(ValueFromPipelineByPropertyName = $true)]
|
||||
{{#pattern}}
|
||||
[ValidatePattern("{{{.}}}")]
|
||||
{{/pattern}}
|
||||
{{#isEnum}}
|
||||
{{#allowableValues}}
|
||||
[ValidateSet({{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}})]
|
||||
{{/allowableValues}}
|
||||
{{/isEnum}}
|
||||
[{{vendorExtensions.x-powershell-data-type}}]
|
||||
{{=<% %>=}}
|
||||
${<%name%>}<%^vendorExtensions.x-lastWritable%>,<%/vendorExtensions.x-lastWritable%>
|
||||
<%={{ }}=%>
|
||||
{{/isReadOnly}}
|
||||
{{/allVars}}
|
||||
{{/discardReadOnly}}
|
||||
{{^discardReadOnly}}
|
||||
{{#allVars}}
|
||||
[Parameter(Position = {{vendorExtensions.x-index}}, ValueFromPipelineByPropertyName = $true)]
|
||||
{{#pattern}}
|
||||
@ -35,12 +62,14 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} {
|
||||
${<%name%>}<%^-last%>,<%/-last%>
|
||||
<%={{ }}=%>
|
||||
{{/allVars}}
|
||||
{{/discardReadOnly}}
|
||||
)
|
||||
|
||||
Process {
|
||||
'Creating PSCustomObject: {{{packageName}}} => {{{apiNamePrefix}}}{{{classname}}}' | Write-Debug
|
||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||
|
||||
{{^discardReadOnly}}
|
||||
{{#vars}}
|
||||
{{^isNullable}}
|
||||
{{#required}}
|
||||
@ -89,6 +118,7 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} {
|
||||
{{/minItems}}
|
||||
{{/hasValidation}}
|
||||
{{/vars}}
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
{{=<< >>=}}
|
||||
<<#allVars>>
|
||||
@ -97,6 +127,70 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} {
|
||||
<<={{ }}=>>
|
||||
}
|
||||
|
||||
{{/discardReadOnly}}
|
||||
{{#discardReadOnly}}
|
||||
{{#vars}}
|
||||
{{^isReadOnly}}
|
||||
{{^isNullable}}
|
||||
{{#required}}
|
||||
if (!${{{name}}}) {
|
||||
throw "invalid value for '{{{name}}}', '{{{name}}}' cannot be null."
|
||||
}
|
||||
|
||||
{{/required}}
|
||||
{{/isNullable}}
|
||||
{{#hasValidation}}
|
||||
{{#maxLength}}
|
||||
if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -gt {{{maxLength}}}) {
|
||||
throw "invalid value for '{{{name}}}', the character length must be smaller than or equal to {{{maxLength}}}."
|
||||
}
|
||||
|
||||
{{/maxLength}}
|
||||
{{#minLength}}
|
||||
if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -lt {{{minLength}}}) {
|
||||
throw "invalid value for '{{{name}}}', the character length must be great than or equal to {{{minLength}}}."
|
||||
}
|
||||
|
||||
{{/minLength}}
|
||||
{{#maximum}}
|
||||
if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}} {{#exclusiveMaximum}}-ge{{/exclusiveMaximum}}{{^exclusiveMaximum}}-gt{{/exclusiveMaximum}} {{{maximum}}}) {
|
||||
throw "invalid value for '{{{name}}}', must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}."
|
||||
}
|
||||
|
||||
{{/maximum}}
|
||||
{{#minimum}}
|
||||
if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}} {{#exclusiveMinimum}}-le{{/exclusiveMinimum}}{{^exclusiveMinimum}}-lt{{/exclusiveMinimum}} {{{minimum}}}) {
|
||||
throw "invalid value for '{{{name}}}', must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}."
|
||||
}
|
||||
|
||||
{{/minimum}}
|
||||
{{#maxItems}}
|
||||
if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -gt {{{maxItems}}}) {
|
||||
throw "invalid value for '{{{name}}}', number of items must be less than or equal to {{{maxItems}}}."
|
||||
}
|
||||
|
||||
{{/maxItems}}
|
||||
{{#minItems}}
|
||||
if ({{^required}}!${{{name}}} -and {{/required}}${{{name}}}.length -lt {{{minItems}}}) {
|
||||
throw "invalid value for '{{{name}}}', number of items must be greater than or equal to {{{minItems}}}."
|
||||
}
|
||||
|
||||
{{/minItems}}
|
||||
{{/hasValidation}}
|
||||
{{/isReadOnly}}
|
||||
{{/vars}}
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
{{=<< >>=}}
|
||||
<<#allVars>>
|
||||
<<^isReadOnly>>
|
||||
"<<baseName>>" = ${<<name>>}
|
||||
<</isReadOnly>>
|
||||
<</allVars>>
|
||||
<<={{ }}=>>
|
||||
}
|
||||
{{/discardReadOnly}}
|
||||
|
||||
return $PSO
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,10 @@ Describes the result of uploading an image resource
|
||||
|
||||
.PARAMETER Code
|
||||
No description available.
|
||||
|
||||
.PARAMETER Type
|
||||
No description available.
|
||||
|
||||
.PARAMETER Message
|
||||
No description available.
|
||||
|
||||
.OUTPUTS
|
||||
|
||||
ApiResponse<PSCustomObject>
|
||||
@ -46,12 +43,14 @@ function Initialize-PSApiResponse {
|
||||
'Creating PSCustomObject: PSPetstore => PSApiResponse' | Write-Debug
|
||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
"code" = ${Code}
|
||||
"type" = ${Type}
|
||||
"message" = ${Message}
|
||||
}
|
||||
|
||||
|
||||
return $PSO
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,8 @@ A category for a pet
|
||||
|
||||
.PARAMETER Id
|
||||
No description available.
|
||||
|
||||
.PARAMETER Name
|
||||
No description available.
|
||||
|
||||
.OUTPUTS
|
||||
|
||||
Category<PSCustomObject>
|
||||
@ -41,11 +39,13 @@ function Initialize-PSCategory {
|
||||
'Creating PSCustomObject: PSPetstore => PSCategory' | Write-Debug
|
||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
"id" = ${Id}
|
||||
"name" = ${Name}
|
||||
}
|
||||
|
||||
|
||||
return $PSO
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,8 @@ No description available.
|
||||
|
||||
.PARAMETER Name
|
||||
Updated name of the pet
|
||||
|
||||
.PARAMETER Status
|
||||
Updated status of the pet
|
||||
|
||||
.OUTPUTS
|
||||
|
||||
InlineObject<PSCustomObject>
|
||||
@ -40,11 +38,13 @@ function Initialize-PSInlineObject {
|
||||
'Creating PSCustomObject: PSPetstore => PSInlineObject' | Write-Debug
|
||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
"name" = ${Name}
|
||||
"status" = ${Status}
|
||||
}
|
||||
|
||||
|
||||
return $PSO
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,8 @@ No description available.
|
||||
|
||||
.PARAMETER AdditionalMetadata
|
||||
Additional data to pass to server
|
||||
|
||||
.PARAMETER File
|
||||
file to upload
|
||||
|
||||
.OUTPUTS
|
||||
|
||||
InlineObject1<PSCustomObject>
|
||||
@ -40,11 +38,13 @@ function Initialize-PSInlineObject1 {
|
||||
'Creating PSCustomObject: PSPetstore => PSInlineObject1' | Write-Debug
|
||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
"additionalMetadata" = ${AdditionalMetadata}
|
||||
"file" = ${File}
|
||||
}
|
||||
|
||||
|
||||
return $PSO
|
||||
}
|
||||
}
|
||||
|
@ -16,22 +16,16 @@ An order for a pets from the pet store
|
||||
|
||||
.PARAMETER Id
|
||||
No description available.
|
||||
|
||||
.PARAMETER PetId
|
||||
No description available.
|
||||
|
||||
.PARAMETER Quantity
|
||||
No description available.
|
||||
|
||||
.PARAMETER ShipDate
|
||||
No description available.
|
||||
|
||||
.PARAMETER Status
|
||||
Order Status
|
||||
|
||||
.PARAMETER Complete
|
||||
No description available.
|
||||
|
||||
.OUTPUTS
|
||||
|
||||
Order<PSCustomObject>
|
||||
@ -65,6 +59,7 @@ function Initialize-PSOrder {
|
||||
'Creating PSCustomObject: PSPetstore => PSOrder' | Write-Debug
|
||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
"id" = ${Id}
|
||||
"petId" = ${PetId}
|
||||
@ -74,6 +69,7 @@ function Initialize-PSOrder {
|
||||
"complete" = ${Complete}
|
||||
}
|
||||
|
||||
|
||||
return $PSO
|
||||
}
|
||||
}
|
||||
|
@ -16,22 +16,16 @@ A pet for sale in the pet store
|
||||
|
||||
.PARAMETER Id
|
||||
No description available.
|
||||
|
||||
.PARAMETER Category
|
||||
No description available.
|
||||
|
||||
.PARAMETER Name
|
||||
No description available.
|
||||
|
||||
.PARAMETER PhotoUrls
|
||||
No description available.
|
||||
|
||||
.PARAMETER Tags
|
||||
No description available.
|
||||
|
||||
.PARAMETER Status
|
||||
pet status in the store
|
||||
|
||||
.OUTPUTS
|
||||
|
||||
Pet<PSCustomObject>
|
||||
@ -73,6 +67,7 @@ function Initialize-PSPet {
|
||||
throw "invalid value for 'PhotoUrls', 'PhotoUrls' cannot be null."
|
||||
}
|
||||
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
"id" = ${Id}
|
||||
"category" = ${Category}
|
||||
@ -82,6 +77,7 @@ function Initialize-PSPet {
|
||||
"status" = ${Status}
|
||||
}
|
||||
|
||||
|
||||
return $PSO
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,8 @@ A tag for a pet
|
||||
|
||||
.PARAMETER Id
|
||||
No description available.
|
||||
|
||||
.PARAMETER Name
|
||||
No description available.
|
||||
|
||||
.OUTPUTS
|
||||
|
||||
Tag<PSCustomObject>
|
||||
@ -40,11 +38,13 @@ function Initialize-PSTag {
|
||||
'Creating PSCustomObject: PSPetstore => PSTag' | Write-Debug
|
||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
"id" = ${Id}
|
||||
"name" = ${Name}
|
||||
}
|
||||
|
||||
|
||||
return $PSO
|
||||
}
|
||||
}
|
||||
|
@ -16,28 +16,20 @@ A User who is purchasing from the pet store
|
||||
|
||||
.PARAMETER Id
|
||||
No description available.
|
||||
|
||||
.PARAMETER Username
|
||||
No description available.
|
||||
|
||||
.PARAMETER FirstName
|
||||
No description available.
|
||||
|
||||
.PARAMETER LastName
|
||||
No description available.
|
||||
|
||||
.PARAMETER Email
|
||||
No description available.
|
||||
|
||||
.PARAMETER Password
|
||||
No description available.
|
||||
|
||||
.PARAMETER Phone
|
||||
No description available.
|
||||
|
||||
.PARAMETER UserStatus
|
||||
User Status
|
||||
|
||||
.OUTPUTS
|
||||
|
||||
User<PSCustomObject>
|
||||
@ -77,6 +69,7 @@ function Initialize-PSUser {
|
||||
'Creating PSCustomObject: PSPetstore => PSUser' | Write-Debug
|
||||
$PSBoundParameters | Out-DebugParameter | Write-Debug
|
||||
|
||||
|
||||
$PSO = [PSCustomObject]@{
|
||||
"id" = ${Id}
|
||||
"username" = ${Username}
|
||||
@ -88,6 +81,7 @@ function Initialize-PSUser {
|
||||
"userStatus" = ${UserStatus}
|
||||
}
|
||||
|
||||
|
||||
return $PSO
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user