-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REQ][spring] Null-Safety annotations #14427
Comments
That was done recently for the regular Java clients #19600 but not for Spring unfortunately. |
If I am not mistaken, |
It would be a very welcome change. And it makes a lot of sense to replicate it for the Spring generator if it is already done for Java clients. In addition, it would be nice if the annotations are configurable (in order to support not only those from Spring, but also org.jspecify.annotations NonNull and Nullable, etc). |
@pcuriel I've just submitted the PR. |
Thanks for the PR. |
@frecco75 I was thinking about it but for the required and non-nullable ( public class Pet {
@JsonProperty("name")
private String requiredName = null;
public Pet() {
super();
}
...
} I am not confident that it is a good idea to annotate that Also, my goal was to prevent dummy NPEs, not to make the good interpolation with Kotlin. Don't get me wrong, I would be happy to put |
Is your feature request related to a problem? Please describe.
Manage null safety for object properties with Spring annotations (
@NonNull
,@Nullable
).Example: https://www.baeldung.com/spring-null-safety-annotations
Describe the solution you'd like
I'd like to add a config option
useSpringNullSafety
for thespring
generator (false
by default), to add Spring Null-Safety annotations (either@NonNull
or@Nullable
, depending of thenullable
attribute of the OAS model).Example:
should generate a model:
Describe alternatives you've considered
Maybe it should be similar to the
useOptional
config option, so that it should be based on therequired
OpenAPI attribute.Additional context
It is better for Kotlin interoparibilty. As it is mentionned in Kotlin reference, Java object are natively resolved as
platform type
.With contextual annotations, the Kotlin compiler can provide null-safety type checking.
https://kotlinlang.org/docs/java-interop.html#null-safety-and-platform-types
The text was updated successfully, but these errors were encountered: