Skip to content

Commit 21c9ffd

Browse files
committed
fix response data type
1 parent cd7fe34 commit 21c9ffd

File tree

27 files changed

+112
-68
lines changed

27 files changed

+112
-68
lines changed

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

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,13 @@ private String setUniquePropertyName(CodegenModel model, CodegenProperty propert
751751
return value;
752752
}
753753

754-
/**
755-
* Fixes nested maps so the generic type is defined
756-
* Convertes List<List>> to List<List<T>>
754+
/**
755+
* Ensures property name is unique and not a reserved word.
756+
* @param model
757+
* @param property
758+
* @param value
759+
* @param composedPropertyNames
760+
* @return
757761
*/
758762
private String patchPropertyName(CodegenModel model, CodegenProperty property, String value, Set<String> composedPropertyNames) {
759763
value = setUniquePropertyName(model, property, value);
@@ -792,6 +796,10 @@ private void patchPropertyVendorExtensions(CodegenProperty property) {
792796
protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) {
793797
}
794798

799+
/**
800+
* Fixes nested maps so the generic type is defined
801+
* Convertes List<List>> to List<List<T>>
802+
*/
795803
private void patchNestedMaps(CodegenProperty property) {
796804
// Process nested types before making any replacements to ensure we have the correct inner type
797805
if (property.items != null) {
@@ -823,6 +831,41 @@ private void patchNestedMaps(CodegenProperty property) {
823831
}
824832
}
825833

834+
/**
835+
* Fixes nested maps so the generic type is defined
836+
* Convertes List<List>> to List<List<T>>
837+
*/
838+
private void patchNestedMaps(CodegenResponse response) {
839+
// Process nested types before making any replacements to ensure we have the correct inner type
840+
if (response.items != null) {
841+
patchNestedMaps(response.items);
842+
}
843+
844+
String[] nestedTypes = {"List", "Collection", "ICollection", "Dictionary"};
845+
846+
if (response.dataType != null) {
847+
String originalType = response.dataType;
848+
849+
for (String nestedType : nestedTypes) {
850+
// fix incorrect data types for maps of maps
851+
if (response.items != null) {
852+
if (response.dataType.contains(", " + nestedType + ">")) {
853+
response.dataType = response.dataType.replace(", " + nestedType + ">", ", " + response.items.datatypeWithEnum + ">");
854+
}
855+
856+
if (response.dataType.contains("<" + nestedType + ">")) {
857+
response.dataType = response.dataType.replace("<" + nestedType + ">", "<" + response.items.datatypeWithEnum + ">");
858+
}
859+
}
860+
}
861+
862+
// Only update dataType if we actually made changes
863+
if (!originalType.equals(response.dataType)) {
864+
response.dataType = response.dataType;
865+
}
866+
}
867+
}
868+
826869
protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel model, CodegenProperty property) {
827870
if (enumRefs.containsKey(property.dataType)) {
828871
// Handle any enum properties referred to by $ref.
@@ -960,6 +1003,7 @@ private void postProcessOperations(OperationMap operations, List<ModelMap> allMo
9601003
}
9611004
if (operation.responses != null) {
9621005
for (CodegenResponse response : operation.responses) {
1006+
patchNestedMaps(response);
9631007

9641008
if (response.returnProperty != null) {
9651009
Boolean isValueType = isValueType(response.returnProperty);

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Api/DefaultApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task RolesReportGetAsyncTest()
9999
{
100100
var response = await _instance.RolesReportGetAsync();
101101
var model = response.Ok();
102-
Assert.IsType<List<List>>(model);
102+
Assert.IsType<List<List<RolesReportsHash>>>(model);
103103
}
104104

105105
/// <summary>

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public interface IRedirectOrDefaultApiResponse : Org.OpenAPITools.Client.IApiRes
219219
/// <summary>
220220
/// The <see cref="IRolesReportGetApiResponse"/>
221221
/// </summary>
222-
public interface IRolesReportGetApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<List<List>>
222+
public interface IRolesReportGetApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<List<List<RolesReportsHash>>>
223223
{
224224
/// <summary>
225225
/// Returns true if the response is 200 Ok
@@ -1495,11 +1495,11 @@ public RolesReportGetApiResponse(ILogger<RolesReportGetApiResponse> logger, Syst
14951495
/// Deserializes the response if the response is 200 Ok
14961496
/// </summary>
14971497
/// <returns></returns>
1498-
public List<List> Ok()
1498+
public List<List<RolesReportsHash>> Ok()
14991499
{
15001500
// This logic may be modified with the AsModel.mustache template
15011501
return IsOk
1502-
? System.Text.Json.JsonSerializer.Deserialize<List<List>>(RawContent, _jsonSerializerOptions)
1502+
? System.Text.Json.JsonSerializer.Deserialize<List<List<RolesReportsHash>>>(RawContent, _jsonSerializerOptions)
15031503
: default;
15041504
}
15051505

@@ -1508,7 +1508,7 @@ public List<List> Ok()
15081508
/// </summary>
15091509
/// <param name="result"></param>
15101510
/// <returns></returns>
1511-
public bool TryOk(out List<List> result)
1511+
public bool TryOk(out List<List<RolesReportsHash>> result)
15121512
{
15131513
result = null;
15141514

samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Api/DefaultApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task RolesReportGetAsyncTest()
9999
{
100100
var response = await _instance.RolesReportGetAsync();
101101
var model = response.Ok();
102-
Assert.IsType<List<List>>(model);
102+
Assert.IsType<List<List<RolesReportsHash>>>(model);
103103
}
104104

105105
/// <summary>

samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public interface IRedirectOrDefaultApiResponse : Org.OpenAPITools.Client.IApiRes
219219
/// <summary>
220220
/// The <see cref="IRolesReportGetApiResponse"/>
221221
/// </summary>
222-
public interface IRolesReportGetApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<List<List>>
222+
public interface IRolesReportGetApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<List<List<RolesReportsHash>>>
223223
{
224224
/// <summary>
225225
/// Returns true if the response is 200 Ok
@@ -1495,11 +1495,11 @@ public RolesReportGetApiResponse(ILogger<RolesReportGetApiResponse> logger, Syst
14951495
/// Deserializes the response if the response is 200 Ok
14961496
/// </summary>
14971497
/// <returns></returns>
1498-
public List<List> Ok()
1498+
public List<List<RolesReportsHash>> Ok()
14991499
{
15001500
// This logic may be modified with the AsModel.mustache template
15011501
return IsOk
1502-
? System.Text.Json.JsonSerializer.Deserialize<List<List>>(RawContent, _jsonSerializerOptions)
1502+
? System.Text.Json.JsonSerializer.Deserialize<List<List<RolesReportsHash>>>(RawContent, _jsonSerializerOptions)
15031503
: default;
15041504
}
15051505

@@ -1508,7 +1508,7 @@ public List<List> Ok()
15081508
/// </summary>
15091509
/// <param name="result"></param>
15101510
/// <returns></returns>
1511-
public bool TryOk(out List<List> result)
1511+
public bool TryOk(out List<List<RolesReportsHash>> result)
15121512
{
15131513
result = null;
15141514

samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools.Test/Api/DefaultApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task RolesReportGetAsyncTest()
9999
{
100100
var response = await _instance.RolesReportGetAsync();
101101
var model = response.Ok();
102-
Assert.IsType<List<List>>(model);
102+
Assert.IsType<List<List<RolesReportsHash>>>(model);
103103
}
104104

105105
/// <summary>

samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Api/DefaultApi.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public interface IRedirectOrDefaultApiResponse : Org.OpenAPITools.Client.IApiRes
219219
/// <summary>
220220
/// The <see cref="IRolesReportGetApiResponse"/>
221221
/// </summary>
222-
public interface IRolesReportGetApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<List<List>>
222+
public interface IRolesReportGetApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<List<List<RolesReportsHash>>>
223223
{
224224
/// <summary>
225225
/// Returns true if the response is 200 Ok
@@ -1495,11 +1495,11 @@ public RolesReportGetApiResponse(ILogger<RolesReportGetApiResponse> logger, Syst
14951495
/// Deserializes the response if the response is 200 Ok
14961496
/// </summary>
14971497
/// <returns></returns>
1498-
public List<List> Ok()
1498+
public List<List<RolesReportsHash>> Ok()
14991499
{
15001500
// This logic may be modified with the AsModel.mustache template
15011501
return IsOk
1502-
? System.Text.Json.JsonSerializer.Deserialize<List<List>>(RawContent, _jsonSerializerOptions)
1502+
? System.Text.Json.JsonSerializer.Deserialize<List<List<RolesReportsHash>>>(RawContent, _jsonSerializerOptions)
15031503
: default;
15041504
}
15051505

@@ -1508,7 +1508,7 @@ public List<List> Ok()
15081508
/// </summary>
15091509
/// <param name="result"></param>
15101510
/// <returns></returns>
1511-
public bool TryOk(out List<List> result)
1511+
public bool TryOk(out List<List<RolesReportsHash>> result)
15121512
{
15131513
result = null;
15141514

samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools.Test/Api/DefaultApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task RolesReportGetAsyncTest()
9999
{
100100
var response = await _instance.RolesReportGetAsync();
101101
var model = response.Ok();
102-
Assert.IsType<List<List>>(model);
102+
Assert.IsType<List<List<RolesReportsHash>>>(model);
103103
}
104104

105105
/// <summary>

samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Api/DefaultApi.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public interface IRedirectOrDefaultApiResponse : Org.OpenAPITools.Client.IApiRes
219219
/// <summary>
220220
/// The <see cref="IRolesReportGetApiResponse"/>
221221
/// </summary>
222-
public interface IRolesReportGetApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<List<List>>
222+
public interface IRolesReportGetApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<List<List<RolesReportsHash>>>
223223
{
224224
/// <summary>
225225
/// Returns true if the response is 200 Ok
@@ -1495,11 +1495,11 @@ public RolesReportGetApiResponse(ILogger<RolesReportGetApiResponse> logger, Syst
14951495
/// Deserializes the response if the response is 200 Ok
14961496
/// </summary>
14971497
/// <returns></returns>
1498-
public List<List> Ok()
1498+
public List<List<RolesReportsHash>> Ok()
14991499
{
15001500
// This logic may be modified with the AsModel.mustache template
15011501
return IsOk
1502-
? System.Text.Json.JsonSerializer.Deserialize<List<List>>(RawContent, _jsonSerializerOptions)
1502+
? System.Text.Json.JsonSerializer.Deserialize<List<List<RolesReportsHash>>>(RawContent, _jsonSerializerOptions)
15031503
: default;
15041504
}
15051505

@@ -1508,7 +1508,7 @@ public List<List> Ok()
15081508
/// </summary>
15091509
/// <param name="result"></param>
15101510
/// <returns></returns>
1511-
public bool TryOk(out List<List> result)
1511+
public bool TryOk(out List<List<RolesReportsHash>> result)
15121512
{
15131513
result = null;
15141514

samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools.Test/Api/DefaultApiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task RolesReportGetAsyncTest()
9999
{
100100
var response = await _instance.RolesReportGetAsync();
101101
var model = response.Ok();
102-
Assert.IsType<List<List>>(model);
102+
Assert.IsType<List<List<RolesReportsHash>>>(model);
103103
}
104104

105105
/// <summary>

0 commit comments

Comments
 (0)