mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-04 18:46:09 +00:00
[JavaSpring][21200] improve Kotlin interopability with optional values (#21202)
nullable annotations are now added to getters, setters, parameters, for optional attributes without default value
This commit is contained in:
@@ -19,6 +19,7 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -80,7 +81,7 @@ public interface DogsApi {
|
||||
)
|
||||
|
||||
default ResponseEntity<Dog> createDog(
|
||||
@Parameter(name = "Dog", description = "") @Valid @RequestBody(required = false) Dog dog
|
||||
@Parameter(name = "Dog", description = "") @Valid @RequestBody(required = false) @Nullable Dog dog
|
||||
) {
|
||||
return getDelegate().createDog(dog);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.openapitools.model.Error;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Dog {
|
||||
|
||||
private @Nullable Integer age;
|
||||
|
||||
public Dog name(String name) {
|
||||
public Dog name(@Nullable String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
@@ -38,15 +38,15 @@ public class Dog {
|
||||
@Pattern(regexp = "^[a-zA-Z]+$", message="Name must contain only letters") @Size(max = 50)
|
||||
@Schema(name = "name", example = "Rex", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
@JsonProperty("name")
|
||||
public String getName() {
|
||||
public @Nullable String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
public void setName(@Nullable String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Dog age(Integer age) {
|
||||
public Dog age(@Nullable Integer age) {
|
||||
this.age = age;
|
||||
return this;
|
||||
}
|
||||
@@ -59,11 +59,11 @@ public class Dog {
|
||||
@Min(0)
|
||||
@Schema(name = "age", example = "5", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
@JsonProperty("age")
|
||||
public Integer getAge() {
|
||||
public @Nullable Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
public void setAge(@Nullable Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Error {
|
||||
|
||||
private @Nullable String message;
|
||||
|
||||
public Error code(Integer code) {
|
||||
public Error code(@Nullable Integer code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
@@ -38,15 +38,15 @@ public class Error {
|
||||
|
||||
@Schema(name = "code", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
@JsonProperty("code")
|
||||
public Integer getCode() {
|
||||
public @Nullable Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
public void setCode(@Nullable Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Error message(String message) {
|
||||
public Error message(@Nullable String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
@@ -58,11 +58,11 @@ public class Error {
|
||||
|
||||
@Schema(name = "message", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
@JsonProperty("message")
|
||||
public String getMessage() {
|
||||
public @Nullable String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
public void setMessage(@Nullable String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user