Skip to content

[java][webclient] remove default Content-Type#7945

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
druppelt:java-spring-no-default-content-type
Nov 24, 2020
Merged

[java][webclient] remove default Content-Type#7945
wing328 merged 1 commit intoOpenAPITools:masterfrom
druppelt:java-spring-no-default-content-type

Conversation

@druppelt
Copy link
Copy Markdown
Contributor

As lorenzleutgeb reported in #476 two years ago, GET requests get a Content-Type header by default, which is wrong. And while it shouldn't, it can actually lead to issues with some servers. This PR changes that for java webclient.
I only changed it for webclient as that is what I use and I was hoping that keeping the PR small would result in a faster merge. If needed for consistency I could also fix the other java clients.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @bkabrda (2020/01)

@auto-labeler
Copy link
Copy Markdown

auto-labeler Bot commented Nov 15, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@druppelt
Copy link
Copy Markdown
Contributor Author

Can someone help me resolve the circleci build issue? It just ends with Too long with no output (exceeded 10m0s): context deadline exceeded so I don't even understand whats wrong. I ran mvn integration-test -f samples/client/petstore/java/webclient/pom.xml locally and that worked.

@wing328
Copy link
Copy Markdown
Member

wing328 commented Nov 23, 2020

Just restarted the CI build. Let's see how that goes.

@wing328 wing328 added this to the 5.0.0 milestone Nov 23, 2020
@wing328 wing328 merged commit 4f0e75b into OpenAPITools:master Nov 24, 2020
@labamba63
Copy link
Copy Markdown

@druppelt How to generate client without content type for GET method? In version 5.0.1, it will still get the old version.

@druppelt
Copy link
Copy Markdown
Contributor Author

@labamba63 What exactly is not working for you? I created a simple Spring project, generated the client with the codegen and the typical petstore swagger and called a mockservice running locally. According to the log, the Content-Type Header was not sent:

2021-02-20 14:35:06.539 DEBUG 9896 --- [nio-8080-exec-1] o.s.w.f.CommonsRequestLoggingFilter      : Before request [uri=/v2/pet/1235;headers={accept-encoding=[gzip], user-agent=[ReactorNetty/1.0.4], host=[localhost:8080], accept=[application/json]}]

The plugin config in the pom:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>5.0.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
                <generatorName>java</generatorName>
                <library>webclient</library>
                <configOptions>
                    <sourceFolder>src/gen/java/main</sourceFolder>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

The api call:

@Slf4j
@Component
public class Runner implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        PetApi petApi = new PetApi();
        petApi.getApiClient().setBasePath("http://localhost:8080/v2");
        petApi.getPetById(1235L)
            .doOnNext(pet -> log.info("returned {}", pet))
            .block();
    }
}

@eratio08
Copy link
Copy Markdown

Now we only need this fix for the rest template

@wing328
Copy link
Copy Markdown
Member

wing328 commented Aug 27, 2022

@eratio08 I wonder if you can file a PR for that when you've time. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants