Skip to content

[JavaScript] Handle reserved operationId/model name in JS client #2257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,18 @@ public String toParamName(String name) {
public String toModelName(String name) {
name = sanitizeName(name); // FIXME parameter should not be assigned. Also declare it as "final"

// camelize the model name
// phone_number => PhoneNumber
name = camelize(name);

// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
String modelName = "Object" + name;
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
return modelName;
}

// camelize the model name
// phone_number => PhoneNumber
return camelize(name);
return name;
}

@Override
Expand Down Expand Up @@ -419,12 +423,16 @@ public String toOperationId(String 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)) {
operationId = escapeReservedWord(operationId);
String newOperationId = camelize("call_" + operationId, true);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId;
}

return camelize(sanitizeName(operationId), true);
return operationId;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/javascript/src/api/PetApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@
* @param {function} callback the callback function, accepting three arguments: error, data, response
* data is of type: 'String'
*/
self.getPetByIdWithByteArray = function(petId, callback) {
self.petPetIdtestingByteArraytrueGet = function(petId, callback) {
var postBody = null;

// verify the required parameter 'petId' is set
if (petId == null) {
throw "Missing the required parameter 'petId' when calling getPetByIdWithByteArray";
throw "Missing the required parameter 'petId' when calling petPetIdtestingByteArraytrueGet";
}


Expand Down