Skip to content

[BUG][Java][Spring] @RequestParam annotation missing for query parameters using oneOf with $ref to a named model #25210

Closed

Description

@cmagowan

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?
Description

When a query parameter's schema wraps a $ref to a named model in oneOf (or allOf), e.g. oneOf: [{$ref: '#/components/schemas/Price'}], the spring generator leaves out the @RequestParam annotation on the generated method parameter.

Cause:

  • After the single-element oneOf/allOf wrapper is resolved, the parameter is treated as a model, so CodegenParameter.isModel = true.
  • JavaSpring/queryParams.mustache only emits @RequestParam inside a {{^isModel}} guard. That guard was added by Link query parameter to model object #2710 to fix [BUG] Query Parameter Serialization (Spring) #2655, so that inline object query params are bound as a model attribute rather than through @RequestParam.
  • That guard is too broad: it also removes @RequestParam from these wrapped model refs.

Observed CodegenParameter flags for different query param schemas (all isModel=true):

Query param schema hasVars @RequestParam generated today
oneOf: [$ref: Price] false no (this bug)
allOf: [$ref: Price] false no (this bug)
direct $ref: Price true no (unchanged by the proposed fix)
inline type: object with properties true no (intended, see #2655)
openapi-generator version

7.26.0 (also reproduced on current master, 7.27.0-SNAPSHOT)

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Model Query Param Test
  version: 1.0.0
paths:
  /items/search:
    get:
      operationId: itemsSearchGet
      tags:
        - items
      parameters:
        - name: SearchTerm
          in: query
          description: A simple string query param
          schema:
            type: string
        - name: MaxPrice
          in: query
          description: A model-typed query param via oneOf ref
          schema:
            nullable: true
            oneOf:
              - $ref: '#/components/schemas/Price'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Item'
components:
  schemas:
    Price:
      type: object
      description: Represents an amount in a specific currency.
      additionalProperties: false
      required:
        - Currency
        - Amount
      properties:
        Currency:
          type: string
          description: The currency code.
        Amount:
          type: number
          description: The numeric value.
          format: double
          default: 0.0
    Item:
      type: object
      properties:
        name:
          type: string
        price:
          $ref: '#/components/schemas/Price'
Generation Details
openapi-generator generate -g spring -i spec.yaml -o output --additional-properties=interfaceOnly=true
Steps to reproduce
  1. Save the spec above as spec.yaml.
  2. Run the generation command above.
  3. Open output/src/main/java/org/openapitools/api/ItemsApi.java and find the itemsSearchGet method.
  4. The maxPrice parameter has no @RequestParam annotation, while searchTerm does.

Actual output

@Parameter(name = "MaxPrice", description = "A model-typed query param via oneOf ref", in = ParameterIn.QUERY) @Valid Price maxPrice

Expected output

@Parameter(name = "MaxPrice", description = "A model-typed query param via oneOf ref", in = ParameterIn.QUERY) @Valid @RequestParam(value = "MaxPrice", required = false) Price maxPrice
Related issues/PRs
Suggest a fix

In JavaSpring/queryParams.mustache, keep the existing {{^isModel}} @RequestParam(...){{/isModel}} branch and add an identical branch for models without vars:

{{#isModel}}{{^hasVars}} @RequestParam(...){{/hasVars}}{{/isModel}}{{^isModel}} @RequestParam(...){{/isModel}}

This restores @RequestParam for oneOf/allOf-wrapped model refs (hasVars=false) and leaves inline object params (hasVars=true, #2655) unchanged. Note that a direct $ref to a named model also has hasVars=true, so this fix does not change that case.

Note: kotlin-spring/queryParams.mustache has the same {{^isModel}} guard and shows the same behaviour; it is not covered by this issue.

Activity

  1. changed the title [-][BUG][Java][Spring] @RequestParam annotation missing for query parameters using oneOf with $ref to a named model[/-] [+][BUG][Java][Kotlin][Spring] @RequestParam annotation missing for query parameters using oneOf with $ref to a named model[/+] on Oct 9, 2026
  2. changed the title [-][BUG][Java][Kotlin][Spring] @RequestParam annotation missing for query parameters using oneOf with $ref to a named model[/-] [+][BUG][Java][Spring] @RequestParam annotation missing for query parameters using oneOf with $ref to a named model[/+] on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions