Skip to content

[BUG][PHP-SYMFONY] Optional query enum with $ref schema and default rejects requests when parameter is omitted #23539

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? (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 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
  1. Generate php-symfony from the YAML above.
  2. GET /pets/feed-hints without tone.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions