[scala-sttp4] Model named Request shadows sttp.client4.Request

Merged
VI
3mo ago
+108-41

Fixes #24680.

A schema named Request makes the generated scala-sttp4 client fail to compile. Every generated API imports its models explicitly and then wildcard-imports sttp:

import org.openapitools.client.model.Request
import sttp.client4._

In Scala an explicit import outranks a wildcard import regardless of order, so Request resolves to the model, and the unqualified return type fails:

error: org.openapitools.client.model.Request does not take type parameters
  def predict(request: Request): Request[Either[ResponseException[String], Response]] =
                                 ^

Request is a common schema name for RPC-style APIs. The scala-sttp (sttp3) generator already emits the qualified sttp.client3.Request[..., Any] and is unaffected; this change brings scala-sttp4 in line by emitting sttp.client4.Request[...].

Tests: Sttp4CodegenTest#verifyModelNamedRequestDoesNotShadowSttpRequest with a new fixture (sttp4-request-model-name.yaml) declaring schemas named Request and Response, asserting both the explicit model import and the qualified return type. Verified by compiling the generated client for that spec, plus 13 real-world specs that declare a Request schema — all of which previously failed to compile and now succeed.

Samples regenerated via ./bin/generate-samples.sh bin/configs/scala-sttp4*.yaml; the change is confined to API return types, and both the scala-sttp4 and scala-sttp4-circe samples still compile. No generator options changed, so no doc export changes.

PR checklist

  • Read the contribution guidelines.
  • Built the project and updated samples; changes committed.
  • Filed against master.
  • Scala technical committee: @clasnake @jimschubert @shijinkui @ramzimaalej @chameleon82 @Bouillie

Summary by cubic

Qualifies API method return types in generated scala-sttp4 clients as sttp.client4.Request[...] to avoid collisions when a model is named Request. Fixes compile errors and aligns behavior with scala-sttp.

  • Bug Fixes
    • Added Sttp4CodegenTest#verifyModelNamedRequestDoesNotShadowSttpRequest with a spec using Request/Response models.
    • Regenerated scala-sttp4 and scala-sttp4-circe samples; both compile; no generator options or docs changed.