Skip to content

[BUG][scala-sttp4] A schema named Request shadows sttp.client4.Request and the generated client does not compile #24680

Description

@vivekmahajan

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

If a spec declares a schema named Request, the generated scala-sttp4 client does not 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 has higher precedence than a wildcard import, regardless of order, so Request resolves to the model. The operation's return type is emitted unqualified as Request[...], which then 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, so this is easy to hit.

The scala-sttp (sttp3) generator emits the qualified form sttp.client3.Request[..., Any] and is unaffected.

openapi-generator version

7.25.0-SNAPSHOT (current master).

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: sttp4 model named Request
  version: 1.0.0
paths:
  /predict:
    post:
      operationId: predict
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Request'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Response'
components:
  schemas:
    Request:
      type: object
      required: [userId]
      properties:
        userId: {type: string}
    Response:
      type: object
      properties:
        score: {type: number}
Generation Details
java -jar openapi-generator-cli.jar generate -g scala-sttp4 -i spec.yaml -o out
Steps to reproduce
  1. Generate with the command above.
  2. sbt compile in the output directory.
  3. Compilation fails with Request does not take type parameters.
Suggest a fix

Qualify the return type in api.mustache as sttp.client4.Request[...], matching what scala-sttp already does.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions