Skip to content

[JavaSpring][21200] improve Kotlin interopability with optional values #21202

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.virtualan.annotation.VirtualService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
{{/jdk8-no-delegate}}
import org.springframework.lang.Nullable;
{{^useResponseEntity}}
import org.springframework.http.HttpStatus;
{{/useResponseEntity}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
{{#useResponseEntity}}
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.springframework.http.MediaType;
{{#useResponseEntity}}
import org.springframework.http.ResponseEntity;
{{/useResponseEntity}}
import org.springframework.lang.Nullable;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.multipart.MultipartFile;
{{#reactive}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isBodyParam}}{{>paramDoc}}{{#useBeanValidation}} @Valid{{>beanValidationBodyParams}}{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}} {{paramName}}{{/isBodyParam}}
{{#isBodyParam}}{{>paramDoc}}{{#useBeanValidation}} @Valid{{>beanValidationBodyParams}}{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{^reactive}}{{>nullableAnnotation}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}} {{paramName}}{{/isBodyParam}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isCookieParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}} @CookieValue(name = "{{baseName}}"{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{>dateTimeParam}} {{>optionalDataType}} {{paramName}}{{/isCookieParam}}
{{#isCookieParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}} @CookieValue(name = "{{baseName}}"{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{>dateTimeParam}} {{>nullableAnnotation}}{{>optionalDataType}} {{paramName}}{{/isCookieParam}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isHeaderParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{vendorExtensions.x-field-extra-annotation}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}} @RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{>dateTimeParam}} {{>optionalDataType}} {{paramName}}{{/isHeaderParam}}
{{#isHeaderParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{vendorExtensions.x-field-extra-annotation}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}} @RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{>dateTimeParam}} {{>nullableAnnotation}}{{>optionalDataType}} {{paramName}}{{/isHeaderParam}}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.springframework.http.HttpStatus;
{{#useResponseEntity}}
import org.springframework.http.ResponseEntity;
{{/useResponseEntity}}
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.service.annotation.*;
import org.springframework.web.multipart.MultipartFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
{{^lombok.Data}}

{{! begin feature: fluent setter methods }}
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
public {{classname}} {{name}}({{>nullableAnnotation}}{{{datatypeWithEnum}}} {{name}}) {
{{#openApiNullable}}
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}Optional.of{{#optionalAcceptNullable}}Nullable{{/optionalAcceptNullable}}({{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}}{{name}}{{#isNullable}}){{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}){{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}};
{{/openApiNullable}}
Expand Down Expand Up @@ -254,7 +254,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
{{#deprecated}}
@Deprecated
{{/deprecated}}
public {{>nullableDataTypeBeanValidation}} {{getter}}() {
public {{>nullableAnnotation}}{{>nullableDataTypeBeanValidation}} {{getter}}() {
return {{name}};
}
{{/lombok.Getter}}
Expand All @@ -271,7 +271,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
{{#deprecated}}
@Deprecated
{{/deprecated}}
public void {{setter}}({{>nullableDataType}} {{name}}) {
public void {{setter}}({{>nullableAnnotation}}{{>nullableDataType}} {{name}}) {
this.{{name}} = {{name}};
}
{{/lombok.Setter}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isQueryParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{vendorExtensions.x-field-extra-annotation}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}}{{#useBeanValidation}} @Valid{{/useBeanValidation}}{{^isModel}} @RequestParam(value = {{#isMap}}""{{/isMap}}{{^isMap}}"{{baseName}}"{{/isMap}}{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/isModel}}{{>dateTimeParam}}{{#isDeprecated}} @Deprecated{{/isDeprecated}} {{>optionalDataType}} {{paramName}}{{/isQueryParam}}
{{#isQueryParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{vendorExtensions.x-field-extra-annotation}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{>paramDoc}}{{#useBeanValidation}} @Valid{{/useBeanValidation}}{{^isModel}} @RequestParam(value = {{#isMap}}""{{/isMap}}{{^isMap}}"{{baseName}}"{{/isMap}}{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/isModel}}{{>dateTimeParam}}{{#isDeprecated}} @Deprecated{{/isDeprecated}} {{>nullableAnnotation}}{{>optionalDataType}} {{paramName}}{{/isQueryParam}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.swagger.v3.oas.annotations.media.ExampleObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -96,7 +97,7 @@ ResponseEntity<Void> addPet(

ResponseEntity<Void> deletePet(
@Parameter(name = "petId", description = "Pet id to delete", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId,
@Parameter(name = "api_key", description = "", in = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) String apiKey
@Parameter(name = "api_key", description = "", in = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) @Nullable String apiKey
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.swagger.v3.oas.annotations.media.ExampleObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.swagger.v3.oas.annotations.media.ExampleObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Category {

private @Nullable String name;

public Category id(Long id) {
public Category id(@Nullable Long id) {
this.id = id;
return this;
}
Expand All @@ -39,15 +39,15 @@ public Category id(Long id) {

@Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("id")
public Long getId() {
public @Nullable Long getId() {
return id;
}

public void setId(Long id) {
public void setId(@Nullable Long id) {
this.id = id;
}

public Category name(String name) {
public Category name(@Nullable String name) {
this.name = name;
return this;
}
Expand All @@ -59,11 +59,11 @@ public Category name(String name) {
@Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$")
@Schema(name = "name", 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ModelApiResponse {

private @Nullable String message;

public ModelApiResponse code(Integer code) {
public ModelApiResponse code(@Nullable Integer code) {
this.code = code;
return this;
}
Expand All @@ -43,15 +43,15 @@ public ModelApiResponse code(Integer code) {

@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 ModelApiResponse type(String type) {
public ModelApiResponse type(@Nullable String type) {
this.type = type;
return this;
}
Expand All @@ -63,15 +63,15 @@ public ModelApiResponse type(String type) {

@Schema(name = "type", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("type")
public String getType() {
public @Nullable String getType() {
return type;
}

public void setType(String type) {
public void setType(@Nullable String type) {
this.type = type;
}

public ModelApiResponse message(String message) {
public ModelApiResponse message(@Nullable String message) {
this.message = message;
return this;
}
Expand All @@ -83,11 +83,11 @@ public ModelApiResponse message(String message) {

@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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static StatusEnum fromValue(String value) {

private Boolean complete = false;

public Order id(Long id) {
public Order id(@Nullable Long id) {
this.id = id;
return this;
}
Expand All @@ -90,15 +90,15 @@ public Order id(Long id) {

@Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("id")
public Long getId() {
public @Nullable Long getId() {
return id;
}

public void setId(Long id) {
public void setId(@Nullable Long id) {
this.id = id;
}

public Order petId(Long petId) {
public Order petId(@Nullable Long petId) {
this.petId = petId;
return this;
}
Expand All @@ -110,15 +110,15 @@ public Order petId(Long petId) {

@Schema(name = "petId", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("petId")
public Long getPetId() {
public @Nullable Long getPetId() {
return petId;
}

public void setPetId(Long petId) {
public void setPetId(@Nullable Long petId) {
this.petId = petId;
}

public Order quantity(Integer quantity) {
public Order quantity(@Nullable Integer quantity) {
this.quantity = quantity;
return this;
}
Expand All @@ -130,15 +130,15 @@ public Order quantity(Integer quantity) {

@Schema(name = "quantity", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("quantity")
public Integer getQuantity() {
public @Nullable Integer getQuantity() {
return quantity;
}

public void setQuantity(Integer quantity) {
public void setQuantity(@Nullable Integer quantity) {
this.quantity = quantity;
}

public Order shipDate(OffsetDateTime shipDate) {
public Order shipDate(@Nullable OffsetDateTime shipDate) {
this.shipDate = shipDate;
return this;
}
Expand All @@ -150,15 +150,15 @@ public Order shipDate(OffsetDateTime shipDate) {
@Valid
@Schema(name = "shipDate", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("shipDate")
public OffsetDateTime getShipDate() {
public @Nullable OffsetDateTime getShipDate() {
return shipDate;
}

public void setShipDate(OffsetDateTime shipDate) {
public void setShipDate(@Nullable OffsetDateTime shipDate) {
this.shipDate = shipDate;
}

public Order status(StatusEnum status) {
public Order status(@Nullable StatusEnum status) {
this.status = status;
return this;
}
Expand All @@ -170,11 +170,11 @@ public Order status(StatusEnum status) {

@Schema(name = "status", description = "Order Status", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("status")
public StatusEnum getStatus() {
public @Nullable StatusEnum getStatus() {
return status;
}

public void setStatus(StatusEnum status) {
public void setStatus(@Nullable StatusEnum status) {
this.status = status;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Pet(String name, List<String> photoUrls) {
this.photoUrls = photoUrls;
}

public Pet id(Long id) {
public Pet id(@Nullable Long id) {
this.id = id;
return this;
}
Expand All @@ -105,15 +105,15 @@ public Pet id(Long id) {

@Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("id")
public Long getId() {
public @Nullable Long getId() {
return id;
}

public void setId(Long id) {
public void setId(@Nullable Long id) {
this.id = id;
}

public Pet category(Category category) {
public Pet category(@Nullable Category category) {
this.category = category;
return this;
}
Expand All @@ -125,11 +125,11 @@ public Pet category(Category category) {
@Valid
@Schema(name = "category", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("category")
public Category getCategory() {
public @Nullable Category getCategory() {
return category;
}

public void setCategory(Category category) {
public void setCategory(@Nullable Category category) {
this.category = category;
}

Expand Down Expand Up @@ -215,7 +215,7 @@ public void setTags(List<@Valid Tag> tags) {
this.tags = tags;
}

public Pet status(StatusEnum status) {
public Pet status(@Nullable StatusEnum status) {
this.status = status;
return this;
}
Expand All @@ -227,11 +227,11 @@ public Pet status(StatusEnum status) {

@Schema(name = "status", description = "pet status in the store", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("status")
public StatusEnum getStatus() {
public @Nullable StatusEnum getStatus() {
return status;
}

public void setStatus(StatusEnum status) {
public void setStatus(@Nullable StatusEnum status) {
this.status = status;
}

Expand Down
Loading
Loading