Update allOf to not always be nullable (#12861)

* added nonNullableVars

* added return property to operation

* added return property to operation

* build samples

* added inner enum

* build samples

* allOf no longer always nullable

* added a comment
This commit is contained in:
devhl-labs
2022-08-15 12:47:51 -04:00
committed by GitHub
parent 17f9a28093
commit 7e4fa70067
12 changed files with 33 additions and 86 deletions

View File

@@ -3506,7 +3506,10 @@ public class DefaultCodegen implements CodegenConfig {
if (Boolean.FALSE.equals(p.getNullable())) {
LOGGER.warn("Schema '{}' is any type, which includes the 'null' value. 'nullable' cannot be set to 'false'", p.getName());
}
property.isNullable = true;
ComposedSchema composedSchema = p instanceof ComposedSchema
? (ComposedSchema) p
: null;
property.isNullable = property.isNullable || composedSchema == null || composedSchema.getAllOf() == null || composedSchema.getAllOf().size() == 0;
if (languageSpecificPrimitives.contains(property.dataType)) {
property.isPrimitiveType = true;
}

View File

@@ -33,7 +33,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// Gets or Sets SingleRefType
/// </summary>
[DataMember(Name="SingleRefType", EmitDefaultValue=true)]
[DataMember(Name="SingleRefType", EmitDefaultValue=false)]
public SingleRefType? SingleRefType { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="AllOfWithSingleRef" /> class.
@@ -42,7 +42,6 @@ namespace Org.OpenAPITools.Model
/// <param name="singleRefType">singleRefType.</param>
public AllOfWithSingleRef(string username = default(string), SingleRefType? singleRefType = default(SingleRefType?))
{
this.SingleRefType = singleRefType;
this.Username = username;
this.SingleRefType = singleRefType;
}

View File

@@ -23,10 +23,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.SingleRefType;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
@@ -43,7 +39,7 @@ public class AllOfWithSingleRef {
private String username;
public static final String JSON_PROPERTY_SINGLE_REF_TYPE = "SingleRefType";
private JsonNullable<SingleRefType> singleRefType = JsonNullable.<SingleRefType>undefined();
private SingleRefType singleRefType;
public AllOfWithSingleRef() {
}
@@ -76,8 +72,8 @@ public class AllOfWithSingleRef {
public AllOfWithSingleRef singleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);
this.singleRefType = singleRefType;
return this;
}
@@ -87,26 +83,18 @@ public class AllOfWithSingleRef {
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
@JsonIgnore
public SingleRefType getSingleRefType() {
return singleRefType.orElse(null);
}
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public JsonNullable<SingleRefType> getSingleRefType_JsonNullable() {
public SingleRefType getSingleRefType() {
return singleRefType;
}
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
public void setSingleRefType_JsonNullable(JsonNullable<SingleRefType> singleRefType) {
this.singleRefType = singleRefType;
}
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setSingleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);
this.singleRefType = singleRefType;
}
@@ -120,23 +108,12 @@ public class AllOfWithSingleRef {
}
AllOfWithSingleRef allOfWithSingleRef = (AllOfWithSingleRef) o;
return Objects.equals(this.username, allOfWithSingleRef.username) &&
equalsNullable(this.singleRefType, allOfWithSingleRef.singleRefType);
}
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()));
Objects.equals(this.singleRefType, allOfWithSingleRef.singleRefType);
}
@Override
public int hashCode() {
return Objects.hash(username, hashCodeNullable(singleRefType));
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
return Objects.hash(username, singleRefType);
}
@Override

View File

