From 2fda6703af11c77a28ec0364d7d3c8a489a27d3b Mon Sep 17 00:00:00 2001 From: Nikhil Sulegaon Date: Tue, 28 Apr 2026 19:11:47 -0700 Subject: [PATCH 1/2] [Fix][scala-sttp] Skip model-package prefix when type name is already fully qualified --- .../languages/ScalaSttpClientCodegen.java | 7 ++----- .../3_0/scala-sttp-circe/petstore.yaml | 16 ++++++++++++++++ .../client/petstore/scala-sttp-circe/README.md | 1 + .../org/openapitools/client/api/StoreApi.scala | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java index 527ee58cc5fb..6f0141201afa 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java @@ -125,11 +125,6 @@ public ScalaSttpClientCodegen() { additionalProperties.put("fnCamelize", new CamelizeLambda(false)); additionalProperties.put("fnEnumEntry", new EnumEntryLambda()); -// importMapping.remove("Seq"); -// importMapping.remove("List"); -// importMapping.remove("Set"); -// importMapping.remove("Map"); - // TODO: there is no specific sttp mapping. All Scala Type mappings should be in AbstractScala typeMapping = new HashMap<>(); typeMapping.put("array", "Seq"); @@ -171,6 +166,8 @@ public void processOpts() { String jsonLibrary = JSON_LIBRARY_PROPERTY.getValue(additionalProperties); String jsonValueClass = "circe".equals(jsonLibrary) ? "io.circe.Json" : "org.json4s.JValue"; + importMapping.put(jsonValueClass, jsonValueClass); + typeMapping.put("object", jsonValueClass); typeMapping.put("AnyType", jsonValueClass); diff --git a/modules/openapi-generator/src/test/resources/3_0/scala-sttp-circe/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/scala-sttp-circe/petstore.yaml index 65c92603c2bf..ea571731a106 100644 --- a/modules/openapi-generator/src/test/resources/3_0/scala-sttp-circe/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/scala-sttp-circe/petstore.yaml @@ -283,6 +283,22 @@ paths: description: file to upload type: string format: binary + /store/stats: + get: + tags: + - store + summary: Returns store statistics as a free-form JSON object + description: Returns arbitrary store metrics whose schema is not fixed + operationId: getStoreStats + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: object + security: + - api_key: [] /store/inventory: get: tags: diff --git a/samples/client/petstore/scala-sttp-circe/README.md b/samples/client/petstore/scala-sttp-circe/README.md index 3455cf578d1c..0a7a9b2de1ff 100644 --- a/samples/client/petstore/scala-sttp-circe/README.md +++ b/samples/client/petstore/scala-sttp-circe/README.md @@ -78,6 +78,7 @@ Class | Method | HTTP request | Description *StoreApi* | **deleteOrder** | **DELETE** /store/order/${orderId} | Delete purchase order by ID *StoreApi* | **getInventory** | **GET** /store/inventory | Returns pet inventories by status *StoreApi* | **getOrderById** | **GET** /store/order/${orderId} | Find purchase order by ID +*StoreApi* | **getStoreStats** | **GET** /store/stats | Returns store statistics as a free-form JSON object *StoreApi* | **placeOrder** | **POST** /store/order | Place an order for a pet *UserApi* | **createUser** | **POST** /user | Create user *UserApi* | **createUsersWithArrayInput** | **POST** /user/createWithArray | Creates list of users with given input array diff --git a/samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/api/StoreApi.scala b/samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/api/StoreApi.scala index efddc39a690b..bc638e59f829 100644 --- a/samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/api/StoreApi.scala +++ b/samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/api/StoreApi.scala @@ -12,6 +12,7 @@ package org.openapitools.client.api import org.openapitools.client.model.Order +import io.circe.Json import org.openapitools.client.core.JsonSupport._ import sttp.client3._ import sttp.model.Method @@ -72,6 +73,23 @@ class StoreApi(baseUrl: String) { .contentType("application/json") .response(asJson[Order]) + /** + * Returns arbitrary store metrics whose schema is not fixed + * + * Expected answers: + * code 200 : io.circe.Json (successful operation) + * + * Available security schemes: + * api_key (apiKey) + */ + def getStoreStats(apiKeyHeader: String)( +): Request[Either[ResponseException[String, Exception], io.circe.Json], Any] = + basicRequest + .method(Method.GET, uri"$baseUrl/store/stats") + .contentType("application/json") + .header("api_key", apiKeyHeader) + .response(asJson[io.circe.Json]) + /** * * From 4d6de321df9315d046ff167dba6e771bd0f765c4 Mon Sep 17 00:00:00 2001 From: Nikhil Sulegaon Date: Tue, 28 Apr 2026 19:29:38 -0700 Subject: [PATCH 2/2] Refactor --- .../codegen/languages/ScalaSttpClientCodegen.java | 9 +++++---- .../scala/org/openapitools/client/api/StoreApi.scala | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java index 6f0141201afa..bfa824392e8d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttpClientCodegen.java @@ -165,11 +165,12 @@ public void processOpts() { modelPackage = PACKAGE_PROPERTY.getModelPackage(additionalProperties); String jsonLibrary = JSON_LIBRARY_PROPERTY.getValue(additionalProperties); - String jsonValueClass = "circe".equals(jsonLibrary) ? "io.circe.Json" : "org.json4s.JValue"; - importMapping.put(jsonValueClass, jsonValueClass); + String jsonValueFqn = "circe".equals(jsonLibrary) ? "io.circe.Json" : "org.json4s.JValue"; + String jsonValueSimpleName = jsonValueFqn.substring(jsonValueFqn.lastIndexOf('.') + 1); - typeMapping.put("object", jsonValueClass); - typeMapping.put("AnyType", jsonValueClass); + typeMapping.put("object", jsonValueSimpleName); + typeMapping.put("AnyType", jsonValueSimpleName); + importMapping.put(jsonValueSimpleName, jsonValueFqn); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt")); diff --git a/samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/api/StoreApi.scala b/samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/api/StoreApi.scala index bc638e59f829..b95fda527181 100644 --- a/samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/api/StoreApi.scala +++ b/samples/client/petstore/scala-sttp-circe/src/main/scala/org/openapitools/client/api/StoreApi.scala @@ -11,8 +11,8 @@ */ package org.openapitools.client.api -import org.openapitools.client.model.Order import io.circe.Json +import org.openapitools.client.model.Order import org.openapitools.client.core.JsonSupport._ import sttp.client3._ import sttp.model.Method @@ -77,18 +77,18 @@ class StoreApi(baseUrl: String) { * Returns arbitrary store metrics whose schema is not fixed * * Expected answers: - * code 200 : io.circe.Json (successful operation) + * code 200 : Json (successful operation) * * Available security schemes: * api_key (apiKey) */ def getStoreStats(apiKeyHeader: String)( -): Request[Either[ResponseException[String, Exception], io.circe.Json], Any] = +): Request[Either[ResponseException[String, Exception], Json], Any] = basicRequest .method(Method.GET, uri"$baseUrl/store/stats") .contentType("application/json") .header("api_key", apiKeyHeader) - .response(asJson[io.circe.Json]) + .response(asJson[Json]) /** *