Skip to content

Commit

Permalink
[php-nextgen] Fix default value for array of items (#16654)
Browse files Browse the repository at this point in the history
* fix form parameter default value

* fix only phpnextgen
  • Loading branch information
wing328 authored Sep 26, 2023
1 parent 6c1a937 commit fce2dcb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.openapitools.codegen.api.TemplatingEngineAdapter;
import org.openapitools.codegen.config.GlobalSettings;
import org.openapitools.codegen.examples.ExampleGenerator;
import org.openapitools.codegen.languages.PhpNextgenClientCodegen;
import org.openapitools.codegen.languages.RustServerCodegen;
import org.openapitools.codegen.meta.FeatureSet;
import org.openapitools.codegen.meta.GeneratorMetadata;
Expand Down Expand Up @@ -7083,7 +7084,12 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
// hoist items data into the array property
// TODO this hoisting code is generator specific and should be isolated into updateFormPropertyForArray
codegenParameter.baseType = arrayInnerProperty.dataType;
codegenParameter.defaultValue = arrayInnerProperty.getDefaultValue();
// TODO we need to fix array of item (with default value) generator by generator
// https://github.com/OpenAPITools/openapi-generator/pull/16654/ is a good reference
if (!(this instanceof PhpNextgenClientCodegen)) {
// no need to set default value here as it was set earlier
codegenParameter.defaultValue = arrayInnerProperty.getDefaultValue();
}
if (codegenParameter.items.isFile) {
codegenParameter.isFile = true;
codegenParameter.dataFormat = codegenParameter.items.dataFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
for (CodegenProperty prop : model.vars) {
if (prop.isArray || prop.isMap) {
prop.vendorExtensions.putIfAbsent("x-php-prop-type", "array");
}
else {
} else {
prop.vendorExtensions.putIfAbsent("x-php-prop-type", prop.dataType);
}
}
Expand All @@ -170,16 +169,14 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
for (CodegenOperation operation : operations.getOperation()) {
if (operation.returnType == null) {
operation.vendorExtensions.putIfAbsent("x-php-return-type", "void");
}
else {
} else {
operation.vendorExtensions.putIfAbsent("x-php-return-type", operation.returnType);
}

for (CodegenParameter param : operation.allParams) {
if (param.isArray || param.isMap) {
param.vendorExtensions.putIfAbsent("x-php-param-type", "array");
}
else {
} else {
param.vendorExtensions.putIfAbsent("x-php-param-type", param.dataType);
}
}
Expand All @@ -191,12 +188,28 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
@Override
public String toDefaultValue(CodegenProperty codegenProperty, Schema schema) {
if (codegenProperty.isArray) {
if (schema.getDefault() != null) {
if (schema.getDefault() != null) { // array schema has default value
return "[" + schema.getDefault().toString() + "]";
} else if (schema.getItems().getDefault() != null) { // array item schema has default value
return "[" + toDefaultValue(schema.getItems()) + "]";
} else {
return null;
}
}
return super.toDefaultValue(codegenProperty, schema);
}

@Override
public String toDefaultParameterValue(CodegenProperty codegenProperty, Schema<?> schema) {
return toDefaultValue(codegenProperty, schema);
}

@Override
public void setParameterExampleValue(CodegenParameter p) {
if (p.isArray && p.items.defaultValue != null) {
p.example = p.defaultValue;
} else {
super.setParameterExampleValue(p);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -800,14 +800,14 @@ $apiInstance = new OpenAPI\Client\Api\FakeApi(
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client()
);
$enum_header_string_array = array('enum_header_string_array_example'); // string[] | Header parameter enum test (string array)
$enum_header_string_array = ['$']; // string[] | Header parameter enum test (string array)
$enum_header_string = '-efg'; // string | Header parameter enum test (string)
$enum_query_string_array = array('enum_query_string_array_example'); // string[] | Query parameter enum test (string array)
$enum_query_string_array = ['$']; // string[] | Query parameter enum test (string array)
$enum_query_string = '-efg'; // string | Query parameter enum test (string)
$enum_query_integer = 56; // int | Query parameter enum test (double)
$enum_query_double = 3.4; // float | Query parameter enum test (double)
$enum_query_model_array = array(new \OpenAPI\Client\Model\\OpenAPI\Client\Model\EnumClass()); // \OpenAPI\Client\Model\EnumClass[]
$enum_form_string_array = array('$'); // string[] | Form parameter enum test (string array)
$enum_form_string_array = ['$']; // string[] | Form parameter enum test (string array)
$enum_form_string = '-efg'; // string | Form parameter enum test (string)

try {
Expand All @@ -821,14 +821,14 @@ try {

| Name | Type | Description | Notes |
| ------------- | ------------- | ------------- | ------------- |
| **enum_header_string_array** | [**string[]**](../Model/string.md)| Header parameter enum test (string array) | [optional] |
| **enum_header_string_array** | [**string[]**](../Model/string.md)| Header parameter enum test (string array) | [optional] [default to [&#39;$&#39;]] |
| **enum_header_string** | **string**| Header parameter enum test (string) | [optional] [default to &#39;-efg&#39;] |
| **enum_query_string_array** | [**string[]**](../Model/string.md)| Query parameter enum test (string array) | [optional] |
| **enum_query_string_array** | [**string[]**](../Model/string.md)| Query parameter enum test (string array) | [optional] [default to [&#39;$&#39;]] |
| **enum_query_string** | **string**| Query parameter enum test (string) | [optional] [default to &#39;-efg&#39;] |
| **enum_query_integer** | **int**| Query parameter enum test (double) | [optional] |
| **enum_query_double** | **float**| Query parameter enum test (double) | [optional] |
| **enum_query_model_array** | [**\OpenAPI\Client\Model\EnumClass[]**](../Model/\OpenAPI\Client\Model\EnumClass.md)| | [optional] |
| **enum_form_string_array** | [**string[]**](../Model/string.md)| Form parameter enum test (string array) | [optional] [default to &#39;$&#39;] |
| **enum_form_string_array** | [**string[]**](../Model/string.md)| Form parameter enum test (string array) | [optional] [default to [&#39;$&#39;]] |
| **enum_form_string** | **string**| Form parameter enum test (string) | [optional] [default to &#39;-efg&#39;] |

### Return type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ $apiInstance = new OpenAPI\Client\Api\PetApi(
new GuzzleHttp\Client(),
$config
);
$status = array('status_example'); // string[] | Status values that need to be considered for filter
$status = ['available']; // string[] | Status values that need to be considered for filter

try {
$result = $apiInstance->findPetsByStatus($status);
Expand All @@ -199,7 +199,7 @@ try {

| Name | Type | Description | Notes |
| ------------- | ------------- | ------------- | ------------- |
| **status** | [**string[]**](../Model/string.md)| Status values that need to be considered for filter | |
| **status** | [**string[]**](../Model/string.md)| Status values that need to be considered for filter | [default to [&#39;available&#39;]] |

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3956,14 +3956,14 @@ public function testEndpointParametersRequest(
*
* To test enum parameters
*
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional)
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_header_string Header parameter enum test (string) (optional, default to '-efg')
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional)
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_query_string Query parameter enum test (string) (optional, default to '-efg')
* @param int|null $enum_query_integer Query parameter enum test (double) (optional)
* @param float|null $enum_query_double Query parameter enum test (double) (optional)
* @param \OpenAPI\Client\Model\EnumClass[]|null $enum_query_model_array enum_query_model_array (optional)
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to '$')
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_form_string Form parameter enum test (string) (optional, default to '-efg')
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEnumParameters'] to see the possible values for this operation
*
Expand All @@ -3972,14 +3972,14 @@ public function testEndpointParametersRequest(
* @return void
*/
public function testEnumParameters(
?array $enum_header_string_array = null,
?array $enum_header_string_array = ['$'],
?string $enum_header_string = '-efg',
?array $enum_query_string_array = null,
?array $enum_query_string_array = ['$'],
?string $enum_query_string = '-efg',
?int $enum_query_integer = null,
?float $enum_query_double = null,
?array $enum_query_model_array = null,
?array $enum_form_string_array = '$',
?array $enum_form_string_array = ['$'],
?string $enum_form_string = '-efg',
string $contentType = self::contentTypes['testEnumParameters'][0]
): void
Expand All @@ -3992,14 +3992,14 @@ public function testEnumParameters(
*
* To test enum parameters
*
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional)
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_header_string Header parameter enum test (string) (optional, default to '-efg')
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional)
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_query_string Query parameter enum test (string) (optional, default to '-efg')
* @param int|null $enum_query_integer Query parameter enum test (double) (optional)
* @param float|null $enum_query_double Query parameter enum test (double) (optional)
* @param \OpenAPI\Client\Model\EnumClass[]|null $enum_query_model_array (optional)
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to '$')
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_form_string Form parameter enum test (string) (optional, default to '-efg')
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEnumParameters'] to see the possible values for this operation
*
Expand All @@ -4008,14 +4008,14 @@ public function testEnumParameters(
* @return array of null, HTTP status code, HTTP response headers (array of strings)
*/
public function testEnumParametersWithHttpInfo(
?array $enum_header_string_array = null,
?array $enum_header_string_array = ['$'],
?string $enum_header_string = '-efg',
?array $enum_query_string_array = null,
?array $enum_query_string_array = ['$'],
?string $enum_query_string = '-efg',
?int $enum_query_integer = null,
?float $enum_query_double = null,
?array $enum_query_model_array = null,
?array $enum_form_string_array = '$',
?array $enum_form_string_array = ['$'],
?string $enum_form_string = '-efg',
string $contentType = self::contentTypes['testEnumParameters'][0]
): array
Expand Down Expand Up @@ -4071,29 +4071,29 @@ public function testEnumParametersWithHttpInfo(
*
* To test enum parameters
*
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional)
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_header_string Header parameter enum test (string) (optional, default to '-efg')
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional)
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_query_string Query parameter enum test (string) (optional, default to '-efg')
* @param int|null $enum_query_integer Query parameter enum test (double) (optional)
* @param float|null $enum_query_double Query parameter enum test (double) (optional)
* @param \OpenAPI\Client\Model\EnumClass[]|null $enum_query_model_array (optional)
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to '$')
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_form_string Form parameter enum test (string) (optional, default to '-efg')
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEnumParameters'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEnumParametersAsync(
?array $enum_header_string_array = null,
?array $enum_header_string_array = ['$'],
?string $enum_header_string = '-efg',
?array $enum_query_string_array = null,
?array $enum_query_string_array = ['$'],
?string $enum_query_string = '-efg',
?int $enum_query_integer = null,
?float $enum_query_double = null,
?array $enum_query_model_array = null,
?array $enum_form_string_array = '$',
?array $enum_form_string_array = ['$'],
?string $enum_form_string = '-efg',
string $contentType = self::contentTypes['testEnumParameters'][0]
): PromiseInterface
Expand All @@ -4111,29 +4111,29 @@ function ($response) {
*
* To test enum parameters
*
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional)
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_header_string Header parameter enum test (string) (optional, default to '-efg')
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional)
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_query_string Query parameter enum test (string) (optional, default to '-efg')
* @param int|null $enum_query_integer Query parameter enum test (double) (optional)
* @param float|null $enum_query_double Query parameter enum test (double) (optional)
* @param \OpenAPI\Client\Model\EnumClass[]|null $enum_query_model_array (optional)
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to '$')
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_form_string Form parameter enum test (string) (optional, default to '-efg')
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEnumParameters'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return PromiseInterface
*/
public function testEnumParametersAsyncWithHttpInfo(
$enum_header_string_array = null,
$enum_header_string_array = ['$'],
$enum_header_string = '-efg',
$enum_query_string_array = null,
$enum_query_string_array = ['$'],
$enum_query_string = '-efg',
$enum_query_integer = null,
$enum_query_double = null,
$enum_query_model_array = null,
$enum_form_string_array = '$',
$enum_form_string_array = ['$'],
$enum_form_string = '-efg',
string $contentType = self::contentTypes['testEnumParameters'][0]
): PromiseInterface
Expand Down Expand Up @@ -4167,29 +4167,29 @@ function ($exception) {
/**
* Create request for operation 'testEnumParameters'
*
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional)
* @param string[]|null $enum_header_string_array Header parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_header_string Header parameter enum test (string) (optional, default to '-efg')
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional)
* @param string[]|null $enum_query_string_array Query parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_query_string Query parameter enum test (string) (optional, default to '-efg')
* @param int|null $enum_query_integer Query parameter enum test (double) (optional)
* @param float|null $enum_query_double Query parameter enum test (double) (optional)
* @param \OpenAPI\Client\Model\EnumClass[]|null $enum_query_model_array (optional)
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to '$')
* @param string[]|null $enum_form_string_array Form parameter enum test (string array) (optional, default to ['$'])
* @param string|null $enum_form_string Form parameter enum test (string) (optional, default to '-efg')
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['testEnumParameters'] to see the possible values for this operation
*
* @throws InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function testEnumParametersRequest(
$enum_header_string_array = null,
$enum_header_string_array = ['$'],
$enum_header_string = '-efg',
$enum_query_string_array = null,
$enum_query_string_array = ['$'],
$enum_query_string = '-efg',
$enum_query_integer = null,
$enum_query_double = null,
$enum_query_model_array = null,
$enum_form_string_array = '$',
$enum_form_string_array = ['$'],
$enum_form_string = '-efg',
string $contentType = self::contentTypes['testEnumParameters'][0]
): Request
Expand Down

0 comments on commit fce2dcb

Please sign in to comment.