swagger-api / swagger-api/swagger-codegen

NPE for parameter without a name

Open
#3,708 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Issue: Bug Issue: Invalid spec
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with bug.yml through the swagger-codegen-cli.jar generate entry point, using nodejs-server or python-flask. Start with DefaultCodegen.fromParameter, DefaultCodegen.fromProperty, and DefaultCodegen.camelize, following the stack trace from DefaultGenerator.processOperation. Done means an unnamed parameter no longer causes an NPE and is either skipped with a warning or rejected with a descriptive error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, node.js, python
Domain
backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.