[Spring] fix nullable map properties (#16524)

* fix map in spring generators

* fix nullable map in spring generators
This commit is contained in:
William Cheng
2023-09-09 13:30:21 +08:00
committed by GitHub
parent 128d9da8a1
commit 18df6ed85f
78 changed files with 1914 additions and 66 deletions

View File

@@ -55,7 +55,7 @@ public class AdditionalPropertiesClass {
private Object anytype1;
private JsonNullable<Object> anytype2 = JsonNullable.undefined();
private JsonNullable<Object> anytype2 = JsonNullable.<Object>undefined();
private Object anytype3;

View File

@@ -28,16 +28,16 @@ import javax.annotation.Generated;
public class ContainerDefaultValue {
@Valid
private JsonNullable<List<String>> nullableArray = JsonNullable.undefined();
private JsonNullable<List<String>> nullableArray = JsonNullable.<List<String>>undefined();
@Valid
private JsonNullable<List<String>> nullableRequiredArray = JsonNullable.undefined();
private JsonNullable<List<String>> nullableRequiredArray = JsonNullable.<List<String>>undefined();
@Valid
private List<String> requiredArray = new ArrayList<>();
@Valid
private JsonNullable<List<String>> nullableArrayWithDefault = JsonNullable.undefined();
private JsonNullable<List<String>> nullableArrayWithDefault = JsonNullable.<List<String>>undefined();
public ContainerDefaultValue() {
super();

View File

@@ -0,0 +1,109 @@
package org.openapitools.model;
import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import org.openapitools.jackson.nullable.JsonNullable;
import java.time.OffsetDateTime;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.*;
import javax.annotation.Generated;
/**
* NullableMapProperty
*/
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public class NullableMapProperty {
@Valid
private JsonNullable<Map<String, String>> languageValues = JsonNullable.<Map<String, String>>undefined();
public NullableMapProperty languageValues(Map<String, String> languageValues) {
this.languageValues = JsonNullable.of(languageValues);
return this;
}
public NullableMapProperty putLanguageValuesItem(String key, String languageValuesItem) {
if (this.languageValues == null || !this.languageValues.isPresent()) {
this.languageValues = JsonNullable.of(new HashMap<>());
}
this.languageValues.get().put(key, languageValuesItem);
return this;
}
/**
* Get languageValues
* @return languageValues
*/
@ApiModelProperty(value = "")
@JsonProperty("languageValues")
public JsonNullable<Map<String, String>> getLanguageValues() {
return languageValues;
}
public void setLanguageValues(JsonNullable<Map<String, String>> languageValues) {
this.languageValues = languageValues;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
NullableMapProperty nullableMapProperty = (NullableMapProperty) o;
return equalsNullable(this.languageValues, nullableMapProperty.languageValues);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(hashCodeNullable(languageValues));
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class NullableMapProperty {\n");
sb.append(" languageValues: ").append(toIndentedString(languageValues)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@@ -2186,6 +2186,14 @@ components:
property name with spaces:
type: string
type: object
NullableMapProperty:
properties:
languageValues:
additionalProperties:
type: string
nullable: true
type: object
type: object
updatePetWithForm_request:
properties:
name: