From 785bb3a003dee49db3e610ad4ab72db0b0b4ca0d Mon Sep 17 00:00:00 2001 From: Damien Date: Tue, 14 May 2024 15:32:12 +0200 Subject: [PATCH] [C#ApiServer] Fix [FromQuery] manquant pour les arrays et [FromForm] en trop pour IFormFile --- TopModel.Generator.Csharp/CSharpApiServerGenerator.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/TopModel.Generator.Csharp/CSharpApiServerGenerator.cs b/TopModel.Generator.Csharp/CSharpApiServerGenerator.cs index ced3dc9a..cb1dbc2e 100644 --- a/TopModel.Generator.Csharp/CSharpApiServerGenerator.cs +++ b/TopModel.Generator.Csharp/CSharpApiServerGenerator.cs @@ -130,7 +130,9 @@ private string GetParam(IProperty param) { var sb = new StringBuilder(); - if (param.Endpoint.IsMultipart && !param.IsQueryParam() && !param.IsRouteParam()) + var type = Config.GetType(param, nonNullable: param.IsJsonBodyParam() || param.IsRouteParam() || param.IsQueryParam() && !param.Endpoint.IsMultipart && Config.GetValue(param, Classes) != "null"); + + if (param.Endpoint.IsMultipart && !param.IsQueryParam() && !param.IsRouteParam() && type != "IFormFile") { sb.Append("[FromForm] "); } @@ -138,8 +140,12 @@ private string GetParam(IProperty param) { sb.Append("[FromBody] "); } + else if (type.EndsWith("[]")) + { + sb.Append("[FromQuery] "); + } - sb.Append($@"{Config.GetType(param, nonNullable: param.IsJsonBodyParam() || param.IsRouteParam() || param.IsQueryParam() && !param.Endpoint.IsMultipart && Config.GetValue(param, Classes) != "null")} {param.GetParamName().Verbatim()}"); + sb.Append($@"{type} {param.GetParamName().Verbatim()}"); if (param.IsQueryParam() && !param.Endpoint.IsMultipart) {