OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] resteasy library - defaultCookieMap not used in ApiClient

Open
#14,108 1 comment 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

When Generating classes via the maven plugin and the resteasy library there is no way to set default cookies via the ApiClient as the defaultCookieMap field is not used.

In the invokeAPI function is generated with a block of code that seems like it's supposed to implement default cookies but instead of the aforementioned defaultCookieMap defaultHeaderMap is used:

    for (Entry<String, String> defaultCookieEntry: defaultHeaderMap.entrySet()) {
      if (!cookieParams.containsKey(defaultCookieEntry.getKey())) {
        String value = defaultCookieEntry.getValue();
        if (value != null) {
          invocationBuilder = invocationBuilder.cookie(defaultCookieEntry.getKey(), value);
        }
      }
    }

Other java generator libraries like jersey2 put defaultCookieMap here like they're supposed to.

openapi-generator version

6.2.1, 5.1.1 and some others were tested.
seems to affect every major semi recent build.

Generation Details

pom plugin configuration:

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.2.1</version>
<executions>
	<execution>
		<goals>
			<goal>generate</goal>
		</goals>
		<configuration>
			<inputSpec>http://localhost:8083/service/openapi.json</inputSpec>
			<generatorName>java</generatorName>

			<configOptions>
				<dateLibrary>java8</dateLibrary>
				<useBeanValidation>true</useBeanValidation>
			</configOptions>

			<library>resteasy</library>
		</configuration>
	</execution>
</executions>
</plugin>

generation is done by executing maven clean compile with profile generate-model in eclipse

Steps to reproduce
  1. take any openapi spec file
  2. generate the client code via the maven plugin, java generator and resteasy library
  3. done

Even your own resteasy example has that issue at line 658

Suggest a fix

The ApiClient.mustache seems to be correct and other libraries like jersey2 don't make this mistake so I think the resteasy library code needs to be checked. I think this is just a copy/ paste error

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 resteasy generated sample at samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/ApiClient.java around line 658, then inspect ApiClient.mustache and compare the corresponding jersey2 code. Regenerate a Java client with the resteasy library and verify that default cookies are applied from defaultCookieMap rather than defaultHeaderMap.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.