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

[golang] Fix Null pointer exception in toVarName #377

Merged
merged 3 commits into from
Jul 3, 2018

Conversation

etherealjoy
Copy link
Contributor

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, 3.1.x, 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

Fix null pointer exception when the request body parameter is an array of primitives or maps.
Fixes #373

@wing328 @antihax @bvwells

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

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

looks good to me.
thanks for the PR!

// replace - with _ e.g. created-at => created_at
name = sanitizeName(name.replaceAll("-", "_"));
name = sanitizeName(name);
Copy link
Member

Choose a reason for hiding this comment

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

will sanitizeName() always return a non-null object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@macjohnny super will always return non null. If name is null it will return ERROR_UNKNOWN
This is a different issue tracked here #376

Copy link
Member

Choose a reason for hiding this comment

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

ok, so then this should be fine

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why that replaceAll is here at all? Go should not use _ or - in variable names. Camelize removes both these.

  // Remove all underscores (underscore_case to camelCase)
        p = Pattern.compile("(_)(.)");
        m = p.matcher(word);
        while (m.find()) {
            String original = m.group(2);
            String upperCase = original.toUpperCase();
            if (original.equals(upperCase)) {
                word = word.replaceFirst("_", "");
            } else {
                word = m.replaceFirst(upperCase);
            }
            m = p.matcher(word);
        }

        // Remove all hyphens (hyphen-case to camelCase)
        p = Pattern.compile("(-)(.)");
        m = p.matcher(word);
        while (m.find()) {
            word = m.replaceFirst(m.group(2).toUpperCase());
            m = p.matcher(word);
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could update this.

@etherealjoy etherealjoy reopened this Jul 2, 2018
@etherealjoy
Copy link
Contributor Author

etherealjoy commented Jul 2, 2018

@antihax
I tested the NPE from #373 and it is solved.
Also I tested a leading '_' and an '-' in between somewhere it is also as you described.

@antihax
Copy link
Contributor

antihax commented Jul 3, 2018

Sounds good, thanks!

@jmini jmini merged commit 83e14a7 into OpenAPITools:master Jul 3, 2018
@jmini jmini added this to the 3.1.0 milestone Jul 3, 2018
@etherealjoy etherealjoy deleted the fix_go_npe_for_array_request branch July 3, 2018 05:24
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
nilskuhn pushed a commit to nilskuhn/openapi-generator that referenced this pull request Apr 6, 2023
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

5 participants