openapi-generator
openapi-generator copied to clipboard
Feature/update kotlin dependecies template
According to #11994, this change is updating Kotlin client dependencies, Kotlin version and what version of Ktor is used (2.0.3).
PR checklist
- [x] Read the contribution guidelines.
- [x] 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.
- [x] Run the following to build the project and update samples:
Commit all changed files. 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./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. - [x] File the PR against the correct branch:
master
(6.1.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks) - [x] If your PR is targeting a particular programming language, @mention the [@jimschubert, @dr4ke616 @karismann @Zomzog @andrewemery @4brunu @yutaka0m ]
Can you please fix the conflicts with the master branch?
Can you also run the following commands and commit the changes?
./mvnw clean package
./bin/generate-samples.sh ./bin/generate-samples.sh bin/configs/kotlin*
Thanks
Excelent work! I'm looking forward for this. Is it real updated Ktor will in in release 6.1.0?
@4brunu updated to master and updated sample templest
Would it be possible to get this merged in?
CI failure not related to the change: https://github.com/OpenAPITools/openapi-generator/runs/8072408542?check_suite_focus=true
Hi @Marek00Malik I'using multiplatform library and now due to this change I'm not more able to send a request in json format using negotiation/json serialization plugin.
Previously jsonRequest() method was setting the content-type header to json. It is not more the case and the request is not serialized : "If you expect serialized body, please check that you have installed the corresponding plugin(like ContentNegotiation
) and set Content-Type
header."
Do I miss something ? Thks.
Hey @frichez, in general, this new plugin should be able to send any request with application/json as the content type. Unfortunately, I'm not able to sit on this and add the header by default as I'm low on free time now (production release coming soon).
Hi @Marek00Malik, thks for the answer. You can have a look in jsonRequest(), application/json
header was set there before this change (multiplatform/infrastructure/ApiClient.kt.mustache). I'm using grade to build my project so I tried to modify ApiClient.kt.mustache with the content of the previous jsonRequest() method. Unfortunately setting templateDir in openApiGenerate grade section has not effect :-(, gradle complains if the template dir doesn't exist but don't use it as custom template dir. As fallback I had to used the generator as command file. I see an issue for this created in 2020...
@frichez I've pushed a PR that adds this content type header. Please review if. If you would find any improvement feel free to contribute.
@frichez so I've checked in the source code how the serializer is being used I noticed that in the multiplatform case the json serializer is using the json contentType.
private val clientConfig: (HttpClientConfig<*>) -> Unit by lazy {
{
it.install(ContentNegotiation) { json(jsonBlock) }
httpClientConfig?.invoke(it)
}
}
@OptIn(ExperimentalSerializationApi::class)
public fun Configuration.json(
json: Json = DefaultJson,
contentType: ContentType = ContentType.Application.Json
) {
serialization(contentType, json)
}
Thks @Marek00Malik. I get the following error :
Fail to prepare request body for sending.
The body type is: class org.openapitools.client.models.ClickRequest, with Content-Type: null.
If you expect serialized body, please check that you have installed the corresponding plugin(like ContentNegotiation
) and set Content-Type
header.
Do I need to add some code in my client (how to set the content-type json there?) or is it an issue in openapi generator ?
Hey @frichez from the examples that are in the repo you can see you don't need to add anything except what is in the dependencies. See this example that is used for validating the multiplatform setup. If you have an issue, a sample project would be handy to verify your issue.
hi @Marek00Malik I tried the example you mentioned but I contains no unit tests. I added following code in samples/client/petstore/kotlin-multiplatform/src/jvmTest/kotlin/util/PetStoreTest.kt and I get the same error as I have in my project:
If you expect serialized body, please check that you have installed the corresponding plugin(like ContentNegotiation
) and set Content-Type
header.
java.lang.IllegalStateException: Fail to prepare request body for sending.
The body type is: class org.openapitools.client.models.Pet (Kotlin reflection is not available), with Content-Type: null.
package util
import org.junit.Test
import org.openapitools.client.apis.PetApi
import org.openapitools.client.models.Pet
class PetStoreTest {
@Test
fun addPet() = runTest {
val mainApi = PetApi()
println(mainApi.addPet(Pet("olya", emptyList())).body())
}
}
@frichez https://github.com/OpenAPITools/openapi-generator/pull/14045