question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][JAVA] Client generator ignores 'nullable' property

See original GitHub issue
Description

Client generator ignores ‘nullable’ property of the object schema. Instead, javax.annotation.Nullable generation seems to be based on ‘required’ property. This behaviour is incorrect - required fields have to be provided, but not necessarily non-null, i.e { "field" : null } satisfies the ‘required’.

Nullable is part of OpenAPI 3.0 spec. To make it more robust, x-nullable could be handled, too.

OpenAPI declaration file content or url
"components": {
   "schemas": {
      "SomeEntity": {
        "type": "object",
        "properties": {
          "name": {
            "id": "string",
            "nullable": false
          }
      }
   }
}
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/3264

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

2reactions
alwaysbemarkcommented, Aug 24, 2021

The semantics posted by @kkosmrli are what I would expect too. This issue is also impacting us and requires manual post-processing of the generated files. It would be nice to get a fix for this. Thank you!

1reaction
kkosmrlicommented, Aug 24, 2021

I also ran into this behaviour today. At the moment it seems the only option is to use required to mark fields with @NotNull. Unfortunately this means that the generated code does not match the specification. According to OAS 3 required just marks a field as mandatory in the object e.g. {"field" : null} and {"field" : "value"} is valid and {} is not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Openapi generator maven plugin nullable property problem
A property can be mentioned as nullable to pass null value in openApi. OpenApi generator wraps the datatype with JsonNullable as shown below ......
Read more >
Changelog - DataStax Java Driver
[improvement] JAVA-852: Ignore peers with null entries during discovery. [bug] JAVA-1005: DowngradingConsistencyRetryPolicy does not work with EACH_QUORUM ...
Read more >
Bug descriptions — spotbugs 4.7.3 documentation
Returning a null value in such case is a contract violation and will most likely break client code. NP: Non-null field is not...
Read more >
Documentation for the java Generator
This option only works for Java API client, false. gradleProperties, Append additional Gradle properties to the gradle.properties file, null.
Read more >
Using Optional and Nullable Properties in API Requests
If a field (whether it is a parameter or a part of a model) is uninitialized, i.e., not specified, then it should be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found