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

NPE for parameter without a name #3708

Open
scop opened this issue Sep 2, 2016 · 2 comments
Open

NPE for parameter without a name #3708

scop opened this issue Sep 2, 2016 · 2 comments

Comments

@scop
Copy link
Contributor

scop commented Sep 2, 2016

Description

Codegen throws a NPE when generating code for a buggy declaration that has parameters without a name. Happens at least with nodejs-server and python-flask, but not with any client codegens I've tried, so maybe this is a server-only issue?

Swagger-codegen version

Current master

Swagger declaration file content or url
swagger: "2.0"
paths:
  /:
    get:
      operationId: foo
      parameters:
        - bug-here:
          in: query
          type: string
Steps to reproduce
$ java -jar swagger-codegen-cli.jar generate -i bug.yml -l nodejs-server
[main] INFO io.swagger.parser.Swagger20Parser - reading from bug.yml
[main] INFO io.swagger.codegen.ignore.CodegenIgnoreProcessor - No .swagger-codegen-ignore file found.
Exception in thread "main" java.lang.RuntimeException: Could not process operation:
  Tag: default
  Operation: foo
  Resource: get /
  Definitions: {}
  Exception: null
    at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:808)
    at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:700)
    at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:377)
    at io.swagger.codegen.cmd.Generate.run(Generate.java:223)
    at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36)
Caused by: java.lang.NullPointerException
    at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
    at java.util.regex.Matcher.reset(Matcher.java:309)
    at java.util.regex.Matcher.<init>(Matcher.java:229)
    at java.util.regex.Pattern.matcher(Pattern.java:1093)
    at io.swagger.codegen.DefaultCodegen.camelize(DefaultCodegen.java:2875)
    at io.swagger.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:1385)
    at io.swagger.codegen.DefaultCodegen.fromParameter(DefaultCodegen.java:2227)
    at io.swagger.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:1993)
    at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:756)
    ... 4 more
Suggest a Fix

Should probably ignore parameters without a name, and output a warning message about them (along with input filename, linenumber if possible). Or fail with a descriptive message.

@wwn
Copy link

wwn commented Oct 25, 2016

stumbled in :(

@wing328
Copy link
Contributor

wing328 commented Oct 25, 2016

Agreed that the NPE should be handled with a better error message.

Btw, "name" in the parameter object is a required field so please update your spec accordingly and you can leverage tools like https://editor.swagger.io to verify the spec.

@wing328 wing328 modified the milestones: Future, v2.2.2 Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants