Skip to content

Commit a5ccd7a

Browse files
committed
fix array default check in php nextgen
1 parent fd90aa6 commit a5ccd7a

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.openapitools.codegen.model.ModelsMap;
2828
import org.openapitools.codegen.model.OperationMap;
2929
import org.openapitools.codegen.model.OperationsMap;
30+
import org.openapitools.codegen.utils.ModelUtils;
3031
import org.slf4j.Logger;
3132
import org.slf4j.LoggerFactory;
3233

@@ -198,7 +199,10 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
198199

199200
@Override
200201
public String toDefaultValue(CodegenProperty codegenProperty, Schema schema) {
202+
201203
if (codegenProperty.isArray) {
204+
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
205+
202206
if (schema.getDefault() != null) { // array schema has default value
203207
return "[" + schema.getDefault().toString() + "]";
204208
} else if (schema.getItems().getDefault() != null) { // array item schema has default value

modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,8 @@ components:
16601660
description: A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01.
16611661
type: string
16621662
pattern: '/^image_\d{1,3}$/i'
1663+
array_ref:
1664+
$ref: '#/components/schemas/ArrayRef'
16631665
EnumClass:
16641666
type: string
16651667
default: '-efg'
@@ -2061,3 +2063,7 @@ components:
20612063
enum:
20622064
- admin
20632065
- user
2066+
ArrayRef:
2067+
type: array
2068+
items:
2069+
type: string

samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/FormatTest.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ Name | Type | Description | Notes
2020
**password** | **string** | |
2121
**pattern_with_digits** | **string** | A string that is a 10 digit number. Can have leading zeros. | [optional]
2222
**pattern_with_digits_and_delimiter** | **string** | A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01. | [optional]
23+
**array_ref** | **string[]** | | [optional]
2324

2425
[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md)

samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
7373
'uuid' => 'string',
7474
'password' => 'string',
7575
'pattern_with_digits' => 'string',
76-
'pattern_with_digits_and_delimiter' => 'string'
76+
'pattern_with_digits_and_delimiter' => 'string',
77+
'array_ref' => 'string[]'
7778
];
7879

7980
/**
@@ -97,7 +98,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
9798
'uuid' => 'uuid',
9899
'password' => 'password',
99100
'pattern_with_digits' => null,
100-
'pattern_with_digits_and_delimiter' => null
101+
'pattern_with_digits_and_delimiter' => null,
102+
'array_ref' => null
101103
];
102104

103105
/**
@@ -121,7 +123,8 @@ class FormatTest implements ModelInterface, ArrayAccess, JsonSerializable
121123
'uuid' => false,
122124
'password' => false,
123125
'pattern_with_digits' => false,
124-
'pattern_with_digits_and_delimiter' => false
126+
'pattern_with_digits_and_delimiter' => false,
127+
'array_ref' => false
125128
];
126129

127130
/**
@@ -225,7 +228,8 @@ public function isNullableSetToNull(string $property): bool
225228
'uuid' => 'uuid',
226229
'password' => 'password',
227230
'pattern_with_digits' => 'pattern_with_digits',
228-
'pattern_with_digits_and_delimiter' => 'pattern_with_digits_and_delimiter'
231+
'pattern_with_digits_and_delimiter' => 'pattern_with_digits_and_delimiter',
232+
'array_ref' => 'array_ref'
229233
];
230234

231235
/**
@@ -249,7 +253,8 @@ public function isNullableSetToNull(string $property): bool
249253
'uuid' => 'setUuid',
250254
'password' => 'setPassword',
251255
'pattern_with_digits' => 'setPatternWithDigits',
252-
'pattern_with_digits_and_delimiter' => 'setPatternWithDigitsAndDelimiter'
256+
'pattern_with_digits_and_delimiter' => 'setPatternWithDigitsAndDelimiter',
257+
'array_ref' => 'setArrayRef'
253258
];
254259

255260
/**
@@ -273,7 +278,8 @@ public function isNullableSetToNull(string $property): bool
273278
'uuid' => 'getUuid',
274279
'password' => 'getPassword',
275280
'pattern_with_digits' => 'getPatternWithDigits',
276-
'pattern_with_digits_and_delimiter' => 'getPatternWithDigitsAndDelimiter'
281+
'pattern_with_digits_and_delimiter' => 'getPatternWithDigitsAndDelimiter',
282+
'array_ref' => 'getArrayRef'
277283
];
278284

279285
/**
@@ -348,6 +354,7 @@ public function __construct(array $data = null)
348354
$this->setIfExists('password', $data ?? [], null);
349355
$this->setIfExists('pattern_with_digits', $data ?? [], null);
350356
$this->setIfExists('pattern_with_digits_and_delimiter', $data ?? [], null);
357+
$this->setIfExists('array_ref', $data ?? [], null);
351358
}
352359

353360
/**
@@ -957,6 +964,33 @@ public function setPatternWithDigitsAndDelimiter(?string $pattern_with_digits_an
957964

958965
return $this;
959966
}
967+
968+
/**
969+
* Gets array_ref
970+
*
971+
* @return string[]|null
972+
*/
973+
public function getArrayRef(): ?array
974+
{
975+
return $this->container['array_ref'];
976+
}
977+
978+
/**
979+
* Sets array_ref
980+
*
981+
* @param string[]|null $array_ref array_ref
982+
*
983+
* @return $this
984+
*/
985+
public function setArrayRef(?array $array_ref): static
986+
{
987+
if (is_null($array_ref)) {
988+
throw new InvalidArgumentException('non-nullable array_ref cannot be null');
989+
}
990+
$this->container['array_ref'] = $array_ref;
991+
992+
return $this;
993+
}
960994
/**
961995
* Returns true if offset exists. False otherwise.
962996
*

0 commit comments

Comments
 (0)