OpenAPITools / OpenAPITools/openapi-generator

PHP Client does not handle default values correctly when they are ENUM references

Open
#6,809 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

The default values set in the constructor for PHP Model classes does not correctly reference self::.

I believe the offending code is this line:
https://github.com/OpenAPITools/openapi-generator/blob/d9a6f4d7261d523d933e4cd33e6abc48d4d0b5e2/modules/openapi-generator/src/main/resources/php/model_generic.mustache#L164

example generated code:

        $this->container['code'] = isset($data['code']) ? $data['code'] : CODE_200;

expected:

        $this->container['code'] = isset($data['code']) ? $data['code'] : self::CODE_200;

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 in modules/openapi-generator/src/main/resources/php/model_generic.mustache at the referenced line and inspect how default values are rendered for enum references. Generate a PHP model containing an enum default and verify that the resulting constructor uses self::CODE_200 rather than CODE_200; done means the generated default is a valid class-constant reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.