OpenAPITools / OpenAPITools/openapi-generator
[BUG][PHP-SYMFONY] Optional query enum with $ref schema and default rejects requests when parameter is omitted
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator? (redocly lint --extends=minimal)
- 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?
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
nullwhen the key is omitted (default not applied inRequest::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(notone) → 2xx,tone= defaultfriendly. - Actual: controller validation 4xx;
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
- Generate
php-symfonyfrom the YAML above. GET /pets/feed-hintswithouttone.- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with CodegenParameter.defaultValue handling and the php-symfony api_controller.mustache template, using the supplied OpenAPI YAML and generation command to reproduce the output. Check how an optional enum $ref parameter differs from the integer default, then verify that an omitted tone uses friendly, reaches the handler, and returns 2xx without validation failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, php, symfony
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100