@@ -23,10 +23,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.SingleRefType;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
@@ -43,7 +39,7 @@ public class AllOfWithSingleRef {
private String username;
public static final String JSON_PROPERTY_SINGLE_REF_TYPE = "SingleRefType";
private JsonNullable<SingleRefType> singleRefType = JsonNullable.<SingleRefType>undefined();
private SingleRefType singleRefType;
public AllOfWithSingleRef() {
}
@@ -76,8 +72,8 @@ public class AllOfWithSingleRef {
public AllOfWithSingleRef singleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);
this.singleRefType = singleRefType;
return this;
}
@@ -87,26 +83,18 @@ public class AllOfWithSingleRef {
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
@JsonIgnore
public SingleRefType getSingleRefType() {
return singleRefType.orElse(null);
}
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public JsonNullable<SingleRefType> getSingleRefType_JsonNullable() {
public SingleRefType getSingleRefType() {
return singleRefType;
}
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
public void setSingleRefType_JsonNullable(JsonNullable<SingleRefType> singleRefType) {
this.singleRefType = singleRefType;
}
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setSingleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);
this.singleRefType = singleRefType;
}
@@ -120,23 +108,12 @@ public class AllOfWithSingleRef {
}
AllOfWithSingleRef allOfWithSingleRef = (AllOfWithSingleRef) o;
return Objects.equals(this.username, allOfWithSingleRef.username) &&
equalsNullable(this.singleRefType, allOfWithSingleRef.singleRefType);
}
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()));
Objects.equals(this.singleRefType, allOfWithSingleRef.singleRefType);
}
@Override
public int hashCode() {
return Objects.hash(username, hashCodeNullable(singleRefType));
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
return Objects.hash(username, singleRefType);
}
@Override

View File

@@ -80,7 +80,7 @@ class AllOfWithSingleRef implements ModelInterface, ArrayAccess, \JsonSerializab
*/
protected static array $openAPINullables = [
'username' => false,
'single_ref_type' => true
'single_ref_type' => false
];
/**
@@ -336,14 +336,7 @@ class AllOfWithSingleRef implements ModelInterface, ArrayAccess, \JsonSerializab
{
if (is_null($single_ref_type)) {
array_push($this->openAPINullablesSetToNull, 'single_ref_type');
} else {
$nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
$index = array_search('single_ref_type', $nullablesSetToNull);
if ($index !== FALSE) {
unset($nullablesSetToNull[$index]);
$this->setOpenAPINullablesSetToNull($nullablesSetToNull);
}
throw new \InvalidArgumentException('non-nullable single_ref_type cannot be null');
}
$this->container['single_ref_type'] = $single_ref_type;

View File

@@ -43,7 +43,6 @@ module Petstore
# List of attributes with nullable: true
def self.openapi_nullable
Set.new([
:'single_ref_type'
])
end

View File

@@ -43,7 +43,6 @@ module Petstore
# List of attributes with nullable: true
def self.openapi_nullable
Set.new([
:'single_ref_type'
])
end

View File

@@ -37,7 +37,7 @@ export interface AllOfWithSingleRef {
* @type {SingleRefType}
* @memberof AllOfWithSingleRef
*/
singleRefType?: SingleRefType | null;
singleRefType?: SingleRefType;
}
/**

View File

@@ -55,7 +55,7 @@ class AllOfWithSingleRef {
@override
int get hashCode =>
username.hashCode +
(singleRefType == null ? 0 : singleRefType.hashCode);
singleRefType.hashCode;
factory AllOfWithSingleRef.fromJson(Map<String, dynamic> json) => _$AllOfWithSingleRefFromJson(json);

View File

@@ -52,7 +52,7 @@ class _$AllOfWithSingleRefSerializer implements StructuredSerializer<AllOfWithSi
result
..add(r'SingleRefType')
..add(serializers.serialize(object.singleRefType,
specifiedType: const FullType.nullable(SingleRefType)));
specifiedType: const FullType(SingleRefType)));
}
return result;
}
@@ -76,8 +76,7 @@ class _$AllOfWithSingleRefSerializer implements StructuredSerializer<AllOfWithSi
break;
case r'SingleRefType':
final valueDes = serializers.deserialize(value,
specifiedType: const FullType.nullable(SingleRefType)) as SingleRefType?;
if (valueDes == null) continue;
specifiedType: const FullType(SingleRefType)) as SingleRefType;
result.singleRefType = valueDes;
break;
}

View File

@@ -57,7 +57,8 @@ class AllOfWithSingleRef(object):
if username is not None:
self.username = username
self.single_ref_type = single_ref_type
if single_ref_type is not None:
self.single_ref_type = single_ref_type
@property
def username(self):

View File

@@ -12,7 +12,7 @@ class AllOfWithSingleRef {
/** @var string $username */
public $username = "";
/** @var SingleRefType|null $singleRefType */
public $singleRefType = null;
/** @var SingleRefType $singleRefType */
public $singleRefType;
}