OpenAPITools / OpenAPITools/openapi-generator

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

Open
#7,888 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 (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.

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 the jaxrs-resteasy-eap generator and its queryParams.mustache template, using the OpenAPI YAML example and generation settings in this issue. Reproduce the generated endpoint and compare handling of exploded object query parameters with the expected Resteasy behavior; done means the generated server handles those parameters without the reported startup deserialization error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.