-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Description
Description
After updating from 7.17 to 7.18, the base pathof the REST client passed into the API constructor is ignored.
openapi-generator version
7.18.0
OpenAPI source (shortened)
// (...)
"/multisend/{type}" : {
"post" : {
"operationId" : "sendFreeText",
"consumes" : [ "application/json;charset=utf-8" ],
"produces" : [ "application/json;charset=utf-8" ],
{
"name" : "type",
"in" : "path",
"required" : true,
"type" : "string",
"enum" : [ "type1", "type2" ]
}, {
"in" : "body",
"name" : "body",
"description" : "target messages",
"required" : true,
"schema" : {
"$ref" : "#/definitions/VehicleFreeTextMessageRequest"
}
},
"responses" : {
"200" : {
"description" : "Message sent successfully.",
"schema" : {
"$ref" : "#/definitions/ResponseStatusWithMessages"
}
},
"security" : [ {
"basic" : [ ]
} ]
}
}Generation Details
Kotlin: 2.2.21
OpenAPI: 2
Steps to reproduce
Create a RestClient like this and pass it to the generated API builder:
Now try to send a request.
Expected
The preconfigured baseUrl is not removed from the path
Actual behavior
Only protocol and port of baseUrl are used, the actual path behind is ignored.
After reverting back to 7.17.0 it worked again.
Debugging results
In a debugger, the base path is still set in the generated API but it is not used in the actual call:
I debugged the requests in the genated ApiClient:
As you can see, it somehow removed the base path but kept the host and the port. It seems like 7.18.0 is actually not using the passed, preconfigured client config (at least not all properties of it).
Suggest a fix
I think, the problem is within class ApiClient.
7.17.0 (working):
private fun <I> RestClient.RequestBodyUriSpec.uri(requestConfig: RequestConfig<I>) =
uri(requestConfig.path) { builder -> // existing client config is preserved
builder
.queryParams(LinkedMultiValueMap(requestConfig.query))
.build(requestConfig.params)
}Here the existing builder of the client is re-used and then query params are added from the config.
In the new, breaking version (7.18.0) the method was changed like this:
private fun <I> RestClient.RequestBodyUriSpec.uri(requestConfig: RequestConfig<I>): RestClient.RequestBodySpec {
val uriComponentsBuilder = UriComponentsBuilder.fromPath(requestConfig.path) // <-- ignores all existing config in builder
requestConfig.query.forEach { key, values ->
uriComponentsBuilder.queryParam(key, "{$key}")
}
return uri(uriComponentsBuilder.encode().buildAndExpand(requestConfig.query + requestConfig.params).toUri())
}Here there is a new uriComponentsBuilder constructed manually which is not taking any existing baseURI from the client into account but just overwriting the existing config. Not sure if this also might happen for other preconfigured values (like the auth header for example).
I suggest reverting #22512
Related Issues
May be related to
#22590 (same commit)