Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][PHP] Missing tagged union discriminator literal #20343

Closed
5 of 6 tasks
brianferri opened this issue Dec 17, 2024 · 1 comment
Closed
5 of 6 tasks

[BUG][PHP] Missing tagged union discriminator literal #20343

brianferri opened this issue Dec 17, 2024 · 1 comment

Comments

@brianferri
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The PHP Client Generator doesn't generate all available discriminator options

in Params.php (after generation) we get:

    public const SERVICE_PROP0 = 'Prop0';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getServiceAllowableValues()
    {
        return [
            self::SERVICE_PROP0,
        ];
    }

when we should instead be seeing:

    public const SERVICE_PROP0 = 'Prop0';
    public const SERVICE_PROP1 = 'Prop1';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getServiceAllowableValues()
    {
        return [
            self::SERVICE_PROP0,
            self::SERVICE_PROP1,
        ];
    }
openapi-generator version

npm: "@openapitools/openapi-generator-cli": "^2.15.3",
jar: 7.10.0

OpenAPI declaration file content or url

Untitled-1.json
https://dpaste.org/k2Qoe

Generation Details

openapitools.config.yml

generatorName: php-nextgen
outputDir: core/client
globalProperties:
  models: ""
  apis: ""
  supportingFiles: "README.md,ApiException.php,Configuration.php,HeaderSelector.php,ObjectSerializer.php,ModelInterface.php"
openapi-generator-cli generate -i Untitled-1.json -c openapitools.config.yml
Steps to reproduce

Generate the php-nextgen client using the command, configuration and json (as an example) provided above

Related issues/PRs
Suggest a fix

It seems the issue has to do with these lines:

{{#vars}}
{{#isEnum}}
{{#allowableValues}}
{{#enumVars}}
public const {{enumName}}_{{{name}}} = {{{value}}};
{{/enumVars}}
{{/allowableValues}}
{{/isEnum}}
{{/vars}}
{{#vars}}
{{#isEnum}}
/**
* Gets allowable values of the enum
*
* @return string[]
*/
public function {{getter}}AllowableValues()
{
return [
{{#allowableValues}}{{#enumVars}}self::{{enumName}}_{{{name}}},{{^-last}}
{{/-last}}{{/enumVars}}{{/allowableValues}}
];
}

Probably present in other PHP client generators as well.

@brianferri
Copy link
Contributor Author

Additionally it would seem that, with the same setup as above, the lines:

{{#discriminator}}
// Initialize discriminator property with the model name.
$this->container['{{discriminatorName}}'] = static::$openAPIModelName;
{{/discriminator}}

Interfere with the construction of the Params object:
Params.php

public function __construct(array $data = null)
    {
        $this->setIfExists('service', $data ?? [], 'Prop0');
        $this->setIfExists('prop1', $data ?? [], null);
        $this->setIfExists('prop0', $data ?? [], null);

        // Initialize discriminator property with the model name.
        $this->container['service'] = static::$openAPIModelName; // Overwrites the `setIfExists` above
    }

brianferri added a commit to brianferri/openapi-generator that referenced this issue Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant