Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion examples/csrApproval/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ string GenerateCertificate(string name)

var replace = new List<V1CertificateSigningRequestCondition>
{
new ("True", "Approved", DateTime.UtcNow, DateTime.UtcNow, "This certificate was approved by k8s client", "Approve"),
new V1CertificateSigningRequestCondition
{
Type = "Approved",
Status = "True",
Reason = "Approve",
Message = "This certificate was approved by k8s client",
LastUpdateTime = DateTime.UtcNow,
LastTransitionTime = DateTime.UtcNow,
},
};
readCert.Status.Conditions = replace;

Expand Down
4 changes: 2 additions & 2 deletions examples/customResource/cResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public override string ToString()
}
}

public class CResourceSpec
public record CResourceSpec
{
[JsonPropertyName("cityName")]
public string CityName { get; set; }
}

public class CResourceStatus : V1Status
public record CResourceStatus : V1Status
{
[JsonPropertyName("temperature")]
public string Temperature { get; set; }
Expand Down
4 changes: 1 addition & 3 deletions src/KubernetesClient.Aot/KubernetesClient.Aot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
<Compile Include="..\KubernetesClient\IMetadata.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrStringJsonConverter.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrStringYamlConverter.cs" />
<Compile Include="..\KubernetesClient\Models\IntstrIntOrString.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrString.cs" />
<Compile Include="..\KubernetesClient\ISpec.cs" />
<Compile Include="..\KubernetesClient\IStatus.cs" />
<Compile Include="..\KubernetesClient\IValidate.cs" />
<Compile Include="..\KubernetesClient\Models\KubernetesEntityAttribute.cs" />
<Compile Include="..\KubernetesClient\Models\KubernetesList.cs" />
<Compile Include="..\KubernetesClient\KubernetesObject.cs" />
<Compile Include="..\KubernetesClient\Models\ModelExtensions.cs" />
<Compile Include="..\KubernetesClient\Models\ModelVersionConverter.cs" />
<Compile Include="..\KubernetesClient\Models\NodeMetrics.cs" />
<Compile Include="..\KubernetesClient\Models\NodeMetricsList.cs" />
<Compile Include="..\KubernetesClient\Models\PodMetrics.cs" />
Expand Down
4 changes: 1 addition & 3 deletions src/KubernetesClient.Classic/KubernetesClient.Classic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
<Compile Include="..\KubernetesClient\IMetadata.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrStringJsonConverter.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrStringYamlConverter.cs" />
<Compile Include="..\KubernetesClient\Models\IntstrIntOrString.cs" />
<Compile Include="..\KubernetesClient\Models\IntOrString.cs" />
<Compile Include="..\KubernetesClient\ISpec.cs" />
<Compile Include="..\KubernetesClient\IStatus.cs" />
<Compile Include="..\KubernetesClient\IValidate.cs" />
<Compile Include="..\KubernetesClient\Models\KubernetesEntityAttribute.cs" />
<Compile Include="..\KubernetesClient\KubernetesJson.cs" />
<Compile Include="..\KubernetesClient\Models\KubernetesList.cs" />
<Compile Include="..\KubernetesClient\KubernetesObject.cs" />
<Compile Include="..\KubernetesClient\KubernetesYaml.cs" />
<Compile Include="..\KubernetesClient\Models\ModelExtensions.cs" />
<Compile Include="..\KubernetesClient\Models\ModelVersionConverter.cs" />
<Compile Include="..\KubernetesClient\Models\NodeMetrics.cs" />
<Compile Include="..\KubernetesClient\Models\NodeMetricsList.cs" />
<Compile Include="..\KubernetesClient\Models\PodMetrics.cs" />
Expand Down
13 changes: 0 additions & 13 deletions src/KubernetesClient/IValidate.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
namespace k8s.Models
{
[JsonConverter(typeof(IntOrStringJsonConverter))]
public partial class IntstrIntOrString
public partial class IntOrString
{
public static implicit operator IntstrIntOrString(int v)
public static implicit operator IntOrString(int v)
{
return new IntstrIntOrString(Convert.ToString(v));
return new IntOrString { Value = Convert.ToString(v) };
}

public static implicit operator IntstrIntOrString(long v)
public static implicit operator IntOrString(long v)
{
return new IntstrIntOrString(Convert.ToString(v));
return new IntOrString { Value = Convert.ToString(v) };
}

public static implicit operator string(IntstrIntOrString v)
public static implicit operator string(IntOrString v)
{
return v?.Value;
}

public static implicit operator IntstrIntOrString(string v)
public static implicit operator IntOrString(string v)
{
return new IntstrIntOrString(v);
return new IntOrString { Value = v };
}

protected bool Equals(IntstrIntOrString other)
protected bool Equals(IntOrString other)
{
return string.Equals(Value, other?.Value);
}
Expand All @@ -45,7 +45,7 @@ public override bool Equals(object obj)
return false;
}

return Equals((IntstrIntOrString)obj);
return Equals((IntOrString)obj);
}

public override int GetHashCode()
Expand Down
6 changes: 3 additions & 3 deletions src/KubernetesClient/Models/IntOrStringJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace k8s.Models
{
internal sealed class IntOrStringJsonConverter : JsonConverter<IntstrIntOrString>
internal sealed class IntOrStringJsonConverter : JsonConverter<IntOrString>
{
public override IntstrIntOrString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override IntOrString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
switch (reader.TokenType)
{
Expand All @@ -17,7 +17,7 @@ public override IntstrIntOrString Read(ref Utf8JsonReader reader, Type typeToCon
throw new NotSupportedException();
}

public override void Write(Utf8JsonWriter writer, IntstrIntOrString value, JsonSerializerOptions options)
public override void Write(Utf8JsonWriter writer, IntOrString value, JsonSerializerOptions options)
{
if (writer == null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/KubernetesClient/Models/IntOrStringYamlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class IntOrStringYamlConverter : IYamlTypeConverter
{
public bool Accepts(Type type)
{
return type == typeof(IntstrIntOrString);
return type == typeof(IntOrString);
}

public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
Expand All @@ -21,7 +21,7 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
return null;
}

return new IntstrIntOrString(scalar?.Value);
return new IntOrString { Value = scalar?.Value };
}
finally
{
Expand All @@ -34,7 +34,7 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria

public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
{
var obj = (IntstrIntOrString)value;
var obj = (IntOrString)value;
emitter?.Emit(new YamlDotNet.Core.Events.Scalar(obj?.Value));
}
}
Expand Down
19 changes: 0 additions & 19 deletions src/KubernetesClient/Models/KubernetesList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,5 @@ public KubernetesList(IList<T> items, string apiVersion = default, string kind =
/// </summary>
[JsonPropertyName("metadata")]
public V1ListMeta Metadata { get; set; }

/// <summary>
/// Validate the object.
/// </summary>
public void Validate()
{
if (Items == null)
{
throw new ArgumentNullException("Items");
}

if (Items != null)
{
foreach (var element in Items.OfType<IValidate>())
{
element.Validate();
}
}
}
}
}
21 changes: 0 additions & 21 deletions src/KubernetesClient/Models/ModelVersionConverter.cs

This file was deleted.

6 changes: 6 additions & 0 deletions src/KubernetesClient/Models/ResourceQuantity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public ResourceQuantity(decimal n, int exp, SuffixFormat format)
Format = format;
}

public ResourceQuantity(string s)
{
Value = s;
CustomInit();
}

public SuffixFormat Format { get; private set; }

public string CanonicalizeString()
Expand Down
6 changes: 3 additions & 3 deletions src/KubernetesClient/Models/ResourceQuantityJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ public override ResourceQuantity Read(ref Utf8JsonReader reader, Type typeToConv
switch (reader.TokenType)
{
case JsonTokenType.Null:
return new ResourceQuantity(null);
return new ResourceQuantity { Value = null };
case JsonTokenType.Number:
if (reader.TryGetDouble(out var val))
{
return new ResourceQuantity(Convert.ToString(val));
return new ResourceQuantity { Value = Convert.ToString(val) };
}

return reader.GetDecimal();
default:
return new ResourceQuantity(reader.GetString());
return new ResourceQuantity { Value = reader.GetString() };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
return null;
}

return new ResourceQuantity(scalar?.Value);
return new ResourceQuantity { Value = scalar?.Value };
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion src/KubernetesClient/Models/V1Patch.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace k8s.Models
{
[JsonConverter(typeof(V1PatchJsonConverter))]
public partial class V1Patch
public partial record class V1Patch
{
public enum PatchType
{
Expand Down
2 changes: 1 addition & 1 deletion src/KubernetesClient/Models/V1PodTemplateSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace k8s.Models
/// Partial implementation of the IMetadata interface
/// to open this class up to ModelExtensions methods
/// </summary>
public partial class V1PodTemplateSpec : IMetadata<V1ObjectMeta>
public partial record V1PodTemplateSpec : IMetadata<V1ObjectMeta>
{
}
}
2 changes: 1 addition & 1 deletion src/KubernetesClient/Models/V1Status.ObjectView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace k8s.Models
{
public partial class V1Status
public partial record V1Status
{
internal sealed class V1StatusObjectViewConverter : JsonConverter<V1Status>
{
Expand Down
2 changes: 1 addition & 1 deletion src/KubernetesClient/Models/V1Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace k8s.Models
{
public partial class V1Status
public partial record class V1Status
{
/// <summary>Converts a <see cref="V1Status"/> object into a short description of the status.</summary>
/// <returns>string description of the status</returns>
Expand Down
6 changes: 6 additions & 0 deletions src/LibKubernetesGenerator/ClassNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public string GetClassNameForSchemaDefinition(JsonSchema definition)
}


if (definition.Format == "int-or-string")
{
return "IntOrString";
}


return schemaToNameMapCooked[definition];
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/LibKubernetesGenerator/GeneralNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ private string GetInterfaceName(JsonSchema definition)
}
}

interfaces.Add("IValidate");

return string.Join(", ", interfaces);
}

Expand All @@ -68,7 +66,7 @@ public string GetDotNetNameOpenApiParameter(OpenApiParameter parameter, string i

if (init == "true" && !parameter.IsRequired)
{
name += " = null";
name += " = default";
}

return name;
Expand Down
4 changes: 0 additions & 4 deletions src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ private static IContainer BuildContainer(OpenApiDocument swagger)
builder.RegisterType<ScriptObjectFactory>()
;

builder.RegisterType<ModelExtGenerator>();
builder.RegisterType<SourceGenerationContextGenerator>();
builder.RegisterType<ModelGenerator>();
builder.RegisterType<ApiGenerator>();
builder.RegisterType<ClientSetGenerator>();
builder.RegisterType<VersionConverterStubGenerator>();
builder.RegisterType<VersionGenerator>();

return builder.Build();
Expand All @@ -79,9 +77,7 @@ public void Initialize(IncrementalGeneratorInitializationContext generatorContex
container.Resolve<VersionGenerator>().Generate(swagger, ctx);

container.Resolve<ModelGenerator>().Generate(swagger, ctx);
container.Resolve<ModelExtGenerator>().Generate(swagger, ctx);
container.Resolve<SourceGenerationContextGenerator>().Generate(swagger, ctx);
container.Resolve<VersionConverterStubGenerator>().Generate(swagger, ctx);
container.Resolve<ApiGenerator>().Generate(swagger, ctx);
container.Resolve<ClientSetGenerator>().Generate(swagger, ctx);
});
Expand Down
36 changes: 0 additions & 36 deletions src/LibKubernetesGenerator/ModelExtGenerator.cs

This file was deleted.

Loading
Loading