-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Better handling of operationID starting with numbers #691
Conversation
// operationId starts with a number | ||
if (operationId.matches("^\\d.*")) { | ||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); | ||
operationId = camelize("call_" + operationId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "operation" as a prefix makes more sense. "Call" suggests an operation is being performed, which may not always be the case (for example if the templates are modified to create infrastructural services rather than endpoint invokers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also you are logging the sanitized name here, and then don't sanitize it when assigning it to the variable operationId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. This should probably assign, then log the assigned value to avoid issues in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jimschubert yup, agree there may be a better choice of word other than "call_". My goal is to make the output compiles without issues due to method names starting with numbers. Users need to rename the operationId if they want complete control.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stkrwork good catch. Let me revise that.
@jimschubert @stkrwork revised and pushed some changes. Please have a look. |
@@ -552,7 +552,7 @@ public String toOperationId(String operationId) { | |||
operationId = "call_" + operationId; | |||
} | |||
|
|||
// model name starts with a number | |||
// operationId starts with a number | |||
if (operationId.matches("^\\d.*")) { | |||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); | |||
operationId = "call_" + operationId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still not sanitizing here
// operationId starts with a number | ||
if (operationId.matches("^\\d.*")) { | ||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); | ||
operationId = "call_" + operationId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still not sanitizing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didnt see sanitization on returning value
@@ -603,6 +603,12 @@ public String toOperationId(String operationId) { | |||
operationId = "call_" + operationId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still not sanitizing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm
// operationId starts with a number | ||
if (operationId.matches("^\\d.*")) { | ||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); | ||
operationId = "call_" + operationId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still not sanitizing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure to understand, this is just about adding the call_
prefix. The value will be sanitized on line 612: return camelize(sanitizeName(operationId));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh my bad, didnt see that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmini is correct. It was already sanitized a few lines above and that's the reason why I didn't call the function sanitize
again when the operationId starts with a number.
@jmini @jimschubert @stkrwork thanks for reviewing the change. Let's go with "call_" first and see if we need a better prefix later. |
* add numeric operationid to test spec * better handling of operationId in more generators * fix go toOperationId * update samples * update java samples * update java samples (vertx, webclient) * update java google api client sample * fix typo, update OAS3 test spec, update php petstore (oas3) * defer camelize in operationid * remove duplicated sanitizeName
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,4.0.x
. Default:master
.Description of the PR
(details of the change, additional tests that have been done, reference to the issue for tracking, etc)