OpenAPITools / OpenAPITools/openapi-generator

[REQ][PHP] Add toPhpDefinition method to AbstractPhpCodegen

Open
#4,288 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: PHP Enhancement: Feature Server: PHP
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.