* feat: enhance Kubernetes client with watch functionality * refactor: simplify watch event handling in Kubernetes client example * refactor: update Kubernetes watch functionality to use new event handling methods and add async enumerable support * fix * fix * fix: correct usage of Pod list items in client example and update Obsolete attribute formatting * fix: update client example to use correct Pod list method and improve Obsolete attribute formatting * refactor: enhance type resolution for list items in TypeHelper by adding TryGetItemTypeFromSchema method * feat: mark Watch methods as obsolete to prepare for future deprecation * fix * refactor: update WatcherExt class to internal and remove obsolete attributes; improve example method signature in Program.cs * refactor: change WatcherExt class from internal to public and mark methods as obsolete for future deprecation
80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
using NJsonSchema;
|
|
using NSwag;
|
|
using Scriban.Runtime;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
|
|
namespace LibKubernetesGenerator
|
|
{
|
|
internal class ParamHelper : IScriptObjectHelper
|
|
{
|
|
private readonly GeneralNameHelper generalNameHelper;
|
|
private readonly TypeHelper typeHelper;
|
|
|
|
public ParamHelper(GeneralNameHelper generalNameHelper, TypeHelper typeHelper)
|
|
{
|
|
this.generalNameHelper = generalNameHelper;
|
|
this.typeHelper = typeHelper;
|
|
}
|
|
|
|
public void RegisterHelper(ScriptObject scriptObject)
|
|
{
|
|
scriptObject.Import(nameof(GetModelCtorParam), new Func<JsonSchema, string>(GetModelCtorParam));
|
|
scriptObject.Import(nameof(IfParamContains), IfParamContains);
|
|
scriptObject.Import(nameof(FilterParameters), FilterParameters);
|
|
scriptObject.Import(nameof(GetParameterValueForWatch), new Func<OpenApiParameter, bool, string, string>(GetParameterValueForWatch));
|
|
}
|
|
|
|
public static bool IfParamContains(OpenApiOperation operation, string name)
|
|
{
|
|
var found = false;
|
|
|
|
foreach (var param in operation.Parameters)
|
|
{
|
|
if (param.Name == name)
|
|
{
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return found;
|
|
}
|
|
|
|
public static IEnumerable<OpenApiParameter> FilterParameters(OpenApiOperation operation, string excludeParam)
|
|
{
|
|
return operation.Parameters.Where(p => p.Name != excludeParam);
|
|
}
|
|
|
|
public string GetParameterValueForWatch(OpenApiParameter parameter, bool watch, string init = "false")
|
|
{
|
|
if (parameter.Name == "watch")
|
|
{
|
|
return watch ? "true" : "false";
|
|
}
|
|
else
|
|
{
|
|
return generalNameHelper.GetDotNetNameOpenApiParameter(parameter, init);
|
|
}
|
|
}
|
|
|
|
public string GetModelCtorParam(JsonSchema schema)
|
|
{
|
|
return string.Join(", ", schema.Properties.Values
|
|
.OrderBy(p => !p.IsRequired)
|
|
.Select(p =>
|
|
{
|
|
var sp =
|
|
$"{typeHelper.GetDotNetType(p)} {generalNameHelper.GetDotNetName(p.Name, "fieldctor")}";
|
|
|
|
if (!p.IsRequired)
|
|
{
|
|
sp = $"{sp} = null";
|
|
}
|
|
|
|
return sp;
|
|
}));
|
|
}
|
|
}
|
|
} |