[REQ][PHP] Add toPhpDefinition method to AbstractPhpCodegen
Created by: ybelenko
Is your feature request related to a problem? Please describe.
I've spend some time under php mock server #3545 (closed)
At first I analyzed current PHP client implementation. It uses flatten data type declarations, eg string[]. It would be enough for a Mock server, but it doesn't help with automatic request validation. Let's look at the example:
ImageUrls:
type: array
minItems: 1
items:
type: string
format: uuid
minLength: 5
maxLength: 255
In current implementation this property will be described as:
/** @var string[] $imageUrls */
$imageUrls = [];
As a result we lost minItems, format, minLength and maxLength declarations. It makes automatic request validation impossible. It's obvious that we need all the props to check request under all requirements. The only way I see it we need to serialize all request parameters into PHP arrays. So the model above will look like:
$parameters = [
'ImageUrls' => [
'type' => 'array',
'minItems' => 1,
'items' => [
'type' => 'string',
'format' => 'uuid',
'minLength' => 5,
'maxLength' => 255,
],
],
];
Describe the solution you'd like
I think there should be method in AbstractPhpCodegen to convert Java Map/List instance into PHP array. Then I can convert parameters into PHP strings and add them to codegen, then use it in templates like $parameters = {{serializedParameters}};. Maybe this function/helper can be useful in other cases which I don't even realize yet.
Describe alternatives you've considered
If there is built-in Java method to convert any Java Map/List into PHP string definition please correct me.
cc @jebentier, @dkarlovi, @mandrean, @jfastnacht, @ackintosh, @renepardon