OpenAPITools / OpenAPITools/openapi-generator

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

Open
#23,539 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.