forked from loafle/openapi-generator-original
scala-sttp: fix for issue 15785 api returns unit. (#18537)
This commit is contained in:
parent
5e40fe7f8f
commit
afd3a78e20
@ -10,8 +10,7 @@ import sttp.model.Method
|
||||
|
||||
{{#operations}}
|
||||
object {{classname}} {
|
||||
|
||||
def apply(baseUrl: String = "{{{basePath}}}") = new {{classname}}(baseUrl)
|
||||
def apply(baseUrl: String = "{{{basePath}}}") = new {{classname}}(baseUrl)
|
||||
}
|
||||
|
||||
class {{classname}}(baseUrl: String) {
|
||||
@ -20,7 +19,7 @@ class {{classname}}(baseUrl: String) {
|
||||
{{#javadocRenderer}}
|
||||
{{>javadoc}}
|
||||
{{/javadocRenderer}}
|
||||
def {{operationId}}({{>methodParameters}}): Request[{{#defaultReturnType}}Either[Either[String, String], Unit]{{/defaultReturnType}}{{^defaultReturnType}}{{#separateErrorChannel}}Either[ResponseException[String, Exception], {{>operationReturnType}}]{{/separateErrorChannel}}{{^separateErrorChannel}}{{>operationReturnType}}{{/separateErrorChannel}}{{/defaultReturnType}}, Any] =
|
||||
def {{operationId}}({{>methodParameters}}): Request[{{#separateErrorChannel}}Either[ResponseException[String, Exception], {{>operationReturnType}}]{{/separateErrorChannel}}{{^separateErrorChannel}}{{>operationReturnType}}{{/separateErrorChannel}}, Any] =
|
||||
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}}
|
||||
@ -36,7 +35,7 @@ class {{classname}}(baseUrl: String) {
|
||||
{{>paramMultipartCreation}}{{^-last}}, {{/-last}}{{/formParams}}
|
||||
).flatten){{/isMultipart}}{{/formParams.0}}{{#bodyParam}}
|
||||
.body({{paramName}}){{/bodyParam}}
|
||||
.response({{#defaultReturnType}}asEither(asString, ignore){{/defaultReturnType}}{{^defaultReturnType}}{{#separateErrorChannel}}asJson{{/separateErrorChannel}}{{^separateErrorChannel}}asJsonAlwaysUnsafe{{/separateErrorChannel}}[{{>operationReturnType}}]{{/defaultReturnType}})
|
||||
.response({{#separateErrorChannel}}{{^returnType}}asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))){{/returnType}}{{#returnType}}asJson[{{>operationReturnType}}]{{/returnType}}{{/separateErrorChannel}}{{^separateErrorChannel}}{{^returnType}}asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))).getRight{{/returnType}}{{#returnType}}asJson[{{>operationReturnType}}].getRight{{/returnType}}{{/separateErrorChannel}})
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ import sttp.client3._
|
||||
import sttp.model.Method
|
||||
|
||||
object FakeApi {
|
||||
|
||||
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new FakeApi(baseUrl)
|
||||
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new FakeApi(baseUrl)
|
||||
}
|
||||
|
||||
class FakeApi(baseUrl: String) {
|
||||
@ -38,6 +37,6 @@ class FakeApi(baseUrl: String) {
|
||||
.contentType("application/json")
|
||||
.header("_type", underscoreType.toString)
|
||||
.header("type_", typeWithUnderscore.toString)
|
||||
.response(asJson[Unit])
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
}
|
||||
|
@ -19,8 +19,7 @@ import sttp.client3._
|
||||
import sttp.model.Method
|
||||
|
||||
object PetApi {
|
||||
|
||||
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new PetApi(baseUrl)
|
||||
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new PetApi(baseUrl)
|
||||
}
|
||||
|
||||
class PetApi(baseUrl: String) {
|
||||
@ -57,7 +56,7 @@ class PetApi(baseUrl: String) {
|
||||
.method(Method.DELETE, uri"$baseUrl/pet/${petId}")
|
||||
.contentType("application/json")
|
||||
.header("api_key", apiKey.toString)
|
||||
.response(asJson[Unit])
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
/**
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
@ -150,7 +149,7 @@ class PetApi(baseUrl: String) {
|
||||
"name" -> name,
|
||||
"status" -> status
|
||||
))
|
||||
.response(asJson[Unit])
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -17,8 +17,7 @@ import sttp.client3._
|
||||
import sttp.model.Method
|
||||
|
||||
object StoreApi {
|
||||
|
||||
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new StoreApi(baseUrl)
|
||||
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new StoreApi(baseUrl)
|
||||
}
|
||||
|
||||
class StoreApi(baseUrl: String) {
|
||||
@ -37,7 +36,7 @@ class StoreApi(baseUrl: String) {
|
||||
basicRequest
|
||||
.method(Method.DELETE, uri"$baseUrl/store/order/${orderId}")
|
||||
.contentType("application/json")
|
||||
.response(asJson[Unit])
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
/**
|
||||
* Returns a map of status codes to quantities
|
||||
|
@ -18,8 +18,7 @@ import sttp.client3._
|
||||
import sttp.model.Method
|
||||
|
||||
object UserApi {
|
||||
|
||||
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new UserApi(baseUrl)
|
||||
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new UserApi(baseUrl)
|
||||
}
|
||||
|
||||
class UserApi(baseUrl: String) {
|
||||
@ -36,13 +35,13 @@ class UserApi(baseUrl: String) {
|
||||
* @param user Created user object
|
||||
*/
|
||||
def createUser(apiKey: String)(user: User
|
||||
): Request[Either[Either[String, String], Unit], Any] =
|
||||
): Request[Either[ResponseException[String, Exception], Unit], Any] =
|
||||
basicRequest
|
||||
.method(Method.POST, uri"$baseUrl/user")
|
||||
.contentType("application/json")
|
||||
.header("api_key", apiKey)
|
||||
.body(user)
|
||||
.response(asEither(asString, ignore))
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
/**
|
||||
*
|
||||
@ -56,13 +55,13 @@ class UserApi(baseUrl: String) {
|
||||
* @param user List of user object
|
||||
*/
|
||||
def createUsersWithArrayInput(apiKey: String)(user: Seq[User]
|
||||
): Request[Either[Either[String, String], Unit], Any] =
|
||||
): Request[Either[ResponseException[String, Exception], Unit], Any] =
|
||||
basicRequest
|
||||
.method(Method.POST, uri"$baseUrl/user/createWithArray")
|
||||
.contentType("application/json")
|
||||
.header("api_key", apiKey)
|
||||
.body(user)
|
||||
.response(asEither(asString, ignore))
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
/**
|
||||
*
|
||||
@ -76,13 +75,13 @@ class UserApi(baseUrl: String) {
|
||||
* @param user List of user object
|
||||
*/
|
||||
def createUsersWithListInput(apiKey: String)(user: Seq[User]
|
||||
): Request[Either[Either[String, String], Unit], Any] =
|
||||
): Request[Either[ResponseException[String, Exception], Unit], Any] =
|
||||
basicRequest
|
||||
.method(Method.POST, uri"$baseUrl/user/createWithList")
|
||||
.contentType("application/json")
|
||||
.header("api_key", apiKey)
|
||||
.body(user)
|
||||
.response(asEither(asString, ignore))
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
@ -102,7 +101,7 @@ class UserApi(baseUrl: String) {
|
||||
.method(Method.DELETE, uri"$baseUrl/user/${username}")
|
||||
.contentType("application/json")
|
||||
.header("api_key", apiKey)
|
||||
.response(asJson[Unit])
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
/**
|
||||
*
|
||||
@ -152,12 +151,12 @@ class UserApi(baseUrl: String) {
|
||||
* api_key (apiKey)
|
||||
*/
|
||||
def logoutUser(apiKey: String)(
|
||||
): Request[Either[Either[String, String], Unit], Any] =
|
||||
): Request[Either[ResponseException[String, Exception], Unit], Any] =
|
||||
basicRequest
|
||||
.method(Method.GET, uri"$baseUrl/user/logout")
|
||||
.contentType("application/json")
|
||||
.header("api_key", apiKey)
|
||||
.response(asEither(asString, ignore))
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
@ -179,6 +178,6 @@ class UserApi(baseUrl: String) {
|
||||
.contentType("application/json")
|
||||
.header("api_key", apiKey)
|
||||
.body(user)
|
||||
.response(asJson[Unit])
|
||||
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user