Skip to content

[BUG] [scala-sttp] the generated client fails to compile if request header is not a string #11942

@bgong-mdsol

Description

@bgong-mdsol

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

scala-sttp client generator doesn't generate doesn't generate Api properly when the request header is not a string.

openapi-generator version

The both version 6.0.0 and the latest master branch (6.0.x)

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Request Header
  version: "1.0.0"
paths:
  /test:
    get:
      summary: Empty Route
      parameters:
      - description: Gets user uuid.
        explode: false
        in: header
        name: user_uuid
        required: true
        schema:
          format: uuid
          type: string
        style: simple
      responses:
        "200":
          description: Good Request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReturnValue'
        "400":
          description: Bad Request.
components:
  schemas:
    ReturnValue:
      properties:
        name:
          type: string
Generation Details

Command line used for generation

openapi-generator-cli generate \
  -g scala-sttp \
  -i name_of_file.yaml \
  -p mainPackage=myPackage \
  -o myApi
Steps to reproduce

Generated class DefaultApi

  def rootGet(userUuid: UUID): Request[Either[ResponseException[String, Exception], ReturnValue], Nothing] =
    basicRequest
      .method(Method.GET, uri"$baseUrl/test")
      .contentType("application/json")
      .header("user_uuid", userUuid)
      .response(asJson[ReturnValue])

Compile Error:

DefaultApi.scala:39:8: overloaded method header with alternatives:
[error]   (k: String,ov: Option[String])sttp.client3.RequestT[sttp.client3.Identity,Either[String,String],Any] <and>
[error]   (k: String,v: String)sttp.client3.RequestT[sttp.client3.Identity,Either[String,String],Any] <and>
[error]   (h: sttp.model.Header,replaceExisting: Boolean)sttp.client3.RequestT[sttp.client3.Identity,Either[String,String],Any]
[error]  cannot be applied to (String, java.util.UUID)
[error]       .header("user_uuid", userUuid)
[error]        ^
Related issues/PRs
Suggest a fix

The generator should convert the value of header parameter to string.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions