2021-10-14 06:55:19 -07:00
|
|
|
using System.IO;
|
2021-12-22 17:16:44 -08:00
|
|
|
using Microsoft.CodeAnalysis;
|
2021-10-14 06:55:19 -07:00
|
|
|
using NSwag;
|
|
|
|
|
using Nustache.Core;
|
|
|
|
|
|
2021-12-22 17:16:44 -08:00
|
|
|
namespace LibKubernetesGenerator
|
2021-10-14 06:55:19 -07:00
|
|
|
{
|
2021-10-24 08:14:22 -07:00
|
|
|
internal class ModelGenerator
|
2021-10-14 06:55:19 -07:00
|
|
|
{
|
|
|
|
|
private readonly ClassNameHelper classNameHelper;
|
|
|
|
|
|
|
|
|
|
public ModelGenerator(ClassNameHelper classNameHelper)
|
|
|
|
|
{
|
|
|
|
|
this.classNameHelper = classNameHelper;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 17:16:44 -08:00
|
|
|
public void Generate(OpenApiDocument swagger, GeneratorExecutionContext context)
|
2021-10-14 06:55:19 -07:00
|
|
|
{
|
2021-12-22 17:16:44 -08:00
|
|
|
foreach (var kv in swagger.Definitions)
|
2021-10-14 06:55:19 -07:00
|
|
|
{
|
2021-12-22 17:16:44 -08:00
|
|
|
var def = kv.Value;
|
2021-10-14 06:55:19 -07:00
|
|
|
var clz = classNameHelper.GetClassNameForSchemaDefinition(def);
|
2021-12-22 17:16:44 -08:00
|
|
|
context.RenderToContext(
|
|
|
|
|
"Model.cs.template",
|
2021-10-14 06:55:19 -07:00
|
|
|
new { clz, def, properties = def.Properties.Values },
|
2021-12-22 17:16:44 -08:00
|
|
|
$"Models_{clz}.g.cs");
|
2021-10-14 06:55:19 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|