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

[JAVA] Exception (NullPointerException) for parameter with schema array and items as strings #6995

Closed
stefanmeschke opened this issue Nov 19, 2017 · 4 comments
Milestone

Comments

@stefanmeschke
Copy link
Contributor

stefanmeschke commented Nov 19, 2017

Description

I'm getting the following error:

Exception in thread "main" java.lang.RuntimeException: Could not generate api file for 'Default'
        at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:495)
        at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:700)
        at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: java.lang.NullPointerException
        at java.util.TreeMap.compare(TreeMap.java:1294)
        at java.util.TreeMap.put(TreeMap.java:538)
        at java.util.TreeSet.add(TreeSet.java:255)
        at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
        at java.util.TreeSet.addAll(TreeSet.java:312)
        at io.swagger.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:897)
        at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:412)
        ... 3 more
Swagger-codegen version

Version: 2.2.1

Swagger declaration file content or url
swagger: "2.0"
info:
  version: "0.0.1"
  title: "com.test"
basePath: "/api"
paths:
  /pets/bulk:
    post:
      summary: "Add new pets"
      operationId: "bulkAddingPets"
      parameters:
      - in: "body"
        name: "pets"
        description: "The pet names which should be added"
        required: true
        schema:
          type: "array"
          items:
            type: "string"
      responses:
        201:
          description: "successful added"

If I remove

        schema:
          type: "array"
          items:
            type: "string"

the generation succeeded.

Command line used for generation

swagger-codegen generate -i ./api-docs/test.yml -l typescript-angular2 -o ./src/app/api/test-api/

Steps to reproduce

Just run the code generation for the definition above.

Related issues/PRs

I think a related issue is the issue from @dancrumb:
#6272

@wing328
Copy link
Contributor

wing328 commented Nov 20, 2017

@stefanmeschke can you show an example of what the HTTP request body looks like?

@stefanmeschke
Copy link
Contributor Author

@wing328 Thanks for your reply.
Yah, sure.

POST /api/pets/bulk
Request Payload:

[
  "max",
  "maxi",
  "mini"
]

The swagger declaration is valid. I copied it to the swagger editor and tried the request. It works as expected. Do you need more information?

@wing328
Copy link
Contributor

wing328 commented Nov 23, 2017

I agree it's valid. 2.2.1 was released a while ago.

Please give it another try with the latest master (the SNAPSHOT version can be found in the README)

@wing328 wing328 added this to the v2.3.0 milestone Nov 23, 2017
@Danielku15
Copy link
Contributor

Danielku15 commented Nov 27, 2017

I can confirm the same error for 2.2.3. The same error does not appear when taking the current master branch, but unfortunatley I cannot move to 3.0.0 (master) yet as there are too many other breaking changes which are not feasable for us (increased boost dependencies for cpprest, huge dependency increase on javascript -> 65000 files of node modules and broken browserify support).

For me it is failing with an integer array:

swagger: "2.0"
info:
  version: "0.0.1"
  title: "com.test"
basePath: "/api"
paths:
  /pets/bulk:
    post:
      summary: "Add new pets"
      operationId: "bulkAddingPets"
      parameters:
      - in: "body"
        name: "pets"
        description: "The pet names which should be added"
        required: true
        schema:
          type: "array"
          items:
            type: "integer"
            format: "int32"
      responses:
        201:
          description: "successful added"

Update 1 (2017-11-27 17:52)

It appears that for some reason a null string is added to the imports of this operation, this leads to a null reference when they are added to the TreeMap. For the trunk it was fixed in commit
92a1c3a and pull request #6079. With adding those patches to the 2.2.3 branch I can generate the array parameters again.

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