Skip to content

Commit

Permalink
[tmdgen - openapi] Ajout classPrefix dans la config de la source (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Sep 20, 2023
1 parent ded4c7d commit 2344936
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions TopModel.Core/schema.tmdgen.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@
"preservePropertyCasing": {
"type": "boolean",
"description": "Garde les noms des propriétés générées tels quels pour la génération via `modgen`, au lieu de les convertir dans le format du langage cible. Par défaut : `true`."
},
"classPrefix": {
"type": "string",
"description": "Préfixe à ajouter à toutes les classes générées pour cette source."
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions TopModel.ModelGenerator/OpenApi/OpenApiTmdGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override async IAsyncEnumerable<string> GenerateCore()

var className = schema.Value.Type == "array" ? schema.Key.Unplurialize() : schema.Key;

fw.WriteLine($" name: {className}");
fw.WriteLine($" name: {_config.ClassPrefix}{className}");

if (_config.PreservePropertyCasing)
{
Expand Down Expand Up @@ -110,7 +110,7 @@ protected override async IAsyncEnumerable<string> GenerateCore()
else
{
fw.WriteLine(" - alias:");
fw.WriteLine($@" class: {schema.Key.ToPascalCase()}{property.Key.ToPascalCase()}");
fw.WriteLine($@" class: {_config.ClassPrefix}{schema.Key.ToPascalCase()}{property.Key.ToPascalCase()}");
fw.WriteLine($" name: {property.Key.ToPascalCase()}");
}

Expand All @@ -124,7 +124,7 @@ protected override async IAsyncEnumerable<string> GenerateCore()
{
fw.WriteLine("---");
fw.WriteLine("class:");
fw.WriteLine($" name: {schema.Key.ToPascalCase()}{property.Key.ToPascalCase()}");
fw.WriteLine($" name: {_config.ClassPrefix}{schema.Key.ToPascalCase()}{property.Key.ToPascalCase()}");

if (_config.PreservePropertyCasing)
{
Expand Down Expand Up @@ -414,7 +414,7 @@ private void WriteProperty(OpenApiConfig config, FileWriter sw, KeyValuePair<str
if (kind != null && name != null)
{
var domainKind = TmdGenUtils.GetDomainString(config.Domains, type: kind);
sw.WriteLine($" {(noList ? string.Empty : "- ")}composition: {name}");
sw.WriteLine($" {(noList ? string.Empty : "- ")}composition: {_config.ClassPrefix}{name}");
sw.WriteLine($" {(noList ? string.Empty : " ")}name: {property.Key}");
if (kind != "object")
{
Expand Down
2 changes: 2 additions & 0 deletions TopModel.ModelGenerator/OpenApi/config/OpenApiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public class OpenApiConfig
public string ModelFileName { get; set; } = "Model";

public bool PreservePropertyCasing { get; set; } = true;

public string? ClassPrefix { get; set; }
}

0 comments on commit 2344936

Please sign in to comment.