OpenAPITools / OpenAPITools/openapi-generator
[REQ][JAVA][WebClient] Add support for setting max-in-memory-size for WebClient
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
When generating a client with the Java WebClient library it is not possible to configure the max-in-memory-size of the WebClient. The generator does not honor the Spring configuration property called spring.codec.max-in-memory-size.
Describe the solution you'd like
A configuration option should be added that will set the max-in-memory-size of the WebClient.
The ApiClient.mustache file should be changed so the buildWebClient method looks something like this:
/**
* Build the WebClient used to make HTTP requests.
* @return WebClient
*/
public static WebClient buildWebClient(ObjectMapper mapper) {
ExchangeStrategies strategies = ExchangeStrategies
.builder()
.codecs(clientDefaultCodecsConfigurer -> {
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper, MediaType.APPLICATION_JSON));
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper, MediaType.APPLICATION_JSON));
clientDefaultCodecsConfigurer.defaultCodecs().maxInMemorySize(configuredMaxInMemorySize);
}).build();
WebClient.Builder webClient = WebClient.builder().exchangeStrategies(strategies);
return webClient.build();
}
Describe alternatives you've considered
An alternative might be some way to set the max-in-memory-size on the ApiClient class after it's created. E.g. with a method like this:
public void setMaxInMemorySize(int maxInMemorySize) {
webClient = webClient.mutate().codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(maxInMemorySize)).build();
}
This would require making the webClient field non-final in the ApiClient class.
Another alternative would be to inject the default WebClient.Builder instantiated and configured by spring-boot, that would honor setting the spring.codec.max-in-memory-size property.
See https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/html/boot-features-webclient.html
Additional context
I am using the gradle plugin with these settings:
plugins {
id 'org.openapi.generator' version '4.2.3'
}
openApiGenerate {
generatorName = "java"
library = "webclient"
inputSpec = "$projectDir/src/main/resources/api-spec/spec.json"
outputDir = "$buildDir/generated"
apiPackage = "com.test.rest.api"
invokerPackage = "com.test.rest.invoker"
modelPackage = "com.test.rest.model"
modelNameSuffix = "Model"
configOptions = [
java11 : "true",
dateLibrary: "java11",
interfaceOnly: "true",
useSwaggerAnnotations: "true"
]
generateModelTests = false
generateApiTests = false
}
See also #874
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache and inspect the buildWebClient method. Review the proposed configuration, ApiClient setter, and Spring WebClient.Builder alternatives, then verify that a generated client can honor a configured max-in-memory-size.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100