OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] javax.annotation.Nullable or javax.annotation.Nonnull on getters in java client
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I use nullable: false attribute on my properties, but they still annotated with @javax.annotation.Nullable in java code. Is it bug? Or may be I am doing something wrong?
openapi-generator version
5.3.1
OpenAPI declaration file content or url
yaml
openapi: 3.0.3
info:
title: title
description: description
version: LATEST
paths:
/api/get:
post:
summary: getInfo
operationId: get
requestBody:
content:
application/json:
schema:
properties:
ids:
type: array
nullable: false
items:
type: integer
format: int64
example: 172
responses:
'200':
description: Ok
client.json
{
"library": "apache-httpclient",
"openApiNullable": false
}
Generation Details
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v5.3.1 generate \
-i /local/openapi/conf.yaml \
-c /local/openapi/client.json \
-g java \
-o /local/openapi/out
Steps to reproduce
- Create folder openapi
- Put client.json in ./openapi/client.json
- Put conf.yaml in /openapi/conf.yaml
- Generate output (see command above)
- Open file openapi/out/src/main/java/org/openapitools/client/model/GetRequest.java
Actual behaviour:
Getter (getIds()) has @Nullable annotation
Expected:
Getter (getIds()) has @Nonnull annotation according to nullable attribute in openapi.yaml configuration.
Suggest a fix
If property is annotated with nullable: true, then annotate getter with @Nullable, otherwise @Nonnull
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 Java client generation with the supplied OpenAPI YAML, client.json, and v5.3.1 command, then inspect openapi/out/src/main/java/org/openapitools/client/model/GetRequest.java. Trace how the ids property's nullable setting affects the generated getIds() annotation. Done means nullable properties produce the expected @Nullable or @Nonnull getter annotation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100