Skip to content

[csharp] Do not inherit additional properties #17140

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

Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5708,6 +5708,10 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
co.baseName = tag;
}

protected void addParentFromContainer(CodegenModel model, Schema schema) {
model.parent = toInstantiationType(schema);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi @OpenAPITools/generator-core-team

/**
* Sets the value of the 'model.parent' property in CodegenModel, based on the value
* of the 'additionalProperties' keyword. Some language generator use class inheritance
Expand All @@ -5727,7 +5731,7 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
protected void addParentContainer(CodegenModel model, String name, Schema schema) {
final CodegenProperty property = fromProperty(name, schema, false);
addImport(model, property.complexType);
model.parent = toInstantiationType(schema);
addParentFromContainer(model, schema);
final String instantiationType = instantiationTypes.get(property.containerType);
if (instantiationType != null) {
addImport(model, instantiationType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ public void useDateTimeOffset(boolean flag) {
this.setTypeMapping();
}

@Override
protected void addParentFromContainer(CodegenModel model, Schema schema) {
// we do not want to inherit simply because additionalProperties is true
// do nothing here
}

@Override
public void processOpts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public void arrayModelTest() {
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "an array model");
Assert.assertEquals(cm.vars.size(), 0);
Assert.assertEquals(cm.parent, "List<Children>");
// TODO: additional properties should be of type Dictionary<string, List<Children>>
Assert.assertEquals(cm.imports.size(), 1);
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
}
Expand All @@ -608,7 +608,7 @@ public void mapModelTest() {
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a map model");
Assert.assertEquals(cm.vars.size(), 0);
Assert.assertEquals(cm.parent, "Dictionary<String, Children>");
// TODO: additional properties should be of type Dictionary<string, Children>
Assert.assertEquals(cm.imports.size(), 1);
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Org.OpenAPITools.Model
/// Drawing
/// </summary>
[DataContract(Name = "Drawing")]
public partial class Drawing : Dictionary<String, Fruit>, IEquatable<Drawing>, IValidatableObject
public partial class Drawing : IEquatable<Drawing>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Drawing" /> class.
Expand All @@ -39,7 +39,7 @@ public partial class Drawing : Dictionary<String, Fruit>, IEquatable<Drawing>, I
/// <param name="shapeOrNull">shapeOrNull.</param>
/// <param name="nullableShape">nullableShape.</param>
/// <param name="shapes">shapes.</param>
public Drawing(Shape mainShape = default(Shape), ShapeOrNull shapeOrNull = default(ShapeOrNull), NullableShape nullableShape = default(NullableShape), List<Shape> shapes = default(List<Shape>)) : base()
public Drawing(Shape mainShape = default(Shape), ShapeOrNull shapeOrNull = default(ShapeOrNull), NullableShape nullableShape = default(NullableShape), List<Shape> shapes = default(List<Shape>))
{
this._MainShape = mainShape;
if (this.MainShape != null)
Expand Down Expand Up @@ -174,7 +174,6 @@ public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class Drawing {\n");
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
sb.Append(" MainShape: ").Append(MainShape).Append("\n");
sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n");
sb.Append(" NullableShape: ").Append(NullableShape).Append("\n");
Expand All @@ -188,7 +187,7 @@ public override string ToString()
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
public virtual string ToJson()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}
Expand Down Expand Up @@ -221,7 +220,7 @@ public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = base.GetHashCode();
int hashCode = 41;
if (this.MainShape != null)
{
hashCode = (hashCode * 59) + this.MainShape.GetHashCode();
Expand Down Expand Up @@ -252,16 +251,6 @@ public override int GetHashCode()
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Org.OpenAPITools.Model
/// NullableClass
/// </summary>
[DataContract(Name = "NullableClass")]
public partial class NullableClass : Dictionary<String, Object>, IEquatable<NullableClass>, IValidatableObject
public partial class NullableClass : IEquatable<NullableClass>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="NullableClass" /> class.
Expand All @@ -47,7 +47,7 @@ public partial class NullableClass : Dictionary<String, Object>, IEquatable<Null
/// <param name="objectNullableProp">objectNullableProp.</param>
/// <param name="objectAndItemsNullableProp">objectAndItemsNullableProp.</param>
/// <param name="objectItemsNullable">objectItemsNullable.</param>
public NullableClass(int? integerProp = default(int?), decimal? numberProp = default(decimal?), bool? booleanProp = default(bool?), string stringProp = default(string), DateTime? dateProp = default(DateTime?), DateTime? datetimeProp = default(DateTime?), List<Object> arrayNullableProp = default(List<Object>), List<Object> arrayAndItemsNullableProp = default(List<Object>), List<Object> arrayItemsNullable = default(List<Object>), Dictionary<string, Object> objectNullableProp = default(Dictionary<string, Object>), Dictionary<string, Object> objectAndItemsNullableProp = default(Dictionary<string, Object>), Dictionary<string, Object> objectItemsNullable = default(Dictionary<string, Object>)) : base()
public NullableClass(int? integerProp = default(int?), decimal? numberProp = default(decimal?), bool? booleanProp = default(bool?), string stringProp = default(string), DateTime? dateProp = default(DateTime?), DateTime? datetimeProp = default(DateTime?), List<Object> arrayNullableProp = default(List<Object>), List<Object> arrayAndItemsNullableProp = default(List<Object>), List<Object> arrayItemsNullable = default(List<Object>), Dictionary<string, Object> objectNullableProp = default(Dictionary<string, Object>), Dictionary<string, Object> objectAndItemsNullableProp = default(Dictionary<string, Object>), Dictionary<string, Object> objectItemsNullable = default(Dictionary<string, Object>))
{
this._IntegerProp = integerProp;
if (this.IntegerProp != null)
Expand Down Expand Up @@ -415,7 +415,6 @@ public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class NullableClass {\n");
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
sb.Append(" IntegerProp: ").Append(IntegerProp).Append("\n");
sb.Append(" NumberProp: ").Append(NumberProp).Append("\n");
sb.Append(" BooleanProp: ").Append(BooleanProp).Append("\n");
Expand All @@ -437,7 +436,7 @@ public override string ToString()
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
public virtual string ToJson()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}
Expand Down Expand Up @@ -470,7 +469,7 @@ public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = base.GetHashCode();
int hashCode = 41;
if (this.IntegerProp != null)
{
hashCode = (hashCode * 59) + this.IntegerProp.GetHashCode();
Expand Down Expand Up @@ -533,16 +532,6 @@ public override int GetHashCode()
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ namespace Org.OpenAPITools.Model
/// TestInlineFreeformAdditionalPropertiesRequest
/// </summary>
[DataContract(Name = "testInlineFreeformAdditionalProperties_request")]
public partial class TestInlineFreeformAdditionalPropertiesRequest : Dictionary<String, Object>, IEquatable<TestInlineFreeformAdditionalPropertiesRequest>, IValidatableObject
public partial class TestInlineFreeformAdditionalPropertiesRequest : IEquatable<TestInlineFreeformAdditionalPropertiesRequest>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="TestInlineFreeformAdditionalPropertiesRequest" /> class.
/// </summary>
/// <param name="someProperty">someProperty.</param>
public TestInlineFreeformAdditionalPropertiesRequest(string someProperty = default(string)) : base()
public TestInlineFreeformAdditionalPropertiesRequest(string someProperty = default(string))
{
this._SomeProperty = someProperty;
if (this.SomeProperty != null)
Expand Down Expand Up @@ -84,7 +84,6 @@ public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class TestInlineFreeformAdditionalPropertiesRequest {\n");
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
sb.Append(" SomeProperty: ").Append(SomeProperty).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append("}\n");
Expand All @@ -95,7 +94,7 @@ public override string ToString()
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
public virtual string ToJson()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}
Expand Down Expand Up @@ -128,7 +127,7 @@ public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = base.GetHashCode();
int hashCode = 41;
if (this.SomeProperty != null)
{
hashCode = (hashCode * 59) + this.SomeProperty.GetHashCode();
Expand All @@ -147,16 +146,6 @@ public override int GetHashCode()
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Org.OpenAPITools.Model
/// Zebra
/// </summary>
[DataContract(Name = "zebra")]
public partial class Zebra : Dictionary<String, Object>, IEquatable<Zebra>, IValidatableObject
public partial class Zebra : IEquatable<Zebra>, IValidatableObject
{
/// <summary>
/// Defines Type
Expand Down Expand Up @@ -96,7 +96,7 @@ protected Zebra()
/// </summary>
/// <param name="type">type.</param>
/// <param name="className">className (required).</param>
public Zebra(TypeEnum? type = default(TypeEnum?), string className = default(string)) : base()
public Zebra(TypeEnum? type = default(TypeEnum?), string className = default(string))
{
// to ensure "className" is required (not null)
if (className == null)
Expand Down Expand Up @@ -150,7 +150,6 @@ public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class Zebra {\n");
sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n");
sb.Append(" Type: ").Append(Type).Append("\n");
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
Expand All @@ -162,7 +161,7 @@ public override string ToString()
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
public virtual string ToJson()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}
Expand Down Expand Up @@ -195,7 +194,7 @@ public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = base.GetHashCode();
int hashCode = 41;
hashCode = (hashCode * 59) + this.Type.GetHashCode();
if (this.ClassName != null)
{
Expand All @@ -215,16 +214,6 @@ public override int GetHashCode()
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace UseSourceGeneration.Model
/// <summary>
/// Drawing
/// </summary>
public partial class Drawing : Dictionary<String, Fruit>, IValidatableObject
public partial class Drawing : IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Drawing" /> class.
Expand All @@ -40,7 +40,7 @@ public partial class Drawing : Dictionary<String, Fruit>, IValidatableObject
/// <param name="shapeOrNull">shapeOrNull</param>
/// <param name="shapes">shapes</param>
[JsonConstructor]
public Drawing(Option<Shape?> mainShape = default, Option<NullableShape?> nullableShape = default, Option<ShapeOrNull?> shapeOrNull = default, Option<List<Shape>?> shapes = default) : base()
public Drawing(Option<Shape?> mainShape = default, Option<NullableShape?> nullableShape = default, Option<ShapeOrNull?> shapeOrNull = default, Option<List<Shape>?> shapes = default)
{
MainShapeOption = mainShape;
NullableShapeOption = nullableShape;
Expand Down Expand Up @@ -117,7 +117,6 @@ public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("class Drawing {\n");
sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n");
sb.Append(" MainShape: ").Append(MainShape).Append("\n");
sb.Append(" NullableShape: ").Append(NullableShape).Append("\n");
sb.Append(" ShapeOrNull: ").Append(ShapeOrNull).Append("\n");
Expand All @@ -133,16 +132,6 @@ public override string ToString()
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}
Expand Down
Loading