Skip to content

make V1.Patch strong type of JsonPatch #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/KubernetesClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Compile Remove="GlobalSuppressions.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="1.1.2" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.3" />
<PackageReference Include="Fractions" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="1.1.2" />
Expand Down
55 changes: 55 additions & 0 deletions src/V1Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using Microsoft.AspNetCore.JsonPatch;
using Newtonsoft.Json;

namespace k8s.Models
{
internal class V1PathJsonConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, (value as V1Patch)?.Content);
}

// no read patch object supported at the moment
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
{
throw new NotImplementedException();
}

public override bool CanConvert(Type objectType)
{
return objectType == typeof(V1Patch);
}
}

[JsonConverter(typeof(V1PathJsonConverter))]
public partial class V1Patch
{

public enum PathType
{
JsonPatch,
MergePatch,
StrategicMergePatch,
}

public PathType Type { get; private set; }

public V1Patch(IJsonPatchDocument jsonPatch) : this((object) jsonPatch)
{
}

partial void CustomInit()
{
if (Content is IJsonPatchDocument)
{
Type = PathType.JsonPatch;
return;
}

throw new NotSupportedException();
}
}
}
180 changes: 90 additions & 90 deletions src/generated/IKubernetes.cs

Large diffs are not rendered by default.

180 changes: 90 additions & 90 deletions src/generated/Kubernetes.cs

Large diffs are not rendered by default.

360 changes: 180 additions & 180 deletions src/generated/KubernetesExtensions.cs

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions src/generated/Models/V1Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <auto-generated>
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>

namespace k8s.Models
{
using Newtonsoft.Json;
using System.Linq;

public partial class V1Patch
{
/// <summary>
/// Initializes a new instance of the V1Patch class.
/// </summary>
public V1Patch()
{
CustomInit();
}

/// <summary>
/// Initializes a new instance of the V1Patch class.
/// </summary>
public V1Patch(object content = default(object))
{
Content = content;
CustomInit();
}

/// <summary>
/// An initialization method that performs custom operations like setting defaults
/// </summary>
partial void CustomInit();

/// <summary>
/// </summary>
[JsonProperty(PropertyName = "content")]
public object Content { get; private set; }

}
}
Loading