[BUG][KOTLIN] Dependencies whose types are in the client's public API are declared as implementation

Đang mở
#25,576 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
kotlin

Hướng nghiên cứu

Start with kotlin-client/build.gradle.mustache and compare its dependency scopes with the multiplatform and jvm-microprofile declarations mentioned in the issue. Check which generated public API types come from those dependencies, using the listed Gradle consumer reproducer and library variants as a guide. Change the exposed dependencies to api, then confirm the consumer compiles for the reproducer and affected options.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

kotlin-client/build.gradle.mustache declares the HTTP, JSON and date libraries as implementation, although their types are part of the generated client's public API. A consumer doesn't get them on its compile classpath, so code that touches those members doesn't compile. With the default jvm-okhttp4, every Api takes client: Call.Factory, ApiClient.defaultClient is an OkHttpClient and Serializer.moshi is a Moshi; in jvm-retrofit2, jvm-vertx and jvm-spring-webclient even getPetById returns such a type.

multiplatform already declares Ktor as api, and jvm-microprofile does the same for Mutiny.

openapi-generator version

7.27.0, and master at d15b0164 (7.28.0-SNAPSHOT).

OpenAPI declaration file content or url

modules/openapi-generator/src/test/resources/3_0/petstore.yaml from this repo (validate reports no issues).

Generation Details
java -jar openapi-generator-cli.jar generate -g kotlin -i petstore.yaml -o client
Steps to reproduce

A consumer next to client:

// settings.gradle
includeBuild('../client')
// build.gradle
plugins { id 'org.jetbrains.kotlin.jvm' version '2.4.0' }
repositories { mavenCentral() }
dependencies { implementation 'org.openapitools:kotlin-client:1.0.0' }
import org.openapitools.client.apis.PetApi
import org.openapitools.client.infrastructure.ApiClient
import org.openapitools.client.infrastructure.Serializer

fun main() {
    val client = ApiClient.defaultClient.newBuilder().build()
    println(PetApi("http://localhost", client))
    println(Serializer.moshi.adapter(String::class.java).toJson("x"))
}

gradle compileKotlin on Gradle 8.14 and 9.8.2:

e: Cannot access class 'okhttp3.OkHttpClient'. Check your module classpath for missing or conflicting dependencies.
e: Cannot access class 'okhttp3.Call.Factory'. Check your module classpath for missing or conflicting dependencies.
e: Cannot access class 'com.squareup.moshi.Moshi'. Check your module classpath for missing or conflicting dependencies.

Expected: it compiles. Adding okhttp and moshi-kotlin to the consumer works around it.

Other options, same consumer setup with one call each (generated by master, Gradle 8.14):

options call missing class
moshiCodeGen=true Serializer.moshi.adapter(...) com.squareup.moshi.Moshi
serializationLibrary=gson Serializer.gson.toJson(...) com.google.gson.Gson
serializationLibrary=jackson Serializer.jacksonObjectMapper.writeValueAsString(...) com.fasterxml.jackson.databind.ObjectMapper
serializationLibrary=jackson, useJackson3=true Serializer.jacksonObjectMapper.writeValueAsString(...) tools.jackson.databind.json.JsonMapper
serializationLibrary=kotlinx_serialization Serializer.kotlinxSerializationJson kotlinx.serialization.json.Json
dateLibrary=threetenbp StoreApi().getOrderById(1L).shipDate?.year org.threeten.bp.OffsetDateTime
library=jvm-retrofit2 ApiClient().createService(PetApi::class.java).getPetById(1L).execute() retrofit2.Call
library=jvm-retrofit2 ApiClient().getTokenEndPoint()?.setClientId("x") org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder
library=jvm-retrofit2, useRxJava3=true ...getPetById(1L).blockingGet() io.reactivex.rxjava3.core.Single
library=jvm-ktor, jackson PetApi(httpClientConfig = { it.expectSuccess = true }) io.ktor.client.HttpClientConfig
library=jvm-vertx api.getPetById(1L).onSuccess { } io.vertx.core.Future
library=jvm-spring-webclient PetApi(url).getPetById(1L).block() reactor.core.publisher.Mono
library=jvm-spring-restclient, useSpringBoot3=true Serializer.jacksonObjectMapper.writeValueAsString(...) com.fasterxml.jackson.databind.ObjectMapper

I didn't build the deprecated jvm-volley, which needs the Android SDK. Its GsonRequest is public and extends com.android.volley.Request, with volley and gson also declared as implementation.

Related issues/PRs

#14113 is about the scope of another dependency (slf4j-simple).

Suggest a fix

Use api for the libraries whose types the client exposes: moshi-kotlin, moshi-adapters and moshi, gson, jackson-module-kotlin (Jackson 2 and 3), kotlinx-serialization-json, threetenbp, okhttp, retrofit, the oltu client, rxjava, ktor-client-core, vertx-core, spring-boot-starter-webflux and spring-boot-starter-web. With that change the reproducer and every call in the table compile on Gradle 8.14 and 9.8.2. The Kotlin JVM plugin already provides the api configuration.

Ngôn ngữ chính
Java
Star
26.9k
Fork
7.8k
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
180

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của OpenAPITools/openapi-generator

Tất cả issue của OpenAPITools/openapi-generator

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.