Skip to content

Commit c89c889

Browse files
Fix how the type is calculated for deep inline arrays
1 parent 7ab9364 commit c89c889

File tree

98 files changed

+2425
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2425
-70
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ public String getTypeDeclaration(Schema p) {
16241624
Schema<?> target = ModelUtils.isGenerateAliasAsModel() ? p : schema;
16251625
if (ModelUtils.isArraySchema(target)) {
16261626
Schema<?> items = getSchemaItems(schema);
1627-
return getSchemaType(target) + "<" + getTypeDeclarationForArray(items) + ">";
1627+
return typeMapping.get("array") + "<" + getTypeDeclarationForArray(items) + ">";
16281628
} else if (ModelUtils.isMapSchema(p)) {
16291629
// Should we also support maps of maps?
16301630
Schema<?> inner = ModelUtils.getAdditionalProperties(p);

modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpModelTest.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,19 @@ public void nullablePropertyWithoutNullableReferenceTypesTest() {
368368
public void nullablePropertyWithNullableReferenceTypesTest() {
369369
final Schema model = new Schema()
370370
.description("a sample model")
371-
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT).nullable(true))
371+
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)
372+
.nullable(true))
372373
.addProperties("urls", new ArraySchema()
373-
.items(new StringSchema()).nullable(true))
374+
.items(new StringSchema())
375+
.nullable(true))
374376
.addProperties("name", new StringSchema().nullable(true))
375-
.addProperties("subObject", new Schema().addProperties("name", new StringSchema()).nullable(true))
377+
.addProperties("subObject", new Schema().addProperties("name", new StringSchema())
378+
.nullable(true))
379+
.addProperties("deepAliasArray", new ArraySchema()
380+
.items(new ArraySchema()
381+
.items(new StringSchema())
382+
.nullable(true))
383+
.nullable(true))
376384
.addRequiredItem("id");
377385
final DefaultCodegen codegen = new AspNetServerCodegen();
378386
codegen.processOpts();
@@ -385,7 +393,7 @@ public void nullablePropertyWithNullableReferenceTypesTest() {
385393
Assert.assertEquals(cm.name, "sample");
386394
Assert.assertEquals(cm.classname, "Sample");
387395
Assert.assertEquals(cm.description, "a sample model");
388-
Assert.assertEquals(cm.vars.size(), 4);
396+
Assert.assertEquals(cm.vars.size(), 5);
389397

390398
final CodegenProperty property1 = cm.vars.get(0);
391399
Assert.assertEquals(property1.baseName, "id");
@@ -398,7 +406,7 @@ public void nullablePropertyWithNullableReferenceTypesTest() {
398406

399407
final CodegenProperty property2 = cm.vars.get(1);
400408
Assert.assertEquals(property2.baseName, "urls");
401-
Assert.assertEquals(property2.dataType, "List?<string>");
409+
Assert.assertEquals(property2.dataType, "List<string>");
402410
Assert.assertEquals(property2.name, "Urls");
403411
Assert.assertNull(property2.defaultValue);
404412
Assert.assertEquals(property2.baseType, "List?");
@@ -424,6 +432,17 @@ public void nullablePropertyWithNullableReferenceTypesTest() {
424432
Assert.assertEquals(property4.baseType, "Object?");
425433
Assert.assertFalse(property4.required);
426434
Assert.assertFalse(property4.isPrimitiveType);
435+
436+
final CodegenProperty property5 = cm.vars.get(4);
437+
Assert.assertEquals(property5.baseName, "deepAliasArray");
438+
Assert.assertEquals(property5.dataType, "List<List<string>>");
439+
Assert.assertEquals(property5.name, "DeepAliasArray");
440+
Assert.assertNull(property5.defaultValue);
441+
Assert.assertEquals(property5.baseType, "List?");
442+
Assert.assertEquals(property5.containerType, "array");
443+
Assert.assertFalse(property5.required);
444+
Assert.assertFalse(property5.isPrimitiveType);
445+
Assert.assertTrue(property5.isContainer);
427446
}
428447

429448
@Test(description = "convert a model with list property")

modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,6 +2935,16 @@ components:
29352935
description: list of named parameters for current message
29362936
additionalProperties:
29372937
type: string
2938+
list:
2939+
type: array
2940+
items:
2941+
type: string
2942+
deepList:
2943+
type: array
2944+
items:
2945+
type: array
2946+
items:
2947+
type: string
29382948
TestResult:
29392949
type: object
29402950
allOf:

samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,6 +2686,16 @@ components:
26862686
type: string
26872687
description: list of named parameters for current message
26882688
type: object
2689+
list:
2690+
items:
2691+
type: string
2692+
type: array
2693+
deepList:
2694+
items:
2695+
items:
2696+
type: string
2697+
type: array
2698+
type: array
26892699
type: object
26902700
TestResult:
26912701
allOf:

samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/Result.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**Code** | **string** | Result code | [optional]
88
**Data** | **Dictionary&lt;string, string&gt;** | list of named parameters for current message | [optional]
9+
**DeepList** | **List&lt;List&lt;string&gt;&gt;** | | [optional]
10+
**List** | **List&lt;string&gt;** | | [optional]
911
**Uuid** | **string** | Result unique identifier | [optional]
1012

1113
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/TestResult.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**Code** | **TestResultCode** | | [optional]
88
**Data** | **Dictionary&lt;string, string&gt;** | list of named parameters for current message | [optional]
9+
**DeepList** | **List&lt;List&lt;string&gt;&gt;** | | [optional]
10+
**List** | **List&lt;string&gt;** | | [optional]
911
**Uuid** | **string** | Result unique identifier | [optional]
1012

1113
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/Result.cs

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ public partial class Result : IValidatableObject
3434
/// </summary>
3535
/// <param name="code">Result code</param>
3636
/// <param name="data">list of named parameters for current message</param>
37+
/// <param name="deepList">deepList</param>
38+
/// <param name="list">list</param>
3739
/// <param name="uuid">Result unique identifier</param>
3840
[JsonConstructor]
39-
public Result(Option<string> code = default, Option<Dictionary<string, string>> data = default, Option<string> uuid = default)
41+
public Result(Option<string> code = default, Option<Dictionary<string, string>> data = default, Option<List<List<string>>> deepList = default, Option<List<string>> list = default, Option<string> uuid = default)
4042
{
4143
CodeOption = code;
4244
DataOption = data;
45+
DeepListOption = deepList;
46+
ListOption = list;
4347
UuidOption = uuid;
4448
OnCreated();
4549
}
@@ -74,6 +78,32 @@ public Result(Option<string> code = default, Option<Dictionary<string, string>>
7478
[JsonPropertyName("data")]
7579
public Dictionary<string, string> Data { get { return this.DataOption; } set { this.DataOption = new Option<Dictionary<string, string>>(value); } }
7680

81+
/// <summary>
82+
/// Used to track the state of DeepList
83+
/// </summary>
84+
[JsonIgnore]
85+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
86+
public Option<List<List<string>>> DeepListOption { get; private set; }
87+
88+
/// <summary>
89+
/// Gets or Sets DeepList
90+
/// </summary>
91+
[JsonPropertyName("deepList")]
92+
public List<List<string>> DeepList { get { return this.DeepListOption; } set { this.DeepListOption = new Option<List<List<string>>>(value); } }
93+
94+
/// <summary>
95+
/// Used to track the state of List
96+
/// </summary>
97+
[JsonIgnore]
98+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
99+
public Option<List<string>> ListOption { get; private set; }
100+
101+
/// <summary>
102+
/// Gets or Sets List
103+
/// </summary>
104+
[JsonPropertyName("list")]
105+
public List<string> List { get { return this.ListOption; } set { this.ListOption = new Option<List<string>>(value); } }
106+
77107
/// <summary>
78108
/// Used to track the state of Uuid
79109
/// </summary>
@@ -104,6 +134,8 @@ public override string ToString()
104134
sb.Append("class Result {\n");
105135
sb.Append(" Code: ").Append(Code).Append("\n");
106136
sb.Append(" Data: ").Append(Data).Append("\n");
137+
sb.Append(" DeepList: ").Append(DeepList).Append("\n");
138+
sb.Append(" List: ").Append(List).Append("\n");
107139
sb.Append(" Uuid: ").Append(Uuid).Append("\n");
108140
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
109141
sb.Append("}\n");
@@ -145,6 +177,8 @@ public override Result Read(ref Utf8JsonReader utf8JsonReader, Type typeToConver
145177

146178
Option<string> code = default;
147179
Option<Dictionary<string, string>> data = default;
180+
Option<List<List<string>>> deepList = default;
181+
Option<List<string>> list = default;
148182
Option<string> uuid = default;
149183

150184
while (utf8JsonReader.Read())
@@ -168,6 +202,12 @@ public override Result Read(ref Utf8JsonReader utf8JsonReader, Type typeToConver
168202
case "data":
169203
data = new Option<Dictionary<string, string>>(JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions));
170204
break;
205+
case "deepList":
206+
deepList = new Option<List<List<string>>>(JsonSerializer.Deserialize<List<List<string>>>(ref utf8JsonReader, jsonSerializerOptions));
207+
break;
208+
case "list":
209+
list = new Option<List<string>>(JsonSerializer.Deserialize<List<string>>(ref utf8JsonReader, jsonSerializerOptions));
210+
break;
171211
case "uuid":
172212
uuid = new Option<string>(utf8JsonReader.GetString());
173213
break;
@@ -183,10 +223,16 @@ public override Result Read(ref Utf8JsonReader utf8JsonReader, Type typeToConver
183223
if (data.IsSet && data.Value == null)
184224
throw new ArgumentNullException(nameof(data), "Property is not nullable for class Result.");
185225

226+
if (deepList.IsSet && deepList.Value == null)
227+
throw new ArgumentNullException(nameof(deepList), "Property is not nullable for class Result.");
228+
229+
if (list.IsSet && list.Value == null)
230+
throw new ArgumentNullException(nameof(list), "Property is not nullable for class Result.");
231+
186232
if (uuid.IsSet && uuid.Value == null)
187233
throw new ArgumentNullException(nameof(uuid), "Property is not nullable for class Result.");
188234

189-
return new Result(code, data, uuid);
235+
return new Result(code, data, deepList, list, uuid);
190236
}
191237

192238
/// <summary>
@@ -219,6 +265,12 @@ public void WriteProperties(Utf8JsonWriter writer, Result result, JsonSerializer
219265
if (result.DataOption.IsSet && result.Data == null)
220266
throw new ArgumentNullException(nameof(result.Data), "Property is required for class Result.");
221267

268+
if (result.DeepListOption.IsSet && result.DeepList == null)
269+
throw new ArgumentNullException(nameof(result.DeepList), "Property is required for class Result.");
270+
271+
if (result.ListOption.IsSet && result.List == null)
272+
throw new ArgumentNullException(nameof(result.List), "Property is required for class Result.");
273+
222274
if (result.UuidOption.IsSet && result.Uuid == null)
223275
throw new ArgumentNullException(nameof(result.Uuid), "Property is required for class Result.");
224276

@@ -230,6 +282,16 @@ public void WriteProperties(Utf8JsonWriter writer, Result result, JsonSerializer
230282
writer.WritePropertyName("data");
231283
JsonSerializer.Serialize(writer, result.Data, jsonSerializerOptions);
232284
}
285+
if (result.DeepListOption.IsSet)
286+
{
287+
writer.WritePropertyName("deepList");
288+
JsonSerializer.Serialize(writer, result.DeepList, jsonSerializerOptions);
289+
}
290+
if (result.ListOption.IsSet)
291+
{
292+
writer.WritePropertyName("list");
293+
JsonSerializer.Serialize(writer, result.List, jsonSerializerOptions);
294+
}
233295
if (result.UuidOption.IsSet)
234296
writer.WriteString("uuid", result.Uuid);
235297
}

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestResult.cs

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ public partial class TestResult : IValidatableObject
3434
/// </summary>
3535
/// <param name="code">code</param>
3636
/// <param name="data">list of named parameters for current message</param>
37+
/// <param name="deepList">deepList</param>
38+
/// <param name="list">list</param>
3739
/// <param name="uuid">Result unique identifier</param>
3840
[JsonConstructor]
39-
public TestResult(Option<TestResultCode?> code = default, Option<Dictionary<string, string>> data = default, Option<string> uuid = default)
41+
public TestResult(Option<TestResultCode?> code = default, Option<Dictionary<string, string>> data = default, Option<List<List<string>>> deepList = default, Option<List<string>> list = default, Option<string> uuid = default)
4042
{
4143
CodeOption = code;
4244
DataOption = data;
45+
DeepListOption = deepList;
46+
ListOption = list;
4347
UuidOption = uuid;
4448
OnCreated();
4549
}
@@ -73,6 +77,32 @@ public TestResult(Option<TestResultCode?> code = default, Option<Dictionary<stri
7377
[JsonPropertyName("data")]
7478
public Dictionary<string, string> Data { get { return this.DataOption; } set { this.DataOption = new Option<Dictionary<string, string>>(value); } }
7579

80+
/// <summary>
81+
/// Used to track the state of DeepList
82+
/// </summary>
83+
[JsonIgnore]
84+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
85+
public Option<List<List<string>>> DeepListOption { get; private set; }
86+
87+
/// <summary>
88+
/// Gets or Sets DeepList
89+
/// </summary>
90+
[JsonPropertyName("deepList")]
91+
public List<List<string>> DeepList { get { return this.DeepListOption; } set { this.DeepListOption = new Option<List<List<string>>>(value); } }
92+
93+
/// <summary>
94+
/// Used to track the state of List
95+
/// </summary>
96+
[JsonIgnore]
97+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
98+
public Option<List<string>> ListOption { get; private set; }
99+
100+
/// <summary>
101+
/// Gets or Sets List
102+
/// </summary>
103+
[JsonPropertyName("list")]
104+
public List<string> List { get { return this.ListOption; } set { this.ListOption = new Option<List<string>>(value); } }
105+
76106
/// <summary>
77107
/// Used to track the state of Uuid
78108
/// </summary>
@@ -103,6 +133,8 @@ public override string ToString()
103133
sb.Append("class TestResult {\n");
104134
sb.Append(" Code: ").Append(Code).Append("\n");
105135
sb.Append(" Data: ").Append(Data).Append("\n");
136+
sb.Append(" DeepList: ").Append(DeepList).Append("\n");
137+
sb.Append(" List: ").Append(List).Append("\n");
106138
sb.Append(" Uuid: ").Append(Uuid).Append("\n");
107139
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
108140
sb.Append("}\n");
@@ -144,6 +176,8 @@ public override TestResult Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
144176

145177
Option<TestResultCode?> code = default;
146178
Option<Dictionary<string, string>> data = default;
179+
Option<List<List<string>>> deepList = default;
180+
Option<List<string>> list = default;
147181
Option<string> uuid = default;
148182

149183
while (utf8JsonReader.Read())
@@ -169,6 +203,12 @@ public override TestResult Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
169203
case "data":
170204
data = new Option<Dictionary<string, string>>(JsonSerializer.Deserialize<Dictionary<string, string>>(ref utf8JsonReader, jsonSerializerOptions));
171205
break;
206+
case "deepList":
207+
deepList = new Option<List<List<string>>>(JsonSerializer.Deserialize<List<List<string>>>(ref utf8JsonReader, jsonSerializerOptions));
208+
break;
209+
case "list":
210+
list = new Option<List<string>>(JsonSerializer.Deserialize<List<string>>(ref utf8JsonReader, jsonSerializerOptions));
211+
break;
172212
case "uuid":
173213
uuid = new Option<string>(utf8JsonReader.GetString());
174214
break;
@@ -184,10 +224,16 @@ public override TestResult Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
184224
if (data.IsSet && data.Value == null)
185225
throw new ArgumentNullException(nameof(data), "Property is not nullable for class TestResult.");
186226

227+
if (deepList.IsSet && deepList.Value == null)
228+
throw new ArgumentNullException(nameof(deepList), "Property is not nullable for class TestResult.");
229+
230+
if (list.IsSet && list.Value == null)
231+
throw new ArgumentNullException(nameof(list), "Property is not nullable for class TestResult.");
232+
187233
if (uuid.IsSet && uuid.Value == null)
188234
throw new ArgumentNullException(nameof(uuid), "Property is not nullable for class TestResult.");
189235

190-
return new TestResult(code, data, uuid);
236+
return new TestResult(code, data, deepList, list, uuid);
191237
}
192238

193239
/// <summary>
@@ -217,6 +263,12 @@ public void WriteProperties(Utf8JsonWriter writer, TestResult testResult, JsonSe
217263
if (testResult.DataOption.IsSet && testResult.Data == null)
218264
throw new ArgumentNullException(nameof(testResult.Data), "Property is required for class TestResult.");
219265

266+
if (testResult.DeepListOption.IsSet && testResult.DeepList == null)
267+
throw new ArgumentNullException(nameof(testResult.DeepList), "Property is required for class TestResult.");
268+
269+
if (testResult.ListOption.IsSet && testResult.List == null)
270+
throw new ArgumentNullException(nameof(testResult.List), "Property is required for class TestResult.");
271+
220272
if (testResult.UuidOption.IsSet && testResult.Uuid == null)
221273
throw new ArgumentNullException(nameof(testResult.Uuid), "Property is required for class TestResult.");
222274

@@ -230,6 +282,16 @@ public void WriteProperties(Utf8JsonWriter writer, TestResult testResult, JsonSe
230282
writer.WritePropertyName("data");
231283
JsonSerializer.Serialize(writer, testResult.Data, jsonSerializerOptions);
232284
}
285+
if (testResult.DeepListOption.IsSet)
286+
{
287+
writer.WritePropertyName("deepList");
288+
JsonSerializer.Serialize(writer, testResult.DeepList, jsonSerializerOptions);
289+
}
290+
if (testResult.ListOption.IsSet)
291+
{
292+
writer.WritePropertyName("list");
293+
JsonSerializer.Serialize(writer, testResult.List, jsonSerializerOptions);
294+
}
233295
if (testResult.UuidOption.IsSet)
234296
writer.WriteString("uuid", testResult.Uuid);
235297
}

0 commit comments

Comments
 (0)