Skip to content

[BUG][Scala][sttp] Generated Code fails to compile when query parameters contain format . #10007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 of 6 tasks
i10416 opened this issue Jul 22, 2021 · 0 comments
Open
5 of 6 tasks

Comments

@i10416
Copy link

i10416 commented Jul 22, 2021

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

When I have the parameter named format, the code below is generated.
The format in argument overrides the implicit value format from import org.openapitools.client.core.JsonSupport._, which causes compile to fail.

openapi-generator version
  • "org.openapitools" % "sbt-openapi-generator" % "5.0.1"
  • "com.softwaremill.sttp.client" %% "core" % "2.2.0"
  • "com.softwaremill.sttp.client" %% "json4s" % "2.2.0"
  • "org.json4s" %% "json4s-jackson" % "3.6.8"
OpenAPI declaration file content or url
paths:
  '/api':
    get:
      parameters:
      - name:  "format"
        in: "query"
        description: "format"
        required: true
        schema:
          type: string
          default: json
Generation Details
package org.openapitools.client.api

import org.openapitools.client.model.SearchResponse
import org.openapitools.client.core.JsonSupport._
import sttp.client._
import sttp.model.Method
class DefaultApi(baseUrl: String) {
  /**
   * 
   * @param format format
   */

  // This  `format` in argument overrides implicit value `format`.
  def apiGet(format: String): Request[Either[ResponseError[Exception], MyResponse], Nothing] =
    basicRequest
      .method(Method.GET, uri"$baseUrl/api?format=${ format }")
      .contentType("application/json")
      .response(asJson[MyResponse]) // No org.json4s.Formats found.

}
Steps to reproduce
  • Prepare openapi.yaml which contains path with format in query parameters.
  • Generate Scala sttp client code by sbt-openapi-generator.
Related issues/PRs

OAI/OpenAPI-Specification#2298

Suggest a fix

Workaround:

openapi-generator/modules/openapi-generator/src/main/resources/scala-sttp/api.mustache

-  import {{invokerPackage}}.JsonSupport._
+ import {{invokerPackage}}.JsonSupport.{format=>_format,serialization=>_serialization,_}

I think if it is possible to give alias to a parameter, this problem can be solved.

@i10416 i10416 changed the title [BUG][Scala][sttp] [BUG][Scala][sttp] Generated Code fails to compile when query parameters contain format . Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant