-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Milestone
Description
Description
When generating JaxRS code, I run in a Nullpointer exception.
This is caused by a string array within the body parameter in the json description.
The problem is in AbstractJavaCodegen Method
protected boolean needToImport(String type) {
return super.needToImport(type) && type.indexOf(".") < 0;
}
There is a null value in the list of imports to check. This in turn results from this code in DefaultCodegen.java (Line 2581):
// recursively add import
CodegenProperty innerCp = cp;
while(innerCp != null) {
imports.add(innerCp.complexType);
innerCp = innerCp.items;
}
innerCp is not a complexType is this case what causes NULL to be added to the import.
Swagger-codegen version
2.2.3
Swagger declaration file content or url
"paths": {
"/test": {
"post": {
"summary": "Test method to show error",
"operationId": "test",
"parameters": [
{
"name": "queryparam1",
"in": "query",
"type": "string"
},
{
"name": "listOfStrings",
"in": "body",
"description": "An array of strings",
"required": true,
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
]
}
} Command line used for generation
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.3</version>
<executions>
<execution>
<id>generation-java</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>test.json</inputSpec>
<language>jaxrs</language> <!-- Defaults to jersey2 -->
</configuration>
</execution>
</executions>
</plugin>
Suggest a fix/enhancement
Add a null check to the needToImport method.