Skip to content

Add support for reserved-words-mappings to cpprest #6501

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
Sep 18, 2017
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 @@ -101,13 +101,32 @@ public String toVarName(String name) {
return sanitizeName(name);
}

if (isReservedWord(name)) {
return escapeReservedWord(name);
}

if (name.length() > 1) {
return sanitizeName(Character.toUpperCase(name.charAt(0)) + name.substring(1));
}

return sanitizeName(name);
}

/**
* Escapes a reserved word as defined in the `reservedWords` array. Handle
* escaping those terms here. This logic is only called if a variable
* matches the reseved words
*
* @return the escaped term
*/
@Override
public String escapeReservedWord(String name) {
if(this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return sanitizeName("_" + name);
}

@Override
public String toParamName(String name) {
return sanitizeName(super.toParamName(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class CppRestClientCodegen extends AbstractCppCodegen {

/**
* Configures the type of generator.
*
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto format changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have my editor set to removing trailing whitespace.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep that whitespace in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that?

* @return the CodegenType for this generator
* @see io.swagger.codegen.CodegenType
*/
Expand All @@ -66,7 +66,7 @@ public CodegenType getTag() {
/**
* Configures a friendly name for the generator. This will be used by the
* generator to select the library with the -l flag.
*
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

* @return the friendly name for the generator
*/
public String getName() {
Expand All @@ -76,7 +76,7 @@ public String getName() {
/**
* Returns human-friendly help for the generator. Provide the consumer with
* help tips, parameters here
*
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

* @return A string value for the help message
*/
public String getHelp() {
Expand Down Expand Up @@ -111,8 +111,6 @@ public CppRestClientCodegen() {
"The default include statement that should be placed in all headers for including things like the declspec (convention: #include \"Commons.h\" ",
this.defaultInclude);

reservedWords = new HashSet<String>();

supportingFiles.add(new SupportingFile("modelbase-header.mustache", "", "ModelBase.h"));
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp"));
supportingFiles.add(new SupportingFile("apiclient-header.mustache", "", "ApiClient.h"));
Expand Down Expand Up @@ -187,18 +185,6 @@ public void processOpts() {
additionalProperties.put("defaultInclude", defaultInclude);
}

/**
* Escapes a reserved word as defined in the `reservedWords` array. Handle
* escaping those terms here. This logic is only called if a variable
* matches the reseved words
*
* @return the escaped term
*/
@Override
public String escapeReservedWord(String name) {
return "_" + name; // add an underscore to the name
}

/**
* Location to write model files. You can use the modelPackage() as defined
* when the class is instantiated
Expand Down