fix array default check in php nextgen

This commit is contained in:
William Cheng 2024-04-26 10:10:13 +08:00
parent fd90aa6347
commit a5ccd7a77e
4 changed files with 51 additions and 6 deletions

View File

@ -27,6 +27,7 @@ import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap; import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.model.OperationMap; import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap; import org.openapitools.codegen.model.OperationsMap;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -198,7 +199,10 @@ public class PhpNextgenClientCodegen extends AbstractPhpCodegen {
@Override @Override
public String toDefaultValue(CodegenProperty codegenProperty, Schema schema) { public String toDefaultValue(CodegenProperty codegenProperty, Schema schema) {
if (codegenProperty.isArray) { if (codegenProperty.isArray) {
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
if (schema.getDefault() != null) { // array schema has default value if (schema.getDefault() != null) { // array schema has default value
return "[" + schema.getDefault().toString() + "]"; return "[" + schema.getDefault().toString() + "]";
} else if (schema.getItems().getDefault() != null) { // array item schema has default value } else if (schema.getItems().getDefault() != null) { // array item schema has default value

View File

@ -1660,6 +1660,8 @@ components:
description: A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. description: A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01.
type: string type: string
pattern: '/^image_\d{1,3}$/i' pattern: '/^image_\d{1,3}$/i'
array_ref:
$ref: '#/components/schemas/ArrayRef'
EnumClass: EnumClass:
type: string type: string
default: '-efg' default: '-efg'
@ -2061,3 +2063,7 @@ components:
enum: enum:
- admin - admin
- user - user
ArrayRef:
type: array
items:
type: string

View File

@ -20,5 +20,6 @@ Name | Type | Description | Notes
**password** | **string** | | **password** | **string** | |
**pattern_with_digits** | **string** | A string that is a 10 digit number. Can have leading zeros. | [optional] **pattern_with_digits** | **string** | A string that is a 10 digit number. Can have leading zeros. | [optional]
**pattern_with_digits_and_delimiter** | **string** | A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. | [optional] **pattern_with_digits_and_delimiter** | **string** | A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. | [optional]
**array_ref** | **string[]** | | [optional]
[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) [[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md)

View File

@ -73,7 +73,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
'uuid' => 'string', 'uuid' => 'string',
'password' => 'string', 'password' => 'string',
'pattern_with_digits' => 'string', 'pattern_with_digits' => 'string',
'pattern_with_digits_and_delimiter' => 'string' 'pattern_with_digits_and_delimiter' => 'string',
'array_ref' => 'string[]'
]; ];
/** /**
@ -97,7 +98,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
'uuid' => 'uuid', 'uuid' => 'uuid',
'password' => 'password', 'password' => 'password',
'pattern_with_digits' => null, 'pattern_with_digits' => null,
'pattern_with_digits_and_delimiter' => null 'pattern_with_digits_and_delimiter' => null,
'array_ref' => null
]; ];
/** /**
@ -121,7 +123,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
'uuid' => false, 'uuid' => false,
'password' => false, 'password' => false,
'pattern_with_digits' => false, 'pattern_with_digits' => false,
'pattern_with_digits_and_delimiter' => false 'pattern_with_digits_and_delimiter' => false,
'array_ref' => false
]; ];
/** /**
@ -225,7 +228,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
'uuid' => 'uuid', 'uuid' => 'uuid',
'password' => 'password', 'password' => 'password',
'pattern_with_digits' => 'pattern_with_digits', 'pattern_with_digits' => 'pattern_with_digits',
'pattern_with_digits_and_delimiter' => 'pattern_with_digits_and_delimiter' 'pattern_with_digits_and_delimiter' => 'pattern_with_digits_and_delimiter',
'array_ref' => 'array_ref'
]; ];
/** /**
@ -249,7 +253,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
'uuid' => 'setUuid', 'uuid' => 'setUuid',
'password' => 'setPassword', 'password' => 'setPassword',
'pattern_with_digits' => 'setPatternWithDigits', 'pattern_with_digits' => 'setPatternWithDigits',
'pattern_with_digits_and_delimiter' => 'setPatternWithDigitsAndDelimiter' 'pattern_with_digits_and_delimiter' => 'setPatternWithDigitsAndDelimiter',
'array_ref' => 'setArrayRef'
]; ];
/** /**
@ -273,7 +278,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
'uuid' => 'getUuid', 'uuid' => 'getUuid',
'password' => 'getPassword', 'password' => 'getPassword',
'pattern_with_digits' => 'getPatternWithDigits', 'pattern_with_digits' => 'getPatternWithDigits',
'pattern_with_digits_and_delimiter' => 'getPatternWithDigitsAndDelimiter' 'pattern_with_digits_and_delimiter' => 'getPatternWithDigitsAndDelimiter',
'array_ref' => 'getArrayRef'
]; ];
/** /**
@ -348,6 +354,7 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
$this->setIfExists('password', $data ?? [], null); $this->setIfExists('password', $data ?? [], null);
$this->setIfExists('pattern_with_digits', $data ?? [], null); $this->setIfExists('pattern_with_digits', $data ?? [], null);
$this->setIfExists('pattern_with_digits_and_delimiter', $data ?? [], null); $this->setIfExists('pattern_with_digits_and_delimiter', $data ?? [], null);
$this->setIfExists('array_ref', $data ?? [], null);
} }
/** /**
@ -957,6 +964,33 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
return $this; return $this;
} }
/**
* Gets array_ref
*
* @return string[]|null
*/
public function getArrayRef(): ?array
{
return $this->container['array_ref'];
}
/**
* Sets array_ref
*
* @param string[]|null $array_ref array_ref
*
* @return $this
*/
public function setArrayRef(?array $array_ref): static
{
if (is_null($array_ref)) {
throw new InvalidArgumentException('non-nullable array_ref cannot be null');
}
$this->container['array_ref'] = $array_ref;
return $this;
}
/** /**
* Returns true if offset exists. False otherwise. * Returns true if offset exists. False otherwise.
* *