forked from loafle/openapi-generator-original
better operation id handling in scala generators (#2490)
This commit is contained in:
parent
5074f4d9c5
commit
3e065db2c6
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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}}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user