openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

Feature/update kotlin dependecies template

Open Marek00Malik opened this issue 2 years ago • 3 comments

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:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    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 ./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 ]

Marek00Malik avatar Jul 21 '22 09:07 Marek00Malik

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

4brunu avatar Jul 27 '22 09:07 4brunu

Excelent work! I'm looking forward for this. Is it real updated Ktor will in in release 6.1.0?

mCzolko avatar Jul 29 '22 10:07 mCzolko

@4brunu updated to master and updated sample templest

Marek00Malik avatar Aug 09 '22 12:08 Marek00Malik

Would it be possible to get this merged in?

scottkennedy avatar Aug 12 '22 23:08 scottkennedy

CI failure not related to the change: https://github.com/OpenAPITools/openapi-generator/runs/8072408542?check_suite_focus=true

wing328 avatar Sep 04 '22 15:09 wing328

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.

frichez avatar Oct 04 '22 11:10 frichez

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).

Marek00Malik avatar Oct 06 '22 19:10 Marek00Malik

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 avatar Oct 07 '22 04:10 frichez

@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.

Marek00Malik avatar Oct 07 '22 18:10 Marek00Malik

@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)
}

Marek00Malik avatar Oct 11 '22 21:10 Marek00Malik

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 ?

frichez avatar Oct 21 '22 14:10 frichez

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.

Marek00Malik avatar Oct 22 '22 11:10 Marek00Malik

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 avatar Oct 22 '22 16:10 frichez

@frichez https://github.com/OpenAPITools/openapi-generator/pull/14045

Marek00Malik avatar Nov 16 '22 20:11 Marek00Malik