Repository navigation
Description
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=falseWith a non-trivial modelPackage / namespacing setup (as in real projects), observe src/API/DefaultApiInterface.php.
Steps to reproduce
- Save the minimal OpenAPI YAML above as
openapi.yaml. - Run
openapi-generator-cliwith-g php-symfony(version7.21.0). - Open the generated
DefaultApiInterface.phpand inspect the method signature / imports for thepageTypequery 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:
- [BUG] php-symfony enum generation generates empty class #14115
- Fix enum generation for php-symfony generator #14105
- [REQ] [PHP-SYMFONY] Support BackedEnum for enum ref #16846
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
dataTypefor enum refs is only the short class name when the template always prefixes\{{modelPackage}}\, or - Change the template / vendor extension so that when
dataTypeis already FQCN / already includesmodelPackage, the generator does not prepend\{{modelPackage}}\again.
Likely touch points:
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java(getTypeDeclarationoverloads forSchemavsString)modules/openapi-generator/src/main/resources/php-symfony/api.mustache(isEnumRefbranches for parameter typing / imports)
Actual vs expected
- Expected:
DefaultApiInterfacereferences the same PHP class as the generated enum model file, e.g....\Model\DTOBalanceModelRecommendedReasonPageType(name depends on naming rules), with a matchingusestatement. - Actual:
DefaultApiInterfacemay reference a non-existent stitched class name such as...\Model\GemsAppsKuaquaOpenAPIModelDTOBalanceModelRecommendedReasonPageType(example pattern: concatenated segments resemblingmodelPackage+ original model name), which does not correspond to the generatedDTO*RecommendedReasonPageType.phpfile on disk.
Activity
fix(php-symfony): enum $ref query params — short types and imports (#…