Skip to content

Commit 92a0e4e

Browse files
committed
Remove 'new' keyword from collection
1 parent 36f4452 commit 92a0e4e

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class CodegenModel {
5858
public Set<String> allMandatory;
5959

6060
public Set<String> imports = new TreeSet<String>();
61-
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, hasOptional, isArrayModel, hasChildren;
61+
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, hasOptional, isArrayModel, hasChildren, isCollectionModel;
6262
public boolean hasOnlyReadOnly = true; // true if all properties are read-only
6363
public ExternalDocumentation externalDocumentation;
6464

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
218218
}
219219
parent.getChildren().add(cm);
220220
if (parent.getDiscriminator() == null) {
221-
parent = allModels.get(parent.parent);
221+
parent = allModels.get(parent.getParent());
222222
} else {
223223
parent = null;
224224
}
@@ -1412,6 +1412,7 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
14121412

14131413
if (ModelUtils.isArraySchema(schema)) {
14141414
m.isArrayModel = true;
1415+
m.isCollectionModel = true;
14151416
m.arrayModelType = fromProperty(name, schema).complexType;
14161417
addParentContainer(m, name, schema);
14171418
} else if (schema instanceof ComposedSchema) {
@@ -1521,6 +1522,7 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
15211522
}
15221523
if (ModelUtils.isMapSchema(schema)) {
15231524
addAdditionPropertiesToCodeGenModel(m, schema);
1525+
m.isCollectionModel = true;
15241526
}
15251527
addVars(m, schema.getProperties(), schema.getRequired());
15261528
}

modules/openapi-generator/src/main/resources/aspnetcore/model.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace {{packageName}}.Models
5656
/// Returns the JSON string presentation of the object
5757
/// </summary>
5858
/// <returns>JSON string presentation of the object</returns>
59-
public {{#parent}} new {{/parent}}string ToJson()
59+
public {{#parent}}{{^isCollectionModel}}new {{/isCollectionModel}}{{/parent}}string ToJson()
6060
{
6161
return JsonConvert.SerializeObject(this, Formatting.Indented);
6262
}
@@ -68,7 +68,7 @@ namespace {{packageName}}.Models
6868
/// <returns>Boolean</returns>
6969
public override bool Equals(object obj)
7070
{
71-
if (ReferenceEquals(null, obj)) return false;
71+
if (obj is null) return false;
7272
if (ReferenceEquals(this, obj)) return true;
7373
return obj.GetType() == GetType() && Equals(({{classname}})obj);
7474
}
@@ -80,7 +80,7 @@ namespace {{packageName}}.Models
8080
/// <returns>Boolean</returns>
8181
public bool Equals({{classname}} other)
8282
{
83-
if (ReferenceEquals(null, other)) return false;
83+
if (other is null) return false;
8484
if (ReferenceEquals(this, other)) return true;
8585
8686
return {{#vars}}{{#isNotContainer}}

0 commit comments

Comments
 (0)