Bug Report Checklist
Description
For an OpenAPI 3.x in: query parameter that is required: false, uses a $ref to an enum schema (e.g. under components/schemas), and declares a valid enum literal as default, omitting the query key should be semantically equivalent to sending that default value. The request should not fail validation solely because the parameter is absent.
With php-symfony, generated controllers can instead:
- Read the parameter from the request as
null when the key is omitted (default not applied in Request::query->get(...)).
- Still run
Assert\Type(<enum PHP class>) (or equivalent) on that value.
- Fail before business logic runs (often 4xx), which contradicts the OpenAPI default semantics.
The same operation may correctly apply default for another optional query (e.g. type: integer with default rendered as the second argument to get(...)), so behavior is inconsistent within one operation.
openapi-generator version
7.22.0-SNAPSHOT, commit c07f3a0ec1f217e8b256421c65ff4310c8ecba81 (reproduced on local tree aligned with master at 2026-04-14).
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: Pet-style optional enum query example
version: "1.0"
paths:
/pets/feed-hints:
get:
operationId: listFeedHints
parameters:
- $ref: "#/components/parameters/ToneQuery"
- name: limit
in: query
required: false
schema:
type: integer
format: int32
default: 10
minimum: 1
maximum: 50
responses:
"200":
description: OK
components:
parameters:
ToneQuery:
name: tone
in: query
required: false
schema:
$ref: "#/components/schemas/PetAnnouncementTone"
default: friendly
schemas:
PetAnnouncementTone:
type: string
enum: [friendly, formal]
- Expected:
GET /pets/feed-hints (no tone) → 2xx, tone = default friendly.
- Actual: controller validation 4xx;
tone stays null (no second arg to query->get).
Generation Details
java -jar openapi-generator-cli.jar generate -g php-symfony -i spec.yaml -o out \
-p 'composerVendorName=example,composerProjectName=demo,bundleName=DemoBundle,bundleAlias=demo,srcBasePath=src,invokerPackage=App\OpenAPI,apiPackage=API,modelPackage=Model,composerPackageName=example/demo,variableNamingConvention=camelCase'
Steps to reproduce
- Generate
php-symfony from the YAML above.
GET /pets/feed-hints without tone.
- Observe 4xx from validation instead of default
friendly.
Related issues/PRs
No exact duplicate found. Closest: #23222 (query get / defaults), #16846 / #16847 (enum $ref), #19008 (php-symfony asserts), #6809 (PHP enum default, client).
Suggest a fix
Populate CodegenParameter.defaultValue when default is on components.parameters + enum $ref, so api_controller.mustache emits query->get('<baseName>', <default>) (and existing Elvis if applicable). Optionally wrap optional enum Assert\Type in Assert\Optional only as a fallback—Optional alone does not apply the OpenAPI default to the handler.
Bug Report Checklist
Description
For an OpenAPI 3.x
in: queryparameter that isrequired: false, uses a$refto an enum schema (e.g. undercomponents/schemas), and declares a valid enum literal asdefault, omitting the query key should be semantically equivalent to sending that default value. The request should not fail validation solely because the parameter is absent.With
php-symfony, generated controllers can instead:nullwhen the key is omitted (default not applied inRequest::query->get(...)).Assert\Type(<enum PHP class>)(or equivalent) on that value.The same operation may correctly apply
defaultfor another optional query (e.g.type: integerwithdefaultrendered as the second argument toget(...)), so behavior is inconsistent within one operation.openapi-generator version
7.22.0-SNAPSHOT, commitc07f3a0ec1f217e8b256421c65ff4310c8ecba81(reproduced on local tree aligned withmasterat 2026-04-14).OpenAPI declaration file content or url
GET /pets/feed-hints(notone) → 2xx,tone= defaultfriendly.tonestaysnull(no second arg toquery->get).Generation Details
java -jar openapi-generator-cli.jar generate -g php-symfony -i spec.yaml -o out \ -p 'composerVendorName=example,composerProjectName=demo,bundleName=DemoBundle,bundleAlias=demo,srcBasePath=src,invokerPackage=App\OpenAPI,apiPackage=API,modelPackage=Model,composerPackageName=example/demo,variableNamingConvention=camelCase'Steps to reproduce
php-symfonyfrom the YAML above.GET /pets/feed-hintswithouttone.friendly.Related issues/PRs
No exact duplicate found. Closest: #23222 (query
get/ defaults), #16846 / #16847 (enum$ref), #19008 (php-symfony asserts), #6809 (PHP enum default, client).Suggest a fix
Populate
CodegenParameter.defaultValuewhendefaultis oncomponents.parameters+ enum$ref, soapi_controller.mustacheemitsquery->get('<baseName>', <default>)(and existing Elvis if applicable). Optionally wrap optional enumAssert\TypeinAssert\Optionalonly as a fallback—Optionalalone does not apply the OpenAPI default to the handler.