diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java index 19a45238713..e0ce0e8c9dd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java @@ -333,4 +333,29 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen { } } + @Override + public String toOperationId(String operationId) { + // throw exception if method name is empty + if (StringUtils.isEmpty(operationId)) { + throw new RuntimeException("Empty method/operation name (operationId) not allowed"); + } + + operationId = camelize(sanitizeName(operationId), true); + + // method name cannot use reserved keyword, e.g. return + if (isReservedWord(operationId)) { + String newOperationId = camelize("call_" + operationId, true); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); + return newOperationId; + } + + // operationId starts with a number + if (operationId.matches("^\\d.*")) { + LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true); + operationId = camelize("call_" + operationId, true); + } + + return operationId; + } + } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java index 7db20b6c857..113277464fa 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java @@ -235,16 +235,6 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code return codegenSecurities; } - @Override - public String toOperationId(String operationId) { - // throw exception if method name is empty - if (StringUtils.isEmpty(operationId)) { - throw new RuntimeException("Empty method name (operationId) not allowed"); - } - - return super.toOperationId(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, operationId)); - } - @Override public String toParamName(String name) { return formatIdentifier(name, false); diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/api.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/api.mustache index 11df8e3494f..bab80595cc0 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/api.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/api.mustache @@ -33,16 +33,20 @@ class {{classname}}(baseUrl: String) { {{/dataType}}{{^dataType}}.with{{>responseState}}Response[Unit]({{code}}) {{/dataType}}{{/isWildcard}}{{/responses}}{{#responses}}{{#isWildcard}}{{#dataType}}.withDefault{{>responseState}}Response[{{dataType}}] {{/dataType}}{{^dataType}}.withDefault{{>responseState}}Response[Unit] - {{/dataType}}{{/isWildcard}}{{/responses}}{{^responseHeaders.isEmpty}} - object {{#fnCapitalize}}{{operationId}}{{/fnCapitalize}}Headers { {{#responseHeaders}} - def {{{name}}}(r: ApiReturnWithHeaders) = r.get{{^isContainer}}{{baseType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}Header("{{baseName}}"){{/responseHeaders}} + {{/dataType}}{{/isWildcard}}{{/responses}} + {{^responseHeaders.isEmpty}} + object {{#fnCapitalize}}{{operationId}}{{/fnCapitalize}}Headers { + {{#responseHeaders}} + def {{{name}}}(r: ApiReturnWithHeaders) = r.get{{^isContainer}}{{baseType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}Header("{{baseName}}") + {{/responseHeaders}} } {{/responseHeaders.isEmpty}} + {{/operation}} -{{#unknownStatusCodes}} + {{#unknownStatusCodes}} ApiInvoker.addCustomStatusCode({{{value}}}, isSuccess = false) -{{/unknownStatusCodes}} + {{/unknownStatusCodes}} } diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala index 3cc0392a242..46cccda09a4 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala @@ -35,7 +35,9 @@ class PetApi(baseUrl: String) { ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/pet", "application/json") .withBody(body) .withErrorResponse[Unit](405) - /** + + + /** * Expected answers: * code 400 : (Invalid pet value) * @@ -47,7 +49,9 @@ class PetApi(baseUrl: String) { .withPathParam("petId", petId) .withHeaderParam("api_key", apiKey) .withErrorResponse[Unit](400) - /** + + + /** * Multiple status values can be provided with comma separated strings * * Expected answers: @@ -61,7 +65,9 @@ class PetApi(baseUrl: String) { .withQueryParam("status", ArrayValues(status, CSV)) .withSuccessResponse[Seq[Pet]](200) .withErrorResponse[Unit](400) - /** + + + /** * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * * Expected answers: @@ -75,7 +81,9 @@ class PetApi(baseUrl: String) { .withQueryParam("tags", ArrayValues(tags, CSV)) .withSuccessResponse[Seq[Pet]](200) .withErrorResponse[Unit](400) - /** + + + /** * Returns a single pet * * Expected answers: @@ -95,7 +103,9 @@ class PetApi(baseUrl: String) { .withSuccessResponse[Pet](200) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) - /** + + + /** * Expected answers: * code 400 : (Invalid ID supplied) * code 404 : (Pet not found) @@ -109,7 +119,9 @@ class PetApi(baseUrl: String) { .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) .withErrorResponse[Unit](405) - /** + + + /** * Expected answers: * code 405 : (Invalid input) * @@ -123,7 +135,9 @@ class PetApi(baseUrl: String) { .withFormParam("status", status) .withPathParam("petId", petId) .withErrorResponse[Unit](405) - /** + + + /** * Expected answers: * code 200 : ApiResponse (successful operation) * @@ -139,5 +153,7 @@ class PetApi(baseUrl: String) { .withSuccessResponse[ApiResponse](200) + + } diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala index ec43060d143..6680acdde72 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala @@ -37,7 +37,9 @@ class StoreApi(baseUrl: String) { .withPathParam("orderId", orderId) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) - /** + + + /** * Returns a map of status codes to quantities * * Expected answers: @@ -50,7 +52,9 @@ class StoreApi(baseUrl: String) { ApiRequest[Map[String, Int]](ApiMethods.GET, "http://petstore.swagger.io/v2", "/store/inventory", "application/json") .withApiKey(apiKey, "api_key", HEADER) .withSuccessResponse[Map[String, Int]](200) - /** + + + /** * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * * Expected answers: @@ -66,7 +70,9 @@ class StoreApi(baseUrl: String) { .withSuccessResponse[Order](200) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) - /** + + + /** * Expected answers: * code 200 : Order (successful operation) * code 400 : (Invalid Order) @@ -80,5 +86,7 @@ class StoreApi(baseUrl: String) { .withErrorResponse[Unit](400) + + } diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala index 411c68aa39d..1480460da33 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala @@ -35,7 +35,9 @@ class UserApi(baseUrl: String) { ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/user", "application/json") .withBody(body) .withDefaultSuccessResponse[Unit] - /** + + + /** * Expected answers: * code 0 : (successful operation) * @@ -45,7 +47,9 @@ class UserApi(baseUrl: String) { ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/user/createWithArray", "application/json") .withBody(body) .withDefaultSuccessResponse[Unit] - /** + + + /** * Expected answers: * code 0 : (successful operation) * @@ -55,7 +59,9 @@ class UserApi(baseUrl: String) { ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/user/createWithList", "application/json") .withBody(body) .withDefaultSuccessResponse[Unit] - /** + + + /** * This can only be done by the logged in user. * * Expected answers: @@ -69,7 +75,9 @@ class UserApi(baseUrl: String) { .withPathParam("username", username) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) - /** + + + /** * Expected answers: * code 200 : User (successful operation) * code 400 : (Invalid username supplied) @@ -83,7 +91,9 @@ class UserApi(baseUrl: String) { .withSuccessResponse[User](200) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) - /** + + + /** * Expected answers: * code 200 : String (successful operation) * Headers : @@ -101,10 +111,11 @@ class UserApi(baseUrl: String) { .withSuccessResponse[String](200) .withErrorResponse[Unit](400) - object LoginUserHeaders { + object LoginUserHeaders { def xRateLimit(r: ApiReturnWithHeaders) = r.getIntHeader("X-Rate-Limit") def xExpiresAfter(r: ApiReturnWithHeaders) = r.getDateTimeHeader("X-Expires-After") } + /** * Expected answers: * code 0 : (successful operation) @@ -112,7 +123,9 @@ class UserApi(baseUrl: String) { def logoutUser(): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/user/logout", "application/json") .withDefaultSuccessResponse[Unit] - /** + + + /** * This can only be done by the logged in user. * * Expected answers: @@ -130,5 +143,7 @@ class UserApi(baseUrl: String) { .withErrorResponse[Unit](404) + + }