OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] Retrofit2 DefaultApi interface is invalid and cannot compile if there is a cookie parameter

Open
#20,932 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)? no, this link is not working
  • 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

The generator produces an invalid Retrofit2 DefaultApi interface that cannot compile if a cookie parameter is specified in the contract.

openapi-generator version

openapi-generator-cli 7.13.0-SNAPSHOT and 7.12.0 maven plugin

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Cookie Bug
  version: 1.0.0

paths:
  /v1/cookie:
    get:
      parameters:
        - name: key
          in: query
          required: true
          schema:
            type: string
        - $ref: "#/components/parameters/SESSION"
      responses:
        "200":
          description: "Success"

components:
  parameters:
    SESSION:
      name: session
      in: cookie
      required: false
      schema:
        type: string
Generation Details
docker run --rm \
	-v ./input:/input:ro \
	-v ./output:/output \
	openapitools/openapi-generator-cli generate \
	-i /input/spec.yaml \
	-g java \
	--library retrofit2 \
	-o /output
Steps to reproduce
  1. mkdir input output
  2. Save the spec to ./input/spec.yaml
  3. Run the command above.
  4. Check ./output/src/main/java/org/openapitools/client/api/DefaultApi.java

Actual result:

// here, see there is no second parameter after the key
Call<Void> v1CookieGet(
  @retrofit2.http.Query("key") String key, 
);

Expected result: to the best of my knowledge, retrofit2 doesn't have a dedicated annotation for cookies, and it doesn't look like there is a "one size fits all" solution. Perhaps, the generator should ignore cookie params and let people deal with them in the headers? So the code would be:

Call<Void> v1CookieGet(
  @retrofit2.http.Query("key") String key
);
Related issues/PRs

Not that I am aware of.

Suggest a fix

Everything works fine if I change in: cookie:

components:
  parameters:
    SESSION:
      name: session
      in: cookie

To in: query:

components:
  parameters:
    SESSION:
      name: session
      in: query

So this is likely related to how cookie params are processed.

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 generated output at output/src/main/java/org/openapitools/client/api/DefaultApi.java and reproduce the issue using the supplied spec.yaml and Docker generation command. Trace how the cookie parameter is processed for the Java retrofit2 library. Done means the generated DefaultApi.java compiles when an operation includes both query and cookie parameters, with the cookie behavior matching the chosen expected handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.