Skip to content

[BUG][php-symfony] Wrong FQCN / use import for $ref enum query parameters in DefaultApiInterface (double modelPackage prefix) #23521

Description

@JerrySLau

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

When generating a Symfony server bundle with php-symfony, a query parameter that $refs a type: string + enum schema can produce an incorrect PHP type / use import in DefaultApiInterface.php.

Specifically, the generator appears to treat the parameter as an enum ref (isEnumRef) and the Mustache template prefixes \{{modelPackage}}\ to {{dataType}}. However, for this generator/path, dataType already resolves to a fully-qualified model type (effectively modelPackage + "\\" + shortClassName). The result is a double-prefixed / mangled class name that does not match the generated model filename / class name.

In practice this breaks static analysis and autoloading unless users add manual class_alias workarounds.

openapi-generator version

7.21.0 (openapi-generator-cli / maven artifact).
Unknown if this is a regression without bisecting; behavior is reproducible on 7.21.0.

OpenAPI declaration file content or url

Minimal reproducer:

openapi: 3.0.3
info:
  title: repro-enum-ref-query-param
  version: 1.0.0
paths:
  /items:
    get:
      operationId: listItems
      parameters:
        - $ref: '#/components/parameters/PageType'
      responses:
        '200':
          description: OK
components:
  parameters:
    PageType:
      name: pageType
      in: query
      required: false
      schema:
        $ref: '#/components/schemas/RecommendedReasonPageType'
  schemas:
    RecommendedReasonPageType:
      type: string
      enum: [home, settings]
Generation Details

Example CLI (adjust package names to your repro):

openapi-generator-cli generate \
  -i openapi.yaml \
  -g php-symfony \
  -o out \
  --additional-properties=variableNamingConvention=camelCase,phpLegacySupport=false

With a non-trivial modelPackage / namespacing setup (as in real projects), observe src/API/DefaultApiInterface.php.

Steps to reproduce
  1. Save the minimal OpenAPI YAML above as openapi.yaml.
  2. Run openapi-generator-cli with -g php-symfony (version 7.21.0).
  3. Open the generated DefaultApiInterface.php and inspect the method signature / imports for the pageType query parameter.
Related issues/PRs

Searched open/closed issues; no exact duplicate found for “php-symfony + query $ref string enum + mangled FQCN due to modelPackage being applied twice”. Partially related discussions include enum handling for php-symfony (e.g. empty enum class issues) and general PHP namespace problems, but they do not describe this specific DefaultApiInterface / isEnumRef interaction:

Suggest a fix

Align PhpSymfonyServerCodegen#getTypeDeclaration(...) output with what modules/openapi-generator/src/main/resources/php-symfony/api.mustache expects in the {{#isEnumRef}} branch:

  • Either ensure dataType for enum refs is only the short class name when the template always prefixes \{{modelPackage}}\, or
  • Change the template / vendor extension so that when dataType is already FQCN / already includes modelPackage, the generator does not prepend \{{modelPackage}}\ again.

Likely touch points:

  • modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java (getTypeDeclaration overloads for Schema vs String)
  • modules/openapi-generator/src/main/resources/php-symfony/api.mustache (isEnumRef branches for parameter typing / imports)
Actual vs expected
  • Expected: DefaultApiInterface references the same PHP class as the generated enum model file, e.g. ...\Model\DTOBalanceModelRecommendedReasonPageType (name depends on naming rules), with a matching use statement.
  • Actual: DefaultApiInterface may reference a non-existent stitched class name such as ...\Model\GemsAppsKuaquaOpenAPIModelDTOBalanceModelRecommendedReasonPageType (example pattern: concatenated segments resembling modelPackage + original model name), which does not correspond to the generated DTO*RecommendedReasonPageType.php file on disk.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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