fix scala akka return type (#2510)

This commit is contained in:
William Cheng 2019-03-26 18:54:09 +08:00 committed by GitHub
parent 5a6f4cb4a9
commit d4244be654
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 22 deletions

View File

@ -49,13 +49,7 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
protected boolean registerNonStandardStatusCodes = true; protected boolean registerNonStandardStatusCodes = true;
protected boolean renderJavadoc = true; protected boolean renderJavadoc = true;
protected boolean removeOAuthSecurities = true; protected boolean removeOAuthSecurities = true;
/**
* If set to true, only the default response (the one with le lowest 2XX code) will be considered as a success, and all
* others as ApiErrors.
* If set to false, all responses defined in the model will be considered as a success upon reception. Only http errors,
* unmarshalling problems and any other RuntimeException will be considered as ApiErrors.
*/
protected boolean onlyOneSuccess = true;
@SuppressWarnings("hiding") @SuppressWarnings("hiding")
protected Logger LOGGER = LoggerFactory.getLogger(ScalaAkkaClientCodegen.class); protected Logger LOGGER = LoggerFactory.getLogger(ScalaAkkaClientCodegen.class);
@ -92,7 +86,6 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
additionalProperties.put("fnCapitalize", new CapitalizeLambda()); additionalProperties.put("fnCapitalize", new CapitalizeLambda());
additionalProperties.put("fnCamelize", new CamelizeLambda(false)); additionalProperties.put("fnCamelize", new CamelizeLambda(false));
additionalProperties.put("fnEnumEntry", new EnumEntryLambda()); additionalProperties.put("fnEnumEntry", new EnumEntryLambda());
additionalProperties.put("onlyOneSuccess", onlyOneSuccess);
additionalProperties.put("mainPackage", mainPackage); additionalProperties.put("mainPackage", mainPackage);
importMapping.remove("Seq"); importMapping.remove("Seq");

View File

@ -1 +1 @@
{{#onlyOneSuccess}}{{^defaultResponse}}Unit{{/defaultResponse}}{{#defaultResponse}}{{#responses}}{{#isDefault}}{{#dataType}}{{dataType}}{{/dataType}}{{^dataType}}Unit{{/dataType}}{{/isDefault}}{{/responses}}{{/defaultResponse}}{{/onlyOneSuccess}}{{^onlyOneSuccess}}{{#responses}}{{#-first}}{{^hasMore}}{{#dataType}}{{dataType}}{{/dataType}}{{^dataType}}Unit{{/dataType}}{{/hasMore}}{{#hasMore}}Any{{/hasMore}}{{/-first}}{{/responses}}{{/onlyOneSuccess}} {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}

View File

@ -1 +1 @@
{{#onlyOneSuccess}}{{#isDefault}}Success{{/isDefault}}{{^isDefault}}Error{{/isDefault}}{{/onlyOneSuccess}}{{^onlyOneSuccess}}Success{{/onlyOneSuccess}} {{#isDefault}}Success{{/isDefault}}{{^isDefault}}Error{{/isDefault}}

View File

@ -96,8 +96,8 @@ class PetApi(baseUrl: String) {
* *
* @param petId ID of pet to return * @param petId ID of pet to return
*/ */
def getPetById(petId: Long)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = def getPetById(petId: Long)(implicit apiKey: ApiKeyValue): ApiRequest[Pet] =
ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/pet/{petId}", "application/json") ApiRequest[Pet](ApiMethods.GET, "http://petstore.swagger.io/v2", "/pet/{petId}", "application/json")
.withApiKey(apiKey, "api_key", HEADER) .withApiKey(apiKey, "api_key", HEADER)
.withPathParam("petId", petId) .withPathParam("petId", petId)
.withSuccessResponse[Pet](200) .withSuccessResponse[Pet](200)
@ -145,8 +145,8 @@ class PetApi(baseUrl: String) {
* @param additionalMetadata Additional data to pass to server * @param additionalMetadata Additional data to pass to server
* @param file file to upload * @param file file to upload
*/ */
def uploadFile(petId: Long, additionalMetadata: Option[String] = None, file: Option[File] = None): ApiRequest[Unit] = def uploadFile(petId: Long, additionalMetadata: Option[String] = None, file: Option[File] = None): ApiRequest[ApiResponse] =
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/pet/{petId}/uploadImage", "multipart/form-data") ApiRequest[ApiResponse](ApiMethods.POST, "http://petstore.swagger.io/v2", "/pet/{petId}/uploadImage", "multipart/form-data")
.withFormParam("additionalMetadata", additionalMetadata) .withFormParam("additionalMetadata", additionalMetadata)
.withFormParam("file", file) .withFormParam("file", file)
.withPathParam("petId", petId) .withPathParam("petId", petId)

View File

@ -64,8 +64,8 @@ class StoreApi(baseUrl: String) {
* *
* @param orderId ID of pet that needs to be fetched * @param orderId ID of pet that needs to be fetched
*/ */
def getOrderById(orderId: Long): ApiRequest[Unit] = def getOrderById(orderId: Long): ApiRequest[Order] =
ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/store/order/{orderId}", "application/json") ApiRequest[Order](ApiMethods.GET, "http://petstore.swagger.io/v2", "/store/order/{orderId}", "application/json")
.withPathParam("orderId", orderId) .withPathParam("orderId", orderId)
.withSuccessResponse[Order](200) .withSuccessResponse[Order](200)
.withErrorResponse[Unit](400) .withErrorResponse[Unit](400)
@ -79,8 +79,8 @@ class StoreApi(baseUrl: String) {
* *
* @param body order placed for purchasing the pet * @param body order placed for purchasing the pet
*/ */
def placeOrder(body: Order): ApiRequest[Unit] = def placeOrder(body: Order): ApiRequest[Order] =
ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/store/order", "application/json") ApiRequest[Order](ApiMethods.POST, "http://petstore.swagger.io/v2", "/store/order", "application/json")
.withBody(body) .withBody(body)
.withSuccessResponse[Order](200) .withSuccessResponse[Order](200)
.withErrorResponse[Unit](400) .withErrorResponse[Unit](400)

View File

@ -85,8 +85,8 @@ class UserApi(baseUrl: String) {
* *
* @param username The name that needs to be fetched. Use user1 for testing. * @param username The name that needs to be fetched. Use user1 for testing.
*/ */
def getUserByName(username: String): ApiRequest[Unit] = def getUserByName(username: String): ApiRequest[User] =
ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/user/{username}", "application/json") ApiRequest[User](ApiMethods.GET, "http://petstore.swagger.io/v2", "/user/{username}", "application/json")
.withPathParam("username", username) .withPathParam("username", username)
.withSuccessResponse[User](200) .withSuccessResponse[User](200)
.withErrorResponse[Unit](400) .withErrorResponse[Unit](400)
@ -104,8 +104,8 @@ class UserApi(baseUrl: String) {
* @param username The user name for login * @param username The user name for login
* @param password The password for login in clear text * @param password The password for login in clear text
*/ */
def loginUser(username: String, password: String): ApiRequest[Unit] = def loginUser(username: String, password: String): ApiRequest[String] =
ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/user/login", "application/json") ApiRequest[String](ApiMethods.GET, "http://petstore.swagger.io/v2", "/user/login", "application/json")
.withQueryParam("username", username) .withQueryParam("username", username)
.withQueryParam("password", password) .withQueryParam("password", password)
.withSuccessResponse[String](200) .withSuccessResponse[String](200)