Skip to content
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

Merged
merged 12 commits into from
Aug 1, 2018

Conversation

wing328
Copy link
Member

@wing328 wing328 commented Jul 30, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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\.
  • Filed the PR against the correct branch: master, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

(details of the change, additional tests that have been done, reference to the issue for tracking, etc)

@wing328 wing328 added the WIP Work in Progress label Jul 30, 2018
@wing328 wing328 added this to the 3.2.0 milestone Jul 30, 2018
@wing328 wing328 changed the title [WIP] Better handling of operationID starting with numbers Better handling of operationID starting with numbers Jul 31, 2018
// 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);
Copy link
Member

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).

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

@wing328
Copy link
Member Author

wing328 commented Aug 1, 2018

@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;
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

still not sanitizing here

Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

still not sanitizing here

Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

still not sanitizing here

Copy link
Member

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));

Copy link
Contributor

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

Copy link
Member Author

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.

@wing328
Copy link
Member Author

wing328 commented Aug 1, 2018

@jmini @jimschubert @stkrwork thanks for reviewing the change. Let's go with "call_" first and see if we need a better prefix later.

@wing328 wing328 merged commit ab08dd1 into master Aug 1, 2018
@wing328 wing328 deleted the operationid_number branch August 1, 2018 14:32
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants