Skip to content

Commit

Permalink
customProperties sur classes, endpoints et propriétés
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Sep 16, 2024
1 parent f0cfe6d commit 6c735c8
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 7 deletions.
3 changes: 3 additions & 0 deletions TopModel.Core/Loaders/ClassLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public Class Load(Parser parser)
});
});
break;
case "customProperties":
parser.ConsumeMapping(prop => classe.CustomProperties.Add(prop.Value, parser.Consume<Scalar>().Value));
break;
case "mappers":
parser.ConsumeMapping(prop =>
{
Expand Down
3 changes: 3 additions & 0 deletions TopModel.Core/Loaders/EndpointLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public Endpoint Load(Parser parser)
}
});
break;
case "customProperties":
parser.ConsumeMapping(prop => endpoint.CustomProperties.Add(prop.Value, parser.Consume<Scalar>().Value));
break;
default:
throw new ModelException(endpoint, $"Propriété ${prop} inconnue pour un endpoint");
}
Expand Down
14 changes: 14 additions & 0 deletions TopModel.Core/Loaders/PropertyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public IProperty Load(Parser parser)
case "trigram":
rp.Trigram = new LocatedString(value);
break;
case "customProperties":
parser.ConsumeMapping(prop => rp.CustomProperties.Add(prop.Value, parser.Consume<Scalar>().Value));
break;
default:
throw new ModelException($"Propriété ${prop} inconnue pour une propriété");
}
Expand Down Expand Up @@ -126,6 +129,9 @@ public IProperty Load(Parser parser)
case "trigram":
ap.Trigram = new LocatedString(value);
break;
case "customProperties":
parser.ConsumeMapping(prop => ap.CustomProperties.Add(prop.Value, parser.Consume<Scalar>().Value));
break;
default:
throw new ModelException($"Propriété ${prop} inconnue pour une propriété");
}
Expand Down Expand Up @@ -177,6 +183,9 @@ public IProperty Load(Parser parser)
case "trigram":
cp.Trigram = new LocatedString(value);
break;
case "customProperties":
parser.ConsumeMapping(prop => cp.CustomProperties.Add(prop.Value, parser.Consume<Scalar>().Value));
break;
default:
throw new ModelException($"Propriété ${prop} inconnue pour une propriété");
}
Expand Down Expand Up @@ -281,6 +290,11 @@ public IProperty Load(Parser parser)
case "defaultValue":
alp.DefaultValue = value!.Value;
break;
case "customProperties":
var customProperties = new Dictionary<string, string>();
parser.ConsumeMapping(prop => customProperties.Add(prop.Value, parser.Consume<Scalar>().Value));
alp.CustomProperties = customProperties;
break;
default:
throw new ModelException($"Propriété ${prop} inconnue pour une propriété");
}
Expand Down
22 changes: 20 additions & 2 deletions TopModel.Core/Model/AliasProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace TopModel.Core;
public class AliasProperty : IProperty
{
private string? _comment;
private Dictionary<string, string> _customProperties = [];
private string? _defaultValue;
private Domain? _domain;
private string[]? _domainParameters;
Expand Down Expand Up @@ -133,6 +134,21 @@ public string? DefaultValue

public string? As { get; set; }

public Dictionary<string, string> CustomProperties
{
get
{
var customProperties = new Dictionary<string, string>(OriginalProperty!.CustomProperties);
foreach (var cp in _customProperties)
{
customProperties[cp.Key] = cp.Value;
}

return customProperties;
}
set => _customProperties = value;
}

public IProperty? OriginalProperty => _property;

public IProperty? PersistentProperty => (Class?.IsPersistent ?? false)
Expand Down Expand Up @@ -186,7 +202,8 @@ public IProperty CloneWithClassOrEndpoint(Class? classe = null, Endpoint? endpoi
Name = _name!,
Trigram = Trigram,
UseLegacyRoleName = UseLegacyRoleName,
DomainParameters = _domainParameters!
DomainParameters = _domainParameters!,
CustomProperties = _customProperties
};

if (_domain != null)
Expand Down Expand Up @@ -235,7 +252,8 @@ internal AliasProperty Clone(IProperty prop, Reference? includeReference)
As = As,
OriginalAliasProperty = this,
UseLegacyRoleName = UseLegacyRoleName,
DomainParameters = _domainParameters!
DomainParameters = _domainParameters!,
CustomProperties = _customProperties
};

if (_domain != null)
Expand Down
2 changes: 2 additions & 0 deletions TopModel.Core/Model/AssociationProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public IProperty Property

public string? DefaultValue { get; set; }

public Dictionary<string, string> CustomProperties { get; } = [];

