Skip to content

[PHP] Proposal: php-nextgen #13192

Open
Open
@thomasphansen

Description

@thomasphansen
Description

Hello,
I've been chatting with @wing328 about some PR's I'd like to submit to modernize the php generator, as well as targeting some of its limitations and enhancing some features. My original idea was to:

  • add parameter and return types as much as possible
  • reorganize the code: use smaller functions, reduce nesting, use early returns.
  • make the code safer by checking if a class implements an interface before trying to call its methods; introduce EnumInterface and enhance ModelInterface with a method to get the discriminator value.
  • create traits to reduce code duplication between Model classes
  • implement a solution for OneOf.

(i've already written the first 3 items in a feature branch - haven't created a PR yet, since our talk evolved to different directions)

During our conversation, William suggested the creation of a new generator, called php-nextgen: this generator would eventually be swapped with the current one, when releasing openapi-generator 7.0.0. He also suggested that the OneOf implementation could follow the ones used in other clients (C#, R, Powershell).

Based on these talks, I'd like to offer myself to develop this new php-nextgen generator, using the following guidelines:

  • should be based on php 8.1;
  • the first two items of my original suggestion (as well as parts for the third, and the traits creation) would be reused in the new generator;
  • the Enum model would be rewritten to use Enumerations instead - superseeds PR [php] fixed model_enum.mustache for real usage #11602
  • bring support for OneOf, using the R client as a model.

This last part has brought me some considerations that I'd like to discuss, as I wrote to @wing328:

  1. Today all the fields in Model objects are properties inside a set of arrays. I was thinking if a better approach wouldn't be to use "real" properties instead, using annotations to provide proper metadata (regarding nullable fields, for example). What do you think?
  2. The R client uses mustache to branch between object creation and simple attribution (checking "isPrimitiveType" and "isContainer" - pretty clever, BTW, way better than the php solution). I'd like to use this approach as well, but the AbstractPhpCodegen.java class defines "\DateType" and "\SplFileObject" as primitives. I haven't investigated yet, but I guess changing that would break all php clients, which I "guess" we don't want. What do you suggest to be done? (we could, for example, add another abstract codegen between the current one and its descendant classes, and move the current "primitives" definition to it).

(actually, while looking at the existing PRs and Issues for php, I found #10817, which seems to be caused exactly because we add \SplFileObject to the primitives list... maybe we should remove it?)

Let me know your thoughts! 😄 I have some time available for this project, and it would be a pleasure to contribute with this client! 😄

openapi-generator version

7.0.0

OpenAPI declaration file content or url

not relevant

Command line used for generation

not relevant

Steps to reproduce

not a bug

Related issues/PRs

#12331, #12721, #10817, #11485

Suggest a fix/enhancement

😄

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions