Skip to content

Commit f3c164d

Browse files
authored
[PHP] Use a valid php type for maps (#8718)
* Use a valid php type for maps * Convert type hint to correct format Align map array format to that expected by phpdoc and associated tools.
1 parent c636f7e commit f3c164d

36 files changed

+144
-102
lines changed

docs/generators/php-laravel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3333
| Type/Alias | Instantiated By |
3434
| ---------- | --------------- |
3535
|array|array|
36-
|map|map|
36+
|map|array|
3737

3838

3939
## LANGUAGE PRIMITIVES

docs/generators/php-lumen.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3333
| Type/Alias | Instantiated By |
3434
| ---------- | --------------- |
3535
|array|array|
36-
|map|map|
36+
|map|array|
3737

3838

3939
## LANGUAGE PRIMITIVES

docs/generators/php-mezzio-ph.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3333
| Type/Alias | Instantiated By |
3434
| ---------- | --------------- |
3535
|array|array|
36-
|map|map|
36+
|map|array|
3737

3838

3939
## LANGUAGE PRIMITIVES

docs/generators/php-slim-deprecated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3333
| Type/Alias | Instantiated By |
3434
| ---------- | --------------- |
3535
|array|array|
36-
|map|map|
36+
|map|array|
3737

3838

3939
## LANGUAGE PRIMITIVES

docs/generators/php-slim4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3434
| Type/Alias | Instantiated By |
3535
| ---------- | --------------- |
3636
|array|array|
37-
|map|map|
37+
|map|array|
3838

3939

4040
## LANGUAGE PRIMITIVES

docs/generators/php-symfony.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3939
| Type/Alias | Instantiated By |
4040
| ---------- | --------------- |
4141
|array|array|
42-
|map|map|
42+
|map|array|
4343

4444

4545
## LANGUAGE PRIMITIVES

docs/generators/php.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3434
| Type/Alias | Instantiated By |
3535
| ---------- | --------------- |
3636
|array|array|
37-
|map|map|
37+
|map|array|
3838

3939

4040
## LANGUAGE PRIMITIVES

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public AbstractPhpCodegen() {
9898
);
9999

100100
instantiationTypes.put("array", "array");
101-
instantiationTypes.put("map", "map");
101+
instantiationTypes.put("map", "array");
102102

103103

104104
// provide primitives to mustache template
@@ -119,7 +119,7 @@ public AbstractPhpCodegen() {
119119
typeMapping.put("Date", "\\DateTime");
120120
typeMapping.put("DateTime", "\\DateTime");
121121
typeMapping.put("file", "\\SplFileObject");
122-
typeMapping.put("map", "map");
122+
typeMapping.put("map", "array");
123123
typeMapping.put("array", "array");
124124
typeMapping.put("list", "array");
125125
typeMapping.put("object", "object");
@@ -307,7 +307,7 @@ public String getTypeDeclaration(Schema p) {
307307
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
308308
inner = new StringSchema().description("TODO default missing map inner type to string");
309309
}
310-
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
310+
return getSchemaType(p) + "<string," + getTypeDeclaration(inner) + ">";
311311
} else if (StringUtils.isNotBlank(p.get$ref())) { // model
312312
String type = super.getTypeDeclaration(p);
313313
return (!languageSpecificPrimitives.contains(type))

modules/openapi-generator/src/main/resources/php-laravel/model.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace {{modelPackage}};
1010
class {{classname}} {
1111
1212
{{#vars}}
13-
/** @var {{dataType}} ${{name}} {{#description}}{{description}}{{/description}}*/
13+
/** @var {{{dataType}}} ${{name}} {{#description}}{{description}}{{/description}}*/
1414
private ${{name}};
1515

1616
{{/vars}}

modules/openapi-generator/src/main/resources/php-mezzio-ph/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class {{classname}}
4545
{{^isPrimitiveType}}
4646
{{#isContainer}}
4747
* TODO check if attribute is valid and can handle your container type
48-
* @PHA\Attribute(name=PHAttribute\Transfer::class, options={"type":"{{dataType}}","objectAttr":"bodyData"})
48+
* @PHA\Attribute(name=PHAttribute\Transfer::class, options={"type":"{{{dataType}}}","objectAttr":"bodyData"})
4949
{{/isContainer}}
5050
{{^isContainer}}
51-
* @PHA\Attribute(name=PHAttribute\Transfer::class, options={"type":{{dataType}}::class,"objectAttr":"bodyData"})
51+
* @PHA\Attribute(name=PHAttribute\Transfer::class, options={"type":{{{dataType}}}::class,"objectAttr":"bodyData"})
5252
{{/isContainer}}
5353
{{/isPrimitiveType}}
5454
{{/bodyParam}}
@@ -64,7 +64,7 @@ class {{classname}}
6464
{{#returnContainer}}
6565
* TODO check if generated return container type is valid
6666
{{/returnContainer}}
67-
* @return {{returnType}}
67+
* @return {{{returnType}}}
6868
{{/returnType}}
6969
*/
7070
public function {{operationId}}(ServerRequestInterface $request){{#returnType}}: {{#returnContainer}}array{{/returnContainer}}{{^returnContainer}}{{returnType}}{{/returnContainer}}{{/returnType}}
@@ -78,7 +78,7 @@ class {{classname}}
7878
{{/vendorExtensions}}
7979
{{#bodyParam}}
8080
{{^isPrimitiveType}}
81-
/** @var {{dataType}} $bodyData */
81+
/** @var {{{dataType}}} $bodyData */
8282
$bodyData = $request->getAttribute("bodyData");
8383
{{/isPrimitiveType}}
8484
{{/bodyParam}}

0 commit comments

Comments
 (0)