From ff30df92f856f631c760c0bf9b4c22978c70f6f5 Mon Sep 17 00:00:00 2001 From: Boris Smidt Date: Tue, 8 Feb 2022 06:46:42 +0100 Subject: [PATCH] Upgrade sttp generator to sttp3 (#11260) Remove CIRCE_VERSION from generator because it is taken in as a transitive dependency of ` "com.softwaremill.sttp.client3" %% "json4s" % "3.3.18"` Co-authored-by: boris --- .../languages/ScalaSttpClientCodegen.java | 9 ++++----- .../src/main/resources/scala-sttp/api.mustache | 4 ++-- .../resources/scala-sttp/build.sbt.mustache | 9 +++------ .../resources/scala-sttp/jsonSupport.mustache | 4 ++-- .../project/build.properties.mustache | 2 +- samples/client/petstore/scala-sttp/build.sbt | 4 ++-- .../scala-sttp/project/build.properties | 2 +- .../org/openapitools/client/api/PetApi.scala | 18 +++++++++--------- .../org/openapitools/client/api/StoreApi.scala | 10 +++++----- .../org/openapitools/client/api/UserApi.scala | 18 +++++++++--------- .../openapitools/client/core/JsonSupport.scala | 2 +- 11 files changed, 39 insertions(+), 43 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 2a359cb0e69..a31d41ff4a8 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 @@ -44,17 +44,16 @@ import static org.openapitools.codegen.utils.StringUtils.camelize; public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements CodegenConfig { private static final StringProperty STTP_CLIENT_VERSION = new StringProperty("sttpClientVersion", "The version of " + - "sttp client", "2.2.9"); + "sttp client", "3.3.18"); private static final BooleanProperty USE_SEPARATE_ERROR_CHANNEL = new BooleanProperty("separateErrorChannel", "Whether to return response as " + "F[Either[ResponseError[ErrorType], ReturnType]]] or to flatten " + "response's error raising them through enclosing monad (F[ReturnType]).", true); private static final StringProperty JODA_TIME_VERSION = new StringProperty("jodaTimeVersion", "The version of " + - "joda-time library", "2.10.10"); + "joda-time library", "2.10.13"); private static final StringProperty JSON4S_VERSION = new StringProperty("json4sVersion", "The version of json4s " + "library", "3.6.11"); - private static final StringProperty CIRCE_VERSION = new StringProperty("circeVersion", "The version of circe " + - "library", "0.13.0"); + private static final JsonLibraryProperty JSON_LIBRARY_PROPERTY = new JsonLibraryProperty(); public static final String DEFAULT_PACKAGE_NAME = "org.openapitools.client"; @@ -62,7 +61,7 @@ public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements Code private static final List> properties = Arrays.asList( STTP_CLIENT_VERSION, USE_SEPARATE_ERROR_CHANNEL, JODA_TIME_VERSION, - JSON4S_VERSION, CIRCE_VERSION, JSON_LIBRARY_PROPERTY, PACKAGE_PROPERTY); + JSON4S_VERSION, JSON_LIBRARY_PROPERTY, PACKAGE_PROPERTY); private final Logger LOGGER = LoggerFactory.getLogger(ScalaSttpClientCodegen.class); diff --git a/modules/openapi-generator/src/main/resources/scala-sttp/api.mustache b/modules/openapi-generator/src/main/resources/scala-sttp/api.mustache index 28cf170922d..f7d5ba6f825 100644 --- a/modules/openapi-generator/src/main/resources/scala-sttp/api.mustache +++ b/modules/openapi-generator/src/main/resources/scala-sttp/api.mustache @@ -5,7 +5,7 @@ package {{package}} import {{import}} {{/imports}} import {{invokerPackage}}.JsonSupport._ -import sttp.client._ +import sttp.client3._ import sttp.model.Method {{#operations}} @@ -20,7 +20,7 @@ class {{classname}}(baseUrl: String) { {{#javadocRenderer}} {{>javadoc}} {{/javadocRenderer}} - def {{operationId}}({{>methodParameters}}): Request[{{#separateErrorChannel}}Either[ResponseError[Exception], {{>operationReturnType}}]{{/separateErrorChannel}}{{^separateErrorChannel}}{{>operationReturnType}}{{/separateErrorChannel}}, Nothing] = + def {{operationId}}({{>methodParameters}}): Request[{{#separateErrorChannel}}Either[ResponseException[String, Exception], {{>operationReturnType}}]{{/separateErrorChannel}}{{^separateErrorChannel}}{{>operationReturnType}}{{/separateErrorChannel}}, Nothing] = basicRequest .method(Method.{{httpMethod.toUpperCase}}, uri"$baseUrl{{{path}}}{{#queryParams.0}}?{{#queryParams}}{{baseName}}=${ {{{paramName}}} }{{^-last}}&{{/-last}}{{/queryParams}}{{/queryParams.0}}{{#isApiKey}}{{#isKeyInQuery}}{{^queryParams.0}}?{{/queryParams.0}}{{#queryParams.0}}&{{/queryParams.0}}{{keyParamName}}=${apiKey.value}&{{/isKeyInQuery}}{{/isApiKey}}") .contentType({{#consumes.0}}"{{{mediaType}}}"{{/consumes.0}}{{^consumes}}"application/json"{{/consumes}}){{#headerParams}} diff --git a/modules/openapi-generator/src/main/resources/scala-sttp/build.sbt.mustache b/modules/openapi-generator/src/main/resources/scala-sttp/build.sbt.mustache index 3072a54368c..06f8a7845db 100644 --- a/modules/openapi-generator/src/main/resources/scala-sttp/build.sbt.mustache +++ b/modules/openapi-generator/src/main/resources/scala-sttp/build.sbt.mustache @@ -6,19 +6,16 @@ scalaVersion := "2.13.5" crossScalaVersions := Seq(scalaVersion.value, "2.12.13") libraryDependencies ++= Seq( - "com.softwaremill.sttp.client" %% "core" % "{{sttpClientVersion}}", + "com.softwaremill.sttp.client3" %% "core" % "{{sttpClientVersion}}", {{#joda}} "joda-time" % "joda-time" % "{{jodaTimeVersion}}", {{/joda}} {{#json4s}} - "com.softwaremill.sttp.client" %% "json4s" % "{{sttpClientVersion}}", + "com.softwaremill.sttp.client3" %% "json4s" % "{{sttpClientVersion}}", "org.json4s" %% "json4s-jackson" % "{{json4sVersion}}" {{/json4s}} {{#circe}} - "com.softwaremill.sttp.client" %% "circe" % "{{sttpClientVersion}}", - "io.circe" %% "circe-core" % "{{circeVersion}}", - "io.circe" %% "circe-generic" % "{{circeVersion}}", - "io.circe" %% "circe-parser" % "{{circeVersion}}" + "com.softwaremill.sttp.client3" %% "circe" % "{{sttpClientVersion}}" {{/circe}} ) diff --git a/modules/openapi-generator/src/main/resources/scala-sttp/jsonSupport.mustache b/modules/openapi-generator/src/main/resources/scala-sttp/jsonSupport.mustache index 57c3ab4204c..cfa33bd834a 100644 --- a/modules/openapi-generator/src/main/resources/scala-sttp/jsonSupport.mustache +++ b/modules/openapi-generator/src/main/resources/scala-sttp/jsonSupport.mustache @@ -6,7 +6,7 @@ import {{modelPackage}}._ {{/models.0}} {{#json4s}} import org.json4s._ -import sttp.client.json4s.SttpJson4sApi +import sttp.client3.json4s.SttpJson4sApi import scala.reflect.ClassTag object JsonSupport extends SttpJson4sApi { @@ -42,7 +42,7 @@ object JsonSupport extends SttpJson4sApi { {{#circe}} import io.circe.{Decoder, Encoder} import io.circe.generic.AutoDerivation -import sttp.client.circe.SttpCirceApi +import sttp.client3.circe.SttpCirceApi object JsonSupport extends SttpCirceApi with AutoDerivation with DateSerializers { {{#models}}{{#model}}{{#hasEnums}}{{#vars}}{{#isEnum}} diff --git a/modules/openapi-generator/src/main/resources/scala-sttp/project/build.properties.mustache b/modules/openapi-generator/src/main/resources/scala-sttp/project/build.properties.mustache index e67343ae796..3161d2146c6 100644 --- a/modules/openapi-generator/src/main/resources/scala-sttp/project/build.properties.mustache +++ b/modules/openapi-generator/src/main/resources/scala-sttp/project/build.properties.mustache @@ -1 +1 @@ -sbt.version=1.5.0 +sbt.version=1.6.1 diff --git a/samples/client/petstore/scala-sttp/build.sbt b/samples/client/petstore/scala-sttp/build.sbt index 1b13385dba1..e50f4ab4879 100644 --- a/samples/client/petstore/scala-sttp/build.sbt +++ b/samples/client/petstore/scala-sttp/build.sbt @@ -6,8 +6,8 @@ scalaVersion := "2.13.5" crossScalaVersions := Seq(scalaVersion.value, "2.12.13") libraryDependencies ++= Seq( - "com.softwaremill.sttp.client" %% "core" % "2.2.9", - "com.softwaremill.sttp.client" %% "json4s" % "2.2.9", + "com.softwaremill.sttp.client3" %% "core" % "3.3.18", + "com.softwaremill.sttp.client3" %% "json4s" % "3.3.18", "org.json4s" %% "json4s-jackson" % "3.6.11" ) diff --git a/samples/client/petstore/scala-sttp/project/build.properties b/samples/client/petstore/scala-sttp/project/build.properties index e67343ae796..3161d2146c6 100644 --- a/samples/client/petstore/scala-sttp/project/build.properties +++ b/samples/client/petstore/scala-sttp/project/build.properties @@ -1 +1 @@ -sbt.version=1.5.0 +sbt.version=1.6.1 diff --git a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/PetApi.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/PetApi.scala index 7bed7d54f33..94ea794967c 100644 --- a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/PetApi.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/PetApi.scala @@ -15,7 +15,7 @@ import org.openapitools.client.model.ApiResponse import java.io.File import org.openapitools.client.model.Pet import org.openapitools.client.core.JsonSupport._ -import sttp.client._ +import sttp.client3._ import sttp.model.Method object PetApi { @@ -33,7 +33,7 @@ class PetApi(baseUrl: String) { * @param pet Pet object that needs to be added to the store */ def addPet(pet: Pet -): Request[Either[ResponseError[Exception], Pet], Nothing] = +): Request[Either[ResponseException[String, Exception], Pet], Nothing] = basicRequest .method(Method.POST, uri"$baseUrl/pet") .contentType("application/json") @@ -48,7 +48,7 @@ class PetApi(baseUrl: String) { * @param apiKey */ def deletePet(petId: Long, apiKey: Option[String] = None -): Request[Either[ResponseError[Exception], Unit], Nothing] = +): Request[Either[ResponseException[String, Exception], Unit], Nothing] = basicRequest .method(Method.DELETE, uri"$baseUrl/pet/${petId}") .contentType("application/json") @@ -65,7 +65,7 @@ class PetApi(baseUrl: String) { * @param status Status values that need to be considered for filter */ def findPetsByStatus(status: Seq[String] -): Request[Either[ResponseError[Exception], Seq[Pet]], Nothing] = +): Request[Either[ResponseException[String, Exception], Seq[Pet]], Nothing] = basicRequest .method(Method.GET, uri"$baseUrl/pet/findByStatus?status=${ status }") .contentType("application/json") @@ -81,7 +81,7 @@ class PetApi(baseUrl: String) { * @param tags Tags to filter by */ def findPetsByTags(tags: Seq[String] -): Request[Either[ResponseError[Exception], Seq[Pet]], Nothing] = +): Request[Either[ResponseException[String, Exception], Seq[Pet]], Nothing] = basicRequest .method(Method.GET, uri"$baseUrl/pet/findByTags?tags=${ tags }") .contentType("application/json") @@ -101,7 +101,7 @@ class PetApi(baseUrl: String) { * @param petId ID of pet to return */ def getPetById(apiKey: String)(petId: Long -): Request[Either[ResponseError[Exception], Pet], Nothing] = +): Request[Either[ResponseException[String, Exception], Pet], Nothing] = basicRequest .method(Method.GET, uri"$baseUrl/pet/${petId}") .contentType("application/json") @@ -118,7 +118,7 @@ class PetApi(baseUrl: String) { * @param pet Pet object that needs to be added to the store */ def updatePet(pet: Pet -): Request[Either[ResponseError[Exception], Pet], Nothing] = +): Request[Either[ResponseException[String, Exception], Pet], Nothing] = basicRequest .method(Method.PUT, uri"$baseUrl/pet") .contentType("application/json") @@ -134,7 +134,7 @@ class PetApi(baseUrl: String) { * @param status Updated status of the pet */ def updatePetWithForm(petId: Long, name: Option[String] = None, status: Option[String] = None -): Request[Either[ResponseError[Exception], Unit], Nothing] = +): Request[Either[ResponseException[String, Exception], Unit], Nothing] = basicRequest .method(Method.POST, uri"$baseUrl/pet/${petId}") .contentType("application/x-www-form-urlencoded") @@ -153,7 +153,7 @@ class PetApi(baseUrl: String) { * @param file file to upload */ def uploadFile(petId: Long, additionalMetadata: Option[String] = None, file: Option[File] = None -): Request[Either[ResponseError[Exception], ApiResponse], Nothing] = +): Request[Either[ResponseException[String, Exception], ApiResponse], Nothing] = basicRequest .method(Method.POST, uri"$baseUrl/pet/${petId}/uploadImage") .contentType("multipart/form-data") diff --git a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/StoreApi.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/StoreApi.scala index e6ffcaae629..b961955e884 100644 --- a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/StoreApi.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/StoreApi.scala @@ -13,7 +13,7 @@ package org.openapitools.client.api import org.openapitools.client.model.Order import org.openapitools.client.core.JsonSupport._ -import sttp.client._ +import sttp.client3._ import sttp.model.Method object StoreApi { @@ -33,7 +33,7 @@ class StoreApi(baseUrl: String) { * @param orderId ID of the order that needs to be deleted */ def deleteOrder(orderId: String -): Request[Either[ResponseError[Exception], Unit], Nothing] = +): Request[Either[ResponseException[String, Exception], Unit], Nothing] = basicRequest .method(Method.DELETE, uri"$baseUrl/store/order/${orderId}") .contentType("application/json") @@ -49,7 +49,7 @@ class StoreApi(baseUrl: String) { * api_key (apiKey) */ def getInventory(apiKey: String)( -): Request[Either[ResponseError[Exception], Map[String, Int]], Nothing] = +): Request[Either[ResponseException[String, Exception], Map[String, Int]], Nothing] = basicRequest .method(Method.GET, uri"$baseUrl/store/inventory") .contentType("application/json") @@ -67,7 +67,7 @@ class StoreApi(baseUrl: String) { * @param orderId ID of pet that needs to be fetched */ def getOrderById(orderId: Long -): Request[Either[ResponseError[Exception], Order], Nothing] = +): Request[Either[ResponseException[String, Exception], Order], Nothing] = basicRequest .method(Method.GET, uri"$baseUrl/store/order/${orderId}") .contentType("application/json") @@ -81,7 +81,7 @@ class StoreApi(baseUrl: String) { * @param order order placed for purchasing the pet */ def placeOrder(order: Order -): Request[Either[ResponseError[Exception], Order], Nothing] = +): Request[Either[ResponseException[String, Exception], Order], Nothing] = basicRequest .method(Method.POST, uri"$baseUrl/store/order") .contentType("application/json") diff --git a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala index 5cc17ea09c1..0b7b0812e92 100644 --- a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/api/UserApi.scala @@ -14,7 +14,7 @@ package org.openapitools.client.api import java.time.OffsetDateTime import org.openapitools.client.model.User import org.openapitools.client.core.JsonSupport._ -import sttp.client._ +import sttp.client3._ import sttp.model.Method object UserApi { @@ -36,7 +36,7 @@ class UserApi(baseUrl: String) { * @param user Created user object */ def createUser(apiKey: String)(user: User -): Request[Either[ResponseError[Exception], Unit], Nothing] = +): Request[Either[ResponseException[String, Exception], Unit], Nothing] = basicRequest .method(Method.POST, uri"$baseUrl/user") .contentType("application/json") @@ -54,7 +54,7 @@ class UserApi(baseUrl: String) { * @param user List of user object */ def createUsersWithArrayInput(apiKey: String)(user: Seq[User] -): Request[Either[ResponseError[Exception], Unit], Nothing] = +): Request[Either[ResponseException[String, Exception], Unit], Nothing] = basicRequest .method(Method.POST, uri"$baseUrl/user/createWithArray") .contentType("application/json") @@ -72,7 +72,7 @@ class UserApi(baseUrl: String) { * @param user List of user object */ def createUsersWithListInput(apiKey: String)(user: Seq[User] -): Request[Either[ResponseError[Exception], Unit], Nothing] = +): Request[Either[ResponseException[String, Exception], Unit], Nothing] = basicRequest .method(Method.POST, uri"$baseUrl/user/createWithList") .contentType("application/json") @@ -93,7 +93,7 @@ class UserApi(baseUrl: String) { * @param username The name that needs to be deleted */ def deleteUser(apiKey: String)(username: String -): Request[Either[ResponseError[Exception], Unit], Nothing] = +): Request[Either[ResponseException[String, Exception], Unit], Nothing] = basicRequest .method(Method.DELETE, uri"$baseUrl/user/${username}") .contentType("application/json") @@ -109,7 +109,7 @@ class UserApi(baseUrl: String) { * @param username The name that needs to be fetched. Use user1 for testing. */ def getUserByName(username: String -): Request[Either[ResponseError[Exception], User], Nothing] = +): Request[Either[ResponseException[String, Exception], User], Nothing] = basicRequest .method(Method.GET, uri"$baseUrl/user/${username}") .contentType("application/json") @@ -128,7 +128,7 @@ class UserApi(baseUrl: String) { * @param password The password for login in clear text */ def loginUser(username: String, password: String -): Request[Either[ResponseError[Exception], String], Nothing] = +): Request[Either[ResponseException[String, Exception], String], Nothing] = basicRequest .method(Method.GET, uri"$baseUrl/user/login?username=${ username }&password=${ password }") .contentType("application/json") @@ -142,7 +142,7 @@ class UserApi(baseUrl: String) { * api_key (apiKey) */ def logoutUser(apiKey: String)( -): Request[Either[ResponseError[Exception], Unit], Nothing] = +): Request[Either[ResponseException[String, Exception], Unit], Nothing] = basicRequest .method(Method.GET, uri"$baseUrl/user/logout") .contentType("application/json") @@ -163,7 +163,7 @@ class UserApi(baseUrl: String) { * @param user Updated user object */ def updateUser(apiKey: String)(username: String, user: User -): Request[Either[ResponseError[Exception], Unit], Nothing] = +): Request[Either[ResponseException[String, Exception], Unit], Nothing] = basicRequest .method(Method.PUT, uri"$baseUrl/user/${username}") .contentType("application/json") diff --git a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/JsonSupport.scala b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/JsonSupport.scala index 51896325c2a..69c83df3f42 100644 --- a/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/JsonSupport.scala +++ b/samples/client/petstore/scala-sttp/src/main/scala/org/openapitools/client/core/JsonSupport.scala @@ -13,7 +13,7 @@ package org.openapitools.client.core import org.openapitools.client.model._ import org.json4s._ -import sttp.client.json4s.SttpJson4sApi +import sttp.client3.json4s.SttpJson4sApi import scala.reflect.ClassTag object JsonSupport extends SttpJson4sApi {