[PowerShell] support default value in models (#6920)

* support default value in ps

* revert changes to the spec
This commit is contained in:
William Cheng
2020-07-13 13:41:10 +08:00
committed by GitHub
parent 1044c30293
commit 29183e0280
14 changed files with 98 additions and 73 deletions

View File

@@ -565,7 +565,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
public boolean getUseOneOfDiscriminatorLookup() {
return this.useOneOfDiscriminatorLookup;
}
public void setDiscardReadOnly(boolean discardReadOnly) {
this.discardReadOnly = discardReadOnly;
}
@@ -951,13 +951,13 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
for (CodegenProperty cp : model.allVars) {
cp.vendorExtensions.put("x-powershell-data-type", getPSDataType(cp));
if(this.discardReadOnly && !cp.isReadOnly) {
if (this.discardReadOnly && !cp.isReadOnly) {
lastWritableProperty = cp;
}
}
// Mark the last readonly false property
if(this.discardReadOnly && lastWritableProperty != null) {
if (this.discardReadOnly && lastWritableProperty != null) {
lastWritableProperty.vendorExtensions.put("x-powershell-last-writable", true);
model.allVars.set(model.allVars.indexOf(lastWritableProperty), lastWritableProperty);
}
@@ -1201,4 +1201,29 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
return escapeText(pattern);
}
@Override
public String toDefaultValue(Schema p) {
if (p.getDefault() != null) {
if (ModelUtils.isBooleanSchema(p)) {
if (Boolean.valueOf(p.getDefault().toString())) {
return "$true";
} else {
return "$false";
}
} else if (ModelUtils.isDateSchema(p)) {
LOGGER.warn("Default value for `date` not yet supported. Please open an issue with https://github.com/openapitools/openapi-generator");
} else if (ModelUtils.isDateTimeSchema(p)) {
LOGGER.warn("Default value for `datetime` not yet supported. Please open an issue with https://github.com/openapitools/openapi-generator");
} else if (ModelUtils.isNumberSchema(p)) {
return p.getDefault().toString();
} else if (ModelUtils.isIntegerSchema(p)) {
return p.getDefault().toString();
} else if (ModelUtils.isStringSchema(p)) {
return "\"" + p.getDefault() + "\"";
}
}
return null;
}
}

View File

@@ -41,7 +41,7 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} {
{{/isEnum}}
[{{vendorExtensions.x-powershell-data-type}}]
{{=<% %>=}}
${<%name%>}<%^vendorExtensions.x-powershell-last-writable%>,<%/vendorExtensions.x-powershell-last-writable%>
${<%name%>}<%#defaultValue%> = <%&.%><%/defaultValue%><%^vendorExtensions.x-powershell-last-writable%>,<%/vendorExtensions.x-powershell-last-writable%>
<%={{ }}=%>
{{/isReadOnly}}
{{/allVars}}
@@ -59,7 +59,7 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} {
{{/isEnum}}
[{{vendorExtensions.x-powershell-data-type}}]
{{=<% %>=}}
${<%name%>}<%^-last%>,<%/-last%>
${<%name%>}<%#defaultValue%> = <%&.%><%/defaultValue%><%^-last%>,<%/-last%>
<%={{ }}=%>
{{/allVars}}
{{/discardReadOnly}}

View File

@@ -3,9 +3,9 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Code** | **Int32** | | [optional] [default to null]
**Type** | **String** | | [optional] [default to null]
**Message** | **String** | | [optional] [default to null]
**Code** | **Int32** | | [optional]
**Type** | **String** | | [optional]
**Message** | **String** | | [optional]
## Examples

View File

@@ -3,8 +3,8 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **Int64** | | [optional] [default to null]
**Name** | **String** | | [optional] [default to null]
**Id** | **Int64** | | [optional]
**Name** | **String** | | [optional]
## Examples

View File

@@ -3,8 +3,8 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Name** | **String** | Updated name of the pet | [optional] [default to null]
**Status** | **String** | Updated status of the pet | [optional] [default to null]
**Name** | **String** | Updated name of the pet | [optional]
**Status** | **String** | Updated status of the pet | [optional]
## Examples

View File

@@ -3,8 +3,8 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**AdditionalMetadata** | **String** | Additional data to pass to server | [optional] [default to null]
**File** | **System.IO.FileInfo** | file to upload | [optional] [default to null]
**AdditionalMetadata** | **String** | Additional data to pass to server | [optional]
**File** | **System.IO.FileInfo** | file to upload | [optional]
## Examples

View File

@@ -3,12 +3,12 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **Int64** | | [optional] [default to null]
**PetId** | **Int64** | | [optional] [default to null]
**Quantity** | **Int32** | | [optional] [default to null]
**ShipDate** | **System.DateTime** | | [optional] [default to null]
**Status** | **String** | Order Status | [optional] [default to null]
**Complete** | **Boolean** | | [optional] [default to false]
**Id** | **Int64** | | [optional]
**PetId** | **Int64** | | [optional]
**Quantity** | **Int32** | | [optional]
**ShipDate** | **System.DateTime** | | [optional]
**Status** | **String** | Order Status | [optional]
**Complete** | **Boolean** | | [optional] [default to $false]
## Examples

View File

@@ -77,8 +77,8 @@ $Configuration = Get-PSPetstoreConfiguration
# Configure OAuth2 access token for authorization: petstore_auth
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
$PetId = 987 # Int64 | Pet id to delete (default to null)
$ApiKey = "ApiKey_example" # String | (optional) (default to null)
$PetId = 987 # Int64 | Pet id to delete
$ApiKey = "ApiKey_example" # String | (optional)
# Deletes a pet
try {
@@ -93,8 +93,8 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**PetId** | **Int64**| Pet id to delete | [default to null]
**ApiKey** | **String**| | [optional] [default to null]
**PetId** | **Int64**| Pet id to delete |
**ApiKey** | **String**| | [optional]
### Return type
@@ -128,7 +128,7 @@ $Configuration = Get-PSPetstoreConfiguration
# Configure OAuth2 access token for authorization: petstore_auth
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
$Status = @("Status_example") # String[] | Status values that need to be considered for filter (default to null)
$Status = @("Status_example") # String[] | Status values that need to be considered for filter
# Finds Pets by status
try {
@@ -143,7 +143,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**Status** | [**String[]**](String.md)| Status values that need to be considered for filter | [default to null]
**Status** | [**String[]**](String.md)| Status values that need to be considered for filter |
### Return type
@@ -177,7 +177,7 @@ $Configuration = Get-PSPetstoreConfiguration
# Configure OAuth2 access token for authorization: petstore_auth
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
$Tags = @("Inner_example") # String[] | Tags to filter by (default to null)
$Tags = @("Inner_example") # String[] | Tags to filter by
# Finds Pets by tags
try {
@@ -192,7 +192,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**Tags** | [**String[]**](String.md)| Tags to filter by | [default to null]
**Tags** | [**String[]**](String.md)| Tags to filter by |
### Return type
@@ -228,7 +228,7 @@ $Configuration["ApiKey"]["api_key"] = "YOUR_API_KEY"
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
#$Configuration["ApiKeyPrefix"]["api_key"] = "Bearer"
$PetId = 987 # Int64 | ID of pet to return (default to null)
$PetId = 987 # Int64 | ID of pet to return
# Find pet by ID
try {
@@ -243,7 +243,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**PetId** | **Int64**| ID of pet to return | [default to null]
**PetId** | **Int64**| ID of pet to return |
### Return type
@@ -324,9 +324,9 @@ $Configuration = Get-PSPetstoreConfiguration
# Configure OAuth2 access token for authorization: petstore_auth
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
$PetId = 987 # Int64 | ID of pet that needs to be updated (default to null)
$Name = "Name_example" # String | Updated name of the pet (optional) (default to null)
$Status = "Status_example" # String | Updated status of the pet (optional) (default to null)
$PetId = 987 # Int64 | ID of pet that needs to be updated
$Name = "Name_example" # String | Updated name of the pet (optional)
$Status = "Status_example" # String | Updated status of the pet (optional)
# Updates a pet in the store with form data
try {
@@ -341,9 +341,9 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**PetId** | **Int64**| ID of pet that needs to be updated | [default to null]
**Name** | **String**| Updated name of the pet | [optional] [default to null]
**Status** | **String**| Updated status of the pet | [optional] [default to null]
**PetId** | **Int64**| ID of pet that needs to be updated |
**Name** | **String**| Updated name of the pet | [optional]
**Status** | **String**| Updated status of the pet | [optional]
### Return type
@@ -377,9 +377,9 @@ $Configuration = Get-PSPetstoreConfiguration
# Configure OAuth2 access token for authorization: petstore_auth
$Configuration["AccessToken"] = "YOUR_ACCESS_TOKEN";
$PetId = 987 # Int64 | ID of pet to update (default to null)
$AdditionalMetadata = "AdditionalMetadata_example" # String | Additional data to pass to server (optional) (default to null)
$File = 987 # System.IO.FileInfo | file to upload (optional) (default to null)
$PetId = 987 # Int64 | ID of pet to update
$AdditionalMetadata = "AdditionalMetadata_example" # String | Additional data to pass to server (optional)
$File = 987 # System.IO.FileInfo | file to upload (optional)
# uploads an image
try {
@@ -394,9 +394,9 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**PetId** | **Int64**| ID of pet to update | [default to null]
**AdditionalMetadata** | **String**| Additional data to pass to server | [optional] [default to null]
**File** | **System.IO.FileInfo****System.IO.FileInfo**| file to upload | [optional] [default to null]
**PetId** | **Int64**| ID of pet to update |
**AdditionalMetadata** | **String**| Additional data to pass to server | [optional]
**File** | **System.IO.FileInfo****System.IO.FileInfo**| file to upload | [optional]
### Return type

View File

@@ -23,7 +23,7 @@ For valid response try integer IDs with value < 1000. Anything above 1000 or non
```powershell
Import-Module -Name PSPetstore
$OrderId = "OrderId_example" # String | ID of the order that needs to be deleted (default to null)
$OrderId = "OrderId_example" # String | ID of the order that needs to be deleted
# Delete purchase order by ID
try {
@@ -38,7 +38,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**OrderId** | **String**| ID of the order that needs to be deleted | [default to null]
**OrderId** | **String**| ID of the order that needs to be deleted |
### Return type
@@ -114,7 +114,7 @@ For valid response try integer IDs with value <= 5 or > 10. Other values will ge
```powershell
Import-Module -Name PSPetstore
$OrderId = 987 # Int64 | ID of pet that needs to be fetched (default to null)
$OrderId = 987 # Int64 | ID of pet that needs to be fetched
# Find purchase order by ID
try {
@@ -129,7 +129,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**OrderId** | **Int64**| ID of pet that needs to be fetched | [default to null]
**OrderId** | **Int64**| ID of pet that needs to be fetched |
### Return type

View File

@@ -182,7 +182,7 @@ $Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
$Username = "Username_example" # String | The name that needs to be deleted (default to null)
$Username = "Username_example" # String | The name that needs to be deleted
# Delete user
try {
@@ -197,7 +197,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**Username** | **String**| The name that needs to be deleted | [default to null]
**Username** | **String**| The name that needs to be deleted |
### Return type
@@ -225,7 +225,7 @@ Get user by user name
```powershell
Import-Module -Name PSPetstore
$Username = "Username_example" # String | The name that needs to be fetched. Use user1 for testing. (default to null)
$Username = "Username_example" # String | The name that needs to be fetched. Use user1 for testing.
# Get user by user name
try {
@@ -240,7 +240,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**Username** | **String**| The name that needs to be fetched. Use user1 for testing. | [default to null]
**Username** | **String**| The name that needs to be fetched. Use user1 for testing. |
### Return type
@@ -269,8 +269,8 @@ Logs user into the system
```powershell
Import-Module -Name PSPetstore
$Username = "Username_example" # String | The user name for login (default to null)
$Password = "Password_example" # String | The password for login in clear text (default to null)
$Username = "Username_example" # String | The user name for login
$Password = "Password_example" # String | The password for login in clear text
# Logs user into the system
try {
@@ -285,8 +285,8 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**Username** | **String**| The user name for login | [default to null]
**Password** | **String**| The password for login in clear text | [default to null]
**Username** | **String**| The user name for login |
**Password** | **String**| The password for login in clear text |
### Return type
@@ -367,7 +367,7 @@ $Configuration["ApiKey"]["AUTH_KEY"] = "YOUR_API_KEY"
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
#$Configuration["ApiKeyPrefix"]["AUTH_KEY"] = "Bearer"
$Username = "Username_example" # String | name that need to be deleted (default to null)
$Username = "Username_example" # String | name that need to be deleted
$User = # User | Updated user object
# Updated user
@@ -383,7 +383,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**Username** | **String**| name that need to be deleted | [default to null]
**Username** | **String**| name that need to be deleted |
**User** | [**User**](User.md)| Updated user object |
### Return type

View File

@@ -3,12 +3,12 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **Int64** | | [optional] [default to null]
**Category** | [**Category**](Category.md) | | [optional] [default to null]
**Name** | **String** | | [default to null]
**PhotoUrls** | **String[]** | | [default to null]
**Tags** | [**Tag[]**](Tag.md) | | [optional] [default to null]
**Status** | **String** | pet status in the store | [optional] [default to null]
**Id** | **Int64** | | [optional]
**Category** | [**Category**](Category.md) | | [optional]
**Name** | **String** | |
**PhotoUrls** | **String[]** | |
**Tags** | [**Tag[]**](Tag.md) | | [optional]
**Status** | **String** | pet status in the store | [optional]
## Examples

View File

@@ -3,8 +3,8 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **Int64** | | [optional] [default to null]
**Name** | **String** | | [optional] [default to null]
**Id** | **Int64** | | [optional]
**Name** | **String** | | [optional]
## Examples

View File

@@ -3,14 +3,14 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **Int64** | | [optional] [default to null]
**Username** | **String** | | [optional] [default to null]
**FirstName** | **String** | | [optional] [default to null]
**LastName** | **String** | | [optional] [default to null]
**Email** | **String** | | [optional] [default to null]
**Password** | **String** | | [optional] [default to null]
**Phone** | **String** | | [optional] [default to null]
**UserStatus** | **Int32** | User Status | [optional] [default to null]
**Id** | **Int64** | | [optional]
**Username** | **String** | | [optional]
**FirstName** | **String** | | [optional]
**LastName** | **String** | | [optional]
**Email** | **String** | | [optional]
**Password** | **String** | | [optional]
**Phone** | **String** | | [optional]
**UserStatus** | **Int32** | User Status | [optional]
## Examples

View File

@@ -52,7 +52,7 @@ function Initialize-PSOrder {
${Status},
[Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)]
[System.Nullable[Boolean]]
${Complete}
${Complete} = $false
)
Process {