Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make php's array primitive #10093

Merged
merged 1 commit into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/generators/php-laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

<ul class="column-ul">
<li>DateTime</li>
<li>array</li>
<li>bool</li>
<li>boolean</li>
<li>byte</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/php-lumen.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

<ul class="column-ul">
<li>DateTime</li>
<li>array</li>
<li>bool</li>
<li>boolean</li>
<li>byte</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/php-mezzio-ph.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

<ul class="column-ul">
<li>DateTime</li>
<li>array</li>
<li>bool</li>
<li>boolean</li>
<li>byte</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/php-slim-deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

<ul class="column-ul">
<li>DateTime</li>
<li>array</li>
<li>bool</li>
<li>boolean</li>
<li>byte</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/php-slim4.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

<ul class="column-ul">
<li>DateTime</li>
<li>array</li>
<li>bool</li>
<li>boolean</li>
<li>byte</li>
Expand Down
1 change: 1 addition & 0 deletions docs/generators/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

<ul class="column-ul">
<li>DateTime</li>
<li>array</li>
<li>bool</li>
<li>boolean</li>
<li>byte</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public AbstractPhpCodegen() {
"float",
"string",
"object",
"array",
"DateTime",
"mixed",
"number",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@

package org.openapitools.codegen.php;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;

import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.languages.AbstractPhpCodegen;
import org.openapitools.codegen.TestUtils;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -122,6 +128,24 @@ public static Object[][] composerNames() {
};
}

@Test(description = "Issue #8945")
public void testArrayOfArrays() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_8945.yaml");
final AbstractPhpCodegen codegen = new P_AbstractPhpCodegen();

Schema test1 = openAPI.getComponents().getSchemas().get("MyResponse");
CodegenModel cm1 = codegen.fromModel("MyResponse", test1);

// Make sure we got the container object.
Assert.assertEquals(cm1.getDataType(), "object");
Assert.assertEquals(codegen.getTypeDeclaration("MyResponse"), "\\php\\Model\\MyResponse");

// Assert the array type is properly detected.
CodegenProperty cp1 = cm1.vars.get(0);
cp1 = codegen.fromProperty("ArrayProp", test1);
Assert.assertTrue(cp1.isPrimitiveType);
}

private static class P_AbstractPhpCodegen extends AbstractPhpCodegen {
@Override
public CodegenType getTag() {
Expand Down
50 changes: 50 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue_8945.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
openapi: 3.0.1
info:
title: OpenAPI Petstore
description: "for schemas with properties and required ensure correct hasVars, hasRequired, vars, and requiredVars"
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: http://petstore.swagger.io:80/v2
tags: []
paths:
/sut:
get:
operationId: getArrayOfArrays
responses:
'200':
description: OK
schema:
$ref: '#/definitions/MyResponse'
components:
schemas:
MyResponse:
type: object
properties:
ArrayOfArrays:
type: array
items:
$ref: '#/components/schemas/ArrayProp'
ArrayOfObjects:
type: array
items:
$ref: '#/components/schemas/ObjectProp'
ArrayOfArrays:
type: array
items:
$ref: '#/components/schemas/ArrayProp'
ArrayOfObjects:
type: array
items:
$ref: '#/components/schemas/ObjectProp'
ArrayProp:
type: array
items:
type: string
ObjectProp:
type: object
properties:
name:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**map_property** | **array<string,string>** | | [optional]
**map_of_map_property** | [**array<string,array<string,string>>**](array.md) | | [optional]
**map_of_map_property** | **array<string,array<string,string>>** | | [optional]

[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**array_array_number** | [**float[][]**](array.md) | | [optional]
**array_array_number** | **float[][]** | | [optional]

[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**array_of_string** | **string[]** | | [optional]
**array_array_of_integer** | [**int[][]**](array.md) | | [optional]
**array_array_of_model** | [**\OpenAPI\Client\Model\ReadOnlyFirst[][]**](array.md) | | [optional]
**array_array_of_integer** | **int[][]** | | [optional]
**array_array_of_model** | **\OpenAPI\Client\Model\ReadOnlyFirst[][]** | | [optional]

[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**map_map_of_string** | [**array<string,array<string,string>>**](array.md) | | [optional]
**map_map_of_string** | **array<string,array<string,string>>** | | [optional]
**map_of_enum_string** | **array<string,string>** | | [optional]
**direct_map** | **array<string,bool>** | | [optional]
**indirect_map** | **array<string,bool>** | | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function sanitizeForSerialization($data, $type = null, $format = n
foreach ($data::openAPITypes() as $property => $openAPIType) {
$getter = $data::getters()[$property];
$value = $data->$getter();
if ($value !== null && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
if ($value !== null && !in_array($openAPIType, ['DateTime', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
$callable = [$openAPIType, 'getAllowableEnumValues'];
if (is_callable($callable)) {
/** array $callable */
Expand Down Expand Up @@ -330,7 +330,7 @@ public static function deserialize($data, $class, $httpHeaders = null)
}

/** @psalm-suppress ParadoxicalCondition */
if (in_array($class, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
if (in_array($class, ['DateTime', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
settype($data, $class);
return $data;
}
Expand Down