forked from loafle/openapi-generator-original
Adds @Nullable annotation to Spring Boot generator (#20345)
* Adds @Nullable annotation to Spring Boot generator * issue-14427: [REQ][spring] Null-Safety annotations * issue-17382: [REQ] spring generator add Nullable annotations Motivations: * Have Spring Boot generator client properly annotated for nullability to be able to check code using them with tools like NullAway * As it is related to Spring then the `org.springframework.lang.Nullable` annotation was chosen to avoid discussion which `@Nullable` one is true one * `@NonNull` wasn't used as I didn't see much benefit of it. Anyhow, an empty constructor and/or setters allow to put a `null` value there Modifications: * Adds nullableAnnotation template to handle nullability annotation on vars * Adjust pojo templates to use the nullability template * Adapts tests Modifications: * Runs export_docs_generator.sh script to update samples * samples update * excludes Spring @Nullable from java-camel * ones with defaults shouldn't be annotated as @Nullable * updates samples * adds AllArgConstructor generation tests * adds container tests
This commit is contained in:
committed by
GitHub
parent
4b5dfc430e
commit
cba756ffa6
@@ -4,6 +4,7 @@ import java.net.URI;
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import java.time.OffsetDateTime;
|
||||
import javax.validation.Valid;
|
||||
@@ -22,9 +23,9 @@ import javax.annotation.Generated;
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
|
||||
public class Category {
|
||||
|
||||
private Long id;
|
||||
private @Nullable Long id;
|
||||
|
||||
private String name;
|
||||
private @Nullable String name;
|
||||
|
||||
public Category id(Long id) {
|
||||
this.id = id;
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import java.time.OffsetDateTime;
|
||||
import javax.validation.Valid;
|
||||
@@ -24,11 +25,11 @@ import javax.annotation.Generated;
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
|
||||
public class ModelApiResponse {
|
||||
|
||||
private Integer code;
|
||||
private @Nullable Integer code;
|
||||
|
||||
private String type;
|
||||
private @Nullable String type;
|
||||
|
||||
private String message;
|
||||
private @Nullable String message;
|
||||
|
||||
public ModelApiResponse code(Integer code) {
|
||||
this.code = code;
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import java.time.OffsetDateTime;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import java.time.OffsetDateTime;
|
||||
import javax.validation.Valid;
|
||||
@@ -25,14 +26,14 @@ import javax.annotation.Generated;
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
|
||||
public class Order {
|
||||
|
||||
private Long id;
|
||||
private @Nullable Long id;
|
||||
|
||||
private Long petId;
|
||||
private @Nullable Long petId;
|
||||
|
||||
private Integer quantity;
|
||||
private @Nullable Integer quantity;
|
||||
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
private @Nullable OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
@@ -71,7 +72,7 @@ public class Order {
|
||||
}
|
||||
}
|
||||
|
||||
private StatusEnum status;
|
||||
private @Nullable StatusEnum status;
|
||||
|
||||
private Boolean complete = false;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.openapitools.model.Category;
|
||||
import org.openapitools.model.Tag;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import java.time.OffsetDateTime;
|
||||
import javax.validation.Valid;
|
||||
@@ -28,9 +29,9 @@ import javax.annotation.Generated;
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
|
||||
public class Pet {
|
||||
|
||||
private Long id;
|
||||
private @Nullable Long id;
|
||||
|
||||
private Category category;
|
||||
private @Nullable Category category;
|
||||
|
||||
private String name;
|
||||
|
||||
@@ -78,7 +79,7 @@ public class Pet {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private StatusEnum status;
|
||||
private @Nullable StatusEnum status;
|
||||
|
||||
public Pet() {
|
||||
super();
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.net.URI;
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import java.time.OffsetDateTime;
|
||||
import javax.validation.Valid;
|
||||
@@ -22,9 +23,9 @@ import javax.annotation.Generated;
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
|
||||
public class Tag {
|
||||
|
||||
private Long id;
|
||||
private @Nullable Long id;
|
||||
|
||||
private String name;
|
||||
private @Nullable String name;
|
||||
|
||||
public Tag id(Long id) {
|
||||
this.id = id;
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.net.URI;
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import java.time.OffsetDateTime;
|
||||
import javax.validation.Valid;
|
||||
@@ -22,21 +23,21 @@ import javax.annotation.Generated;
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
|
||||
public class User {
|
||||
|
||||
private Long id;
|
||||
private @Nullable Long id;
|
||||
|
||||
private String username;
|
||||
private @Nullable String username;
|
||||
|
||||
private String firstName;
|
||||
private @Nullable String firstName;
|
||||
|
||||
private String lastName;
|
||||
private @Nullable String lastName;
|
||||
|
||||
private String email;
|
||||
private @Nullable String email;
|
||||
|
||||
private String password;
|
||||
private @Nullable String password;
|
||||
|
||||
private String phone;
|
||||
private @Nullable String phone;
|
||||
|
||||
private Integer userStatus;
|
||||
private @Nullable Integer userStatus;
|
||||
|
||||
public User id(Long id) {
|
||||
this.id = id;
|
||||
|
||||
Reference in New Issue
Block a user