migrate to record (#1665)
* migrate to record * chore: update project files and clean up unused references * refactor: convert classes to records and simplify constructors for IntOrString, ResourceQuantity, and V1Patch * fix: define IsExternalInit to resolve CS0518 error in IntOrString * refactor: change IntOrString and ResourceQuantity from records to structs, update implicit conversions, and simplify null checks * refactor: add JsonPropertyName attribute to Value property in IntOrString struct * refactor: simplify V1Patch constructor and improve argument validation * refactor: remove unnecessary CultureInfo parameter in ToInt method * Update src/KubernetesClient/Models/ResourceQuantity.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/KubernetesClient/Models/IntOrString.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Revert "Update src/KubernetesClient/Models/ResourceQuantity.cs" This reverts commit 62b20a691554659e28d419067220dc1a0620133b. * refactor: remove commented-out formatting check and simplify build command * refactor: remove IValidate.cs from project references in Aot and Classic --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using NSwag;
|
||||
|
||||
@@ -18,15 +19,49 @@ namespace LibKubernetesGenerator
|
||||
{
|
||||
var sc = scriptObjectFactory.CreateScriptObject();
|
||||
|
||||
var genSkippedTypes = new HashSet<string>
|
||||
{
|
||||
"IntOrString",
|
||||
"ResourceQuantity",
|
||||
"V1Patch",
|
||||
};
|
||||
|
||||
var extSkippedTypes = new HashSet<string>
|
||||
{
|
||||
"V1WatchEvent",
|
||||
};
|
||||
|
||||
var typeOverrides = new Dictionary<string, string>
|
||||
{
|
||||
// not used at the moment
|
||||
};
|
||||
|
||||
foreach (var kv in swagger.Definitions)
|
||||
{
|
||||
var def = kv.Value;
|
||||
var clz = classNameHelper.GetClassNameForSchemaDefinition(def);
|
||||
|
||||
if (genSkippedTypes.Contains(clz))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var hasExt = def.ExtensionData != null
|
||||
&& def.ExtensionData.ContainsKey("x-kubernetes-group-version-kind")
|
||||
&& !extSkippedTypes.Contains(clz);
|
||||
|
||||
|
||||
var typ = "record";
|
||||
if (typeOverrides.TryGetValue(clz, out var to))
|
||||
{
|
||||
typ = to;
|
||||
}
|
||||
|
||||
sc.SetValue("clz", clz, true);
|
||||
sc.SetValue("def", def, true);
|
||||
sc.SetValue("properties", def.Properties.Values, true);
|
||||
sc.SetValue("typ", typ, true);
|
||||
sc.SetValue("hasExt", hasExt, true);
|
||||
|
||||
context.RenderToContext("Model.cs.template", sc, $"Models_{clz}.g.cs");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user