OpenAPITools / OpenAPITools/openapi-generator
[BUG] Kotlin generated code makes non-nullable shema fields nullable
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [x ] Have you provided a full/minimal spec to reproduce the issue?
- [ x] Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- [x ] Have you searched for related issues/PRs?
- [ x] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When I use the open-api-generator all of the model fields are ? nullable, all classes look like this:
data class PagedResultDtoOfStoredDeviceFilterWithoutTermDto (
@Json(name = "currentPage")
val currentPage: kotlin.Int? = null,
@Json(name = "totalPages")
val totalPages: kotlin.Int? = null,
@Json(name = "pageSize")
val pageSize: kotlin.Int? = null,
@Json(name = "totalCount")
val totalCount: kotlin.Int? = null,
@Json(name = "items")
val items: kotlin.collections.List<StoredDeviceFilterWithoutTermDto>? = null
)
Despite those fields are not all nullable in the swagger.json.
openapi-generator version
6.3.0
OpenAPI declaration file content or url
Generation Details
java -jar openapi-generator-cli.jar generate ^
-g kotlin ^
--library jvm-retrofit2 ^
-i "https://app-hsm-clse-stage.azurewebsites.net/swagger/standardV1/swagger.json" ^
-p groupId=com.mycompany ^
-p artifactId=mycompany-myproduct-client-kotlin ^
-p artifactVersion=1.0.0 ^
-p basePackage=com.mycompany.myproduct.networking ^
-p packageName=com.mycompany.myproduct.networking ^
-p configPackage=com.mycompany.myproduct.networking.config ^
-p apiPackage=com.mycompany.myproduct.networking.api ^
-p modelPackage=com.mycompany.myproduct.networking.model ^
-p sourceFolder=src/main/java ^
-p dateLibrary=java8 ^
-p java8=true ^
-p useRxJava3=true ^
pause
Steps to reproduce
Run above batch file. Check all model classes. For example IDs are never nullable in our swagger.json, the generated code is always nullable, no matter which one.
Related issues/PRs
Suggest a fix
On SO somebody suggested a workaround, but I strongly think this is a bug.
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
Reproduce the issue with the supplied swagger.json URL and Kotlin jvm-retrofit2 generation command, then inspect the generated model classes shown in the report. Compare their nullable fields with the OpenAPI declaration; done means non-nullable schema fields generate as non-nullable Kotlin properties, with regression coverage added where the generator's existing tests permit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100