diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java index 3c57a89f4ab..8136c9d3003 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java @@ -27,6 +27,7 @@ import org.openapitools.codegen.model.ModelMap; import org.openapitools.codegen.model.ModelsMap; import org.openapitools.codegen.model.OperationMap; import org.openapitools.codegen.model.OperationsMap; +import org.openapitools.codegen.utils.ModelUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -198,7 +199,10 @@ public class PhpNextgenClientCodegen extends AbstractPhpCodegen { @Override public String toDefaultValue(CodegenProperty codegenProperty, Schema schema) { + if (codegenProperty.isArray) { + schema = ModelUtils.getReferencedSchema(this.openAPI, schema); + 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 diff --git a/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml index 28b35f47071..433bd56071e 100644 --- a/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1660,6 +1660,8 @@ components: description: A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. type: string pattern: '/^image_\d{1,3}$/i' + array_ref: + $ref: '#/components/schemas/ArrayRef' EnumClass: type: string default: '-efg' @@ -2061,3 +2063,7 @@ components: enum: - admin - user + ArrayRef: + type: array + items: + type: string \ No newline at end of file diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/FormatTest.md b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/FormatTest.md index 81f6387a2ed..91e1f56e6b1 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/FormatTest.md +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/FormatTest.md @@ -20,5 +20,6 @@ Name | Type | Description | Notes **password** | **string** | | **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] +**array_ref** | **string[]** | | [optional] [[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php index 0da2bab5d01..bad4359dba5 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php @@ -73,7 +73,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable 'uuid' => 'string', 'password' => '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', 'password' => 'password', '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, 'password' => 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', 'password' => 'password', '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', 'password' => 'setPassword', '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', 'password' => 'getPassword', '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('pattern_with_digits', $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; } + + /** + * 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. *