public string Name
{
get
Expand Down
2 changes: 2 additions & 0 deletions TopModel.Core/Model/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class Class : IPropertyContainer

public List<ClassMappings> ToMappers { get; } = [];

public Dictionary<string, string> CustomProperties { get; } = [];

public string PluralName
{
get => _pluralName ?? (Name.EndsWith("s") ? Name : $"{Name}s");
Expand Down
2 changes: 2 additions & 0 deletions TopModel.Core/Model/CompositionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class CompositionProperty : IProperty

public LocatedString? Trigram { get; set; }

public Dictionary<string, string> CustomProperties { get; } = [];

public IProperty? CompositionPrimaryKey
{
get
Expand Down
12 changes: 7 additions & 5 deletions TopModel.Core/Model/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,26 @@ public string FullRoute

public IProperty? Returns { get; set; }

public IList<IProperty> Params { get; set; } = new List<IProperty>();
public IList<IProperty> Params { get; set; } = [];

public bool IsMultipart => Params.Any(p => p.Domain?.IsMultipart ?? false || p is CompositionProperty cp && cp.IsMultipart);

public IList<IProperty> Properties => Params.Concat(new[] { Returns! }).Where(p => p != null).ToList();
public IList<IProperty> Properties => Params.Concat([Returns!]).Where(p => p != null).ToList();

public bool PreservePropertyCasing { get; set; }

public List<(Decorator Decorator, string[] Parameters)> Decorators { get; } = new();
public Dictionary<string, string> CustomProperties { get; } = [];

public List<(Decorator Decorator, string[] Parameters)> Decorators { get; } = [];

public IEnumerable<ClassDependency> ClassDependencies => Properties.GetClassDependencies();

public List<DecoratorReference> DecoratorReferences { get; } = new();
public List<DecoratorReference> DecoratorReferences { get; } = [];

#nullable disable
internal Reference Location { get; set; }

internal List<string> OwnTags { get; set; } = new();
internal List<string> OwnTags { get; set; } = [];

#nullable enable

Expand Down
2 changes: 2 additions & 0 deletions TopModel.Core/Model/IProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public interface IProperty

LocatedString? Trigram { get; set; }

Dictionary<string, string> CustomProperties { get; }

Class Class { get; set; }

Endpoint Endpoint { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions TopModel.Core/Model/RegularProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class RegularProperty : IProperty

public string Comment { get; set; }

public Dictionary<string, string> CustomProperties { get; } = [];

public Class Class { get; set; }

public Endpoint Endpoint { get; set; }
Expand Down
42 changes: 42 additions & 0 deletions TopModel.Core/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@
},
"defaultValue": {
"description": "Valeur par défaut de la propriété, dans les classes et les endpoints."
},
"customProperties": {
"type": "object",
"description": "Propriétés de propriété personnalisées, pour utilisation dans un générateur personnalisé.",
"additionalProperties": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -154,6 +161,13 @@
"property": {
"type": "string",
"description": "Propriété de la classe cible à utiliser pour la clé étrangère (au lieu de la clé primaire)."
},
"customProperties": {
"type": "object",
"description": "Propriétés de propriété personnalisées, pour utilisation dans un générateur personnalisé.",
"additionalProperties": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -314,6 +328,13 @@
},
"defaultValue": {
"description": "Surcharge la valeur par défaut de la propriété."
},
"customProperties": {
"type": "object",
"description": "Propriétés de propriété personnalisées, pour utilisation dans un générateur personnalisé. Elles s'ajouteront à celles de la propriété originale (avec remplacement si conflit).",
"additionalProperties": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -357,6 +378,13 @@
"trigram": {
"type": "string",
"description": "Surcharge locale du trigram"
},
"customProperties": {
"type": "object",
"description": "Propriétés de propriété personnalisées, pour utilisation dans un générateur personnalisé.",
"additionalProperties": {
"type": "string"
}
}
}
}
Expand Down Expand Up @@ -817,6 +845,13 @@
"type": "object",
"description": "Liste des valeurs de la table à insérer à la création de la base de données. Il doit d'agir d'un objet ayant pour clés un nom de ligne (qui sera utilisé pour identifier la clé en C#), et pour valeurs un objet de type JSON qui renseigne les valeurs des différentes propriétés."
},
"customProperties": {
"type": "object",
"description": "Propriétés de classe personnalisées, pour utilisation dans un générateur personnalisé.",
"additionalProperties": {
"type": "string"
}
},
"mappers": {
"type": "object",
"description": "Définitions de mappers vers et depuis cette classe.",
Expand Down Expand Up @@ -1016,6 +1051,13 @@
"$ref": "#/definitions/property"
}
},
"customProperties": {
"type": "object",
"description": "Propriétés d'endpoint personnalisées, pour utilisation dans un générateur personnalisé.",
"additionalProperties": {
"type": "string"
}
},
"decorators": {
"type": "array",
"description": "Décorateurs du endpoint",
Expand Down

0 comments on commit 6c735c8

Please sign in to comment.