OpenAPITools / OpenAPITools/openapi-generator
[BUG][Scala][sttp] Generated Code fails to compile when query parameters contain `format` .
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
formatin query parameters. - Generate Scala sttp client code by sbt-openapi-generator.
Related issues/PRs
https://github.com/OAI/OpenAPI-Specification/issues/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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with openapi-generator/modules/openapi-generator/src/main/resources/scala-sttp/api.mustache and reproduce generation using an OpenAPI query parameter named format. Check how the generated import conflicts with the method parameter, then verify that the generated Scala sttp client compiles without that conflict.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100