Skip to content

[BUG][jaxrs] server generator does not handle exploded query parameters of type object correctly #7888

@lbilger

Description

@lbilger

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I have an API that allows arbitrary query parameters. Following this answer on StackOverflow, I defined the parameter as follows:

        - name: parameters
          in: query
          schema:
            type: object
            additionalProperties:
              type: string
          style: form
          explode: true

The generator (I used jaxrs-resteasy-eap, but also tried some other jaxrs-based ones and got similar results) renders this parameter as @QueryParam("parameters") Map<String, String> parameters. This causes resteasy to complain at startup that it doesn't know how to deserialize a Map<String, String> from a Query Parameter.

I tried implementing my own ParamConverter, which works but is only called if a Query Param called parameters is actually specified in the URL, so it's obviously not the way to go.

In the end I settled for modifying the queryParams.mustache template to change the parameter to @Context javax.ws.rs.core.UriInfo uriInfo, so the implementation can use the UriInfo to access the query parameters.

openapi-generator version

4.3.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Test
  version: 1.0.0
paths:
  /something:
    get:
      operationId: getSomething
      parameters:
        - name: parameters
          in: query
          schema:
            type: object
            additionalProperties:
              type: string
          style: form
          explode: true
      responses:
        200:
          description: concatenated parameters
          content:
            application/json:
              schema:
                type: string
Generation Details
          <execution>
            <id>generate-test-server-code</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/src/main/resources/openapi-test.yaml</inputSpec>
              <generatorName>jaxrs-resteasy-eap</generatorName>
              <apiPackage>test</apiPackage>
              <modelPackage>test.model</modelPackage>
              <modelNamePrefix>Api</modelNamePrefix>
              <generateSupportingFiles>false</generateSupportingFiles>
              <configOptions>
                <interfaceOnly>true</interfaceOnly>
                <swaggerDocketConfig>false</swaggerDocketConfig>
                <dateLibrary>java8</dateLibrary>
                <bigDecimalAsString>true</bigDecimalAsString>
                <sourceFolder>src/gen/java</sourceFolder>
              </configOptions>
            </configuration>
          </execution>
Steps to reproduce

Generate code with the above source spec and settings.

Suggest a fix

As described above, you could change the parameter to be the UriInfo, or leave out the parameter entirely and let implementors inject it at class level instead.
If there's a nicer solution to actually specify it as a Map<String, String>, that would be welcome, too, of course.

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