Skip to content

Commit

Permalink
[tmdgen] Refonte du OpenApiGenerator sur le modèle du DatabaseGenerator
Browse files Browse the repository at this point in the history
Création d'alias dans plus de cas
Fixes #304
  • Loading branch information
gideruette committed Nov 16, 2023
1 parent 3b4e9de commit 35e043e
Show file tree
Hide file tree
Showing 18 changed files with 708 additions and 291 deletions.
2 changes: 1 addition & 1 deletion TopModel.Generator.Jpa/SpringClientApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private void WriteUriBuilderMethod(JavaWriter fw, Endpoint endpoint)

if (endpoint.GetRouteParams().Any())
{
fullRoute = $@"""{fullRoute}"".formatted({string.Join(", ", endpoint.GetRouteParams().Select(p => p.GetParamName()))});";
fullRoute = $@"""{fullRoute}"".formatted({string.Join(", ", endpoint.GetRouteParams().Select(p => p.GetParamName()))})";
}
else
{
Expand Down
17 changes: 8 additions & 9 deletions TopModel.ModelGenerator/Database/DatabaseTmdGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ private static void AddUniqConstraints(TmdClass classe, IEnumerable<IGrouping<st
{
var uniqConstraints = group.GroupBy(g => g.Name);
classe.Unique
.AddRange(uniqConstraints.Select(u => u.Where(c => classe.Properties.Any(p => p.SqlName == c.ColumnName)).Select(c =>
.AddRange(uniqConstraints.Select(u => u.Where(c => classe.Properties.OfType<TmdRegularProperty>().Any(p => p.SqlName == c.ColumnName)).Select(c =>
{
var property = classe.Properties.First(p => p.SqlName == c.ColumnName);
var property = classe.Properties.OfType<TmdRegularProperty>().First(p => p.SqlName == c.ColumnName);
string name = string.Empty;
if (property is TmdAssociationProperty ap)
{
name = ap.ForeignClass.Name + ap.ForeignProperty!.Name + ap.Role;
name = ap.Association.Name + ap.ForeignProperty!.Name + ap.Role;
}
else
{
Expand Down Expand Up @@ -144,16 +144,16 @@ private TmdProperty ColumnToProperty(TmdClass classe, DbColumn column, string tr

var columnName = column.ColumnName;

TmdProperty tmdProperty;
TmdRegularProperty tmdProperty;
if (foreignConstraint != null && _classes.ContainsKey(foreignConstraint.ForeignTableName))
{
tmdProperty = new TmdAssociationProperty();
var foreignClass = _classes[foreignConstraint.ForeignTableName];
((TmdAssociationProperty)tmdProperty).ForeignClass = foreignClass;
((TmdAssociationProperty)tmdProperty).Association = foreignClass;
}
else
{
tmdProperty = new TmdProperty();
tmdProperty = new TmdRegularProperty();
if (!string.IsNullOrEmpty(trigram))
{
var regex = new Regex(Regex.Escape(trigram));
Expand Down Expand Up @@ -479,7 +479,7 @@ private async Task ReadValues()
var d = new Dictionary<string, string?>();
foreach (var kv in r)
{
d.Add(classe.Value.Properties.First(p => p.SqlName == kv.Key).Name, kv.Value?.ToString());
d.Add(classe.Value.Properties.OfType<TmdRegularProperty>().First(p => p.SqlName == kv.Key).Name, kv.Value?.ToString());
}

return d;
Expand Down Expand Up @@ -509,7 +509,7 @@ private void ResolveForeignProperties(IGrouping<string, DbColumn> group, IGroupi
foreach (var fk in classe.Properties.OfType<TmdAssociationProperty>())
{
var foreignColumnName = foreignKeys.First(p => p.ColumnName == fk.SqlName).ForeignColumnName;
fk.ForeignProperty = fk.ForeignClass!.Properties.First(p => p.SqlName == foreignColumnName);
fk.ForeignProperty = fk.Association!.Properties.OfType<TmdRegularProperty>().First(p => p.SqlName == foreignColumnName);
}
}
}
Expand All @@ -523,7 +523,6 @@ private IEnumerable<string> WriteFiles()
yield return fileName;

using var tmdFileWriter = new TmdWriter(rootPath, file!, _logger, ModelRoot);
tmdFileWriter.Write();
}
}
}
Loading

0 comments on commit 35e043e

Please sign in to comment.