Skip to content

Commit

Permalink
[Core] Modification de la détection des champs de type fichier
Browse files Browse the repository at this point in the history
  • Loading branch information
gideruette committed Oct 31, 2023
1 parent 3ea0ac9 commit 2be183c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# TopModel.Generator (`modgen`)

## 1.39.0

- [`#322`](https://github.com/klee-contrib/topmodel/pull/322) - [Core] Modification de la détection des requêtes contenant un formulaire. Il faut désormais préciser sur les domaines de fichiers le mediaType : `multipart/form-data`.

## 1.38.4

- [`edfdc21`](https://github.com/klee-contrib/topmodel/commit/edfdc211d0f714a866a2a2f172552ef73ebfab9b) - [JPA] Correction visibilité flows
Expand Down
2 changes: 1 addition & 1 deletion TopModel.Generator.Csharp/CSharpApiServerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private string GetParam(IProperty param)
{
var sb = new StringBuilder();

var hasForm = param.Endpoint.Params.Any(p => Config.GetType(p).Contains("IFormFile"));
var hasForm = param.Endpoint.Params.Any(p => p.Domain?.MediaType == "multipart/form-data");

if (param.IsBodyParam())
{
Expand Down
4 changes: 2 additions & 2 deletions TopModel.Generator.Javascript/AngularApiClientGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected override void HandleFile(string filePath, string fileName, string tag,
WriteEndpoint(endpoint, fw);
}

var hasForm = endpoints.Any(endpoint => endpoint.Params.Any(p => p is IFieldProperty fp && Config.GetType(fp).Contains("File")));
var hasForm = endpoints.Any(endpoint => endpoint.Params.Any(p => p.Domain?.MediaType == "multipart/form-data"));
if (hasForm)
{
fw.WriteLine(@"
Expand Down Expand Up @@ -106,7 +106,7 @@ private void WriteEndpoint(Endpoint endpoint, FileWriter fw)
fw.WriteLine(1, " */");
fw.Write(1, $"{endpoint.NameCamel}(");

var hasForm = endpoint.Params.Any(p => p is IFieldProperty fp && Config.GetType(fp).Contains("File"));
var hasForm = endpoint.Params.Any(p => p.Domain?.MediaType == "multipart/form-data");
var hasProperty = false;
foreach (var param in endpoint.Params)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override void HandleFile(string filePath, string fileName, string tag,
fw.WriteLine(" */");
fw.Write($"export function {endpoint.NameCamel}(");

var hasForm = endpoint.Params.Any(p => p is IFieldProperty fp && Config.GetType(fp).Contains("File"));
var hasForm = endpoint.Params.Any(p => p.Domain?.MediaType == "multipart/form-data");

foreach (var param in endpoint.Params)
{
Expand Down
29 changes: 16 additions & 13 deletions TopModel.Generator.Jpa/SpringServerApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,33 @@ private void WriteEndpoint(JavaWriter fw, Endpoint endpoint, string tag)
}

var bodyParam = endpoint.GetBodyParam();
var formParam = endpoint.Params.FirstOrDefault(p => p.Domain?.MediaType == "multipart/form-data", null);
if (bodyParam != null)
var hasForm = endpoint.Params.Any(p => p.Domain?.MediaType == "multipart/form-data");

if (hasForm)
{
var ann = string.Empty;
if (formParam != null)
foreach (var param in endpoint.Params.Where(param => param is CompositionProperty || param is IFieldProperty { Domain.BodyParam: true }))
{
if (formParam != bodyParam)
var ann = string.Empty;
if (param.Domain.MediaType != "multipart/form-data")
{
ann += @$"@ModelAttribute ";
fw.AddImport("org.springframework.web.bind.annotation.ModelAttribute");
}
else
{
ann += @$"@RequestPart(value = ""{bodyParam.GetParamName()}"", required = {(bodyParam is not IFieldProperty fp || fp.Required).ToString().ToFirstLower()}) ";
ann += @$"@RequestPart(value = ""{param.GetParamName()}"", required = {(param is not IFieldProperty fp || fp.Required).ToString().ToFirstLower()}) ";
fw.AddImport("org.springframework.web.bind.annotation.RequestPart");
}
}
else
{
ann += @$"@RequestBody @Valid ";
fw.AddImport("org.springframework.web.bind.annotation.RequestBody");
fw.AddImport(Config.PersistenceMode.ToString().ToLower() + ".validation.Valid");
}

methodParams.Add($"{ann}{Config.GetType(param)} {param.GetParamName()}");
}
}
else if (bodyParam != null)
{
var ann = string.Empty;
ann += @$"@RequestBody @Valid ";
fw.AddImport("org.springframework.web.bind.annotation.RequestBody");
fw.AddImport(Config.PersistenceMode.ToString().ToLower() + ".validation.Valid");
methodParams.Add($"{ann}{Config.GetType(bodyParam)} {bodyParam.GetParamName()}");
}

Expand Down

0 comments on commit 2be183c

Please sign in to comment.