swagger-api / swagger-api/swagger-codegen
[Kotlin] int type results in null pointer exception
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When generating swagger for our kotlin project, we hit a null pointer exception. After looking into it, it seems to originate from using int as a type (as opposed to Integer, int32, etc)
[main] WARN io.swagger.codegen.DefaultCodegen - Type is NULL for Serializable Parameter: orderDetailId
Exception in thread "main" java.lang.RuntimeException: Could not process operation:
Tag: Tag {
name: DocumentInfo
description: null
externalDocs: null
extensions:{}}
Operation: V1DocumentInfoUploadPost
Resource: post /v1/DocumentInfo/upload
Exception: null
at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:940)
at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:819)
at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:439)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:754)
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 io.swagger.codegen.languages.AbstractKotlinCodegen.toModelName(AbstractKotlinCodegen.java:445)
at io.swagger.codegen.languages.AbstractKotlinCodegen.getSwaggerType(AbstractKotlinCodegen.java:252)
at io.swagger.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:1594)
at io.swagger.codegen.DefaultCodegen.fromParameter(DefaultCodegen.java:2536)
at io.swagger.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:2241)
at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:889)
... 5 more
Swagger-codegen version
Master
Swagger declaration file content or url
"/v1/DocumentInfo/upload": {
"post": {
"tags": [
"DocumentInfo"
],
"operationId": "V1DocumentInfoUploadPost",
"consumes": [
"multipart/form-data",
],
"produces": [
],
"parameters": [
{
"name": "orderDetailId",
"in": "query",
"description": "OrderDetailId",
"required": true,
"type": "int"
}
],
"responses": {
"204": {
"description": "Success"
}
}
}
}
Command line used for generation
swagger-codegen generate -i swagger.json -l kotlin -o SwaggerClient/
Steps to reproduce
Have a property with type int as a parameter.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in AbstractKotlinCodegen.toModelName and follow how the int parameter reaches getSwaggerType and fromProperty. Run the supplied swagger-codegen generate command with the declaration shown; done means Kotlin generation handles the int parameter without the null pointer exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100