OpenAPITools / OpenAPITools/openapi-generator
[REQ][PHP] Add toPhpDefinition method to AbstractPhpCodegen
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
I've spend some time under php mock server #3545
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading AbstractPhpCodegen and the current PHP client generation path. Trace how model parameters reach templates, then define completion as nested Java Map/List data being represented as PHP array syntax while preserving the schema properties shown in the issue and making the result available to templates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100