Skip to content

Commit 7408926

Browse files
tg123brendandburns
authored andcommitted
make V1.Patch strong type of JsonPatch (#84)
* generate patch object * generate using private set * force patch to strong type
1 parent edc0cfb commit 7408926

File tree

7 files changed

+551
-540
lines changed

7 files changed

+551
-540
lines changed

src/KubernetesClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<Compile Remove="GlobalSuppressions.cs" />
1717
</ItemGroup>
1818
<ItemGroup>
19+
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="1.1.2" />
1920
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.3" />
2021
<PackageReference Include="Fractions" Version="3.0.1" />
2122
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="1.1.2" />

src/V1Patch.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using Microsoft.AspNetCore.JsonPatch;
3+
using Newtonsoft.Json;
4+
5+
namespace k8s.Models
6+
{
7+
internal class V1PathJsonConverter : JsonConverter
8+
{
9+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
10+
{
11+
serializer.Serialize(writer, (value as V1Patch)?.Content);
12+
}
13+
14+
// no read patch object supported at the moment
15+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
16+
JsonSerializer serializer)
17+
{
18+
throw new NotImplementedException();
19+
}
20+
21+
public override bool CanConvert(Type objectType)
22+
{
23+
return objectType == typeof(V1Patch);
24+
}
25+
}
26+
27+
[JsonConverter(typeof(V1PathJsonConverter))]
28+
public partial class V1Patch
29+
{
30+
31+
public enum PathType
32+
{
33+
JsonPatch,
34+
MergePatch,
35+
StrategicMergePatch,
36+
}
37+
38+
public PathType Type { get; private set; }
39+
40+
public V1Patch(IJsonPatchDocument jsonPatch) : this((object) jsonPatch)
41+
{
42+
}
43+
44+
partial void CustomInit()
45+
{
46+
if (Content is IJsonPatchDocument)
47+
{
48+
Type = PathType.JsonPatch;
49+
return;
50+
}
51+
52+
throw new NotSupportedException();
53+
}
54+
}
55+
}

src/generated/IKubernetes.cs

Lines changed: 90 additions & 90 deletions
Large diffs are not rendered by default.

src/generated/Kubernetes.cs

Lines changed: 90 additions & 90 deletions
Large diffs are not rendered by default.

src/generated/KubernetesExtensions.cs

Lines changed: 180 additions & 180 deletions
Large diffs are not rendered by default.

src/generated/Models/V1Patch.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// <auto-generated>
2+
// Code generated by Microsoft (R) AutoRest Code Generator.
3+
// Changes may cause incorrect behavior and will be lost if the code is
4+
// regenerated.
5+
// </auto-generated>
6+
7+
namespace k8s.Models
8+
{
9+
using Newtonsoft.Json;
10+
using System.Linq;
11+
12+
public partial class V1Patch
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the V1Patch class.
16+
/// </summary>
17+
public V1Patch()
18+
{
19+
CustomInit();
20+
}
21+
22+
/// <summary>
23+
/// Initializes a new instance of the V1Patch class.
24+
/// </summary>
25+
public V1Patch(object content = default(object))
26+
{
27+
Content = content;
28+
CustomInit();
29+
}
30+
31+
/// <summary>
32+
/// An initialization method that performs custom operations like setting defaults
33+
/// </summary>
34+
partial void CustomInit();
35+
36+
/// <summary>
37+
/// </summary>
38+
[JsonProperty(PropertyName = "content")]
39+
public object Content { get; private set; }
40+
41+
}
42+
}

0 commit comments

Comments
 (0)