Skip to content

Commit 6c53987

Browse files
authored
Fix x-kubernetes-int-or-string in CRD can not be desterilized correctly. (#747)
* bug fix * add ut
1 parent e45fa77 commit 6c53987

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/KubernetesClient/Yaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private static TBuilder WithOverridesFromJsonPropertyAttributes<TBuilder>(this T
225225
continue;
226226
}
227227

228-
var yamlAttribute = new YamlMemberAttribute { Alias = jsonAttribute.PropertyName };
228+
var yamlAttribute = new YamlMemberAttribute { Alias = jsonAttribute.PropertyName, ApplyNamingConventions = false };
229229
builder.WithAttributeOverride(type, property.Name, yamlAttribute);
230230
}
231231
}

tests/KubernetesClient.Tests/YamlTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,5 +559,40 @@ public void LoadSecret()
559559
Assert.Equal("bXktYXBw", Encoding.UTF8.GetString(result.Data["username"]));
560560
Assert.Equal("Mzk1MjgkdmRnN0pi", Encoding.UTF8.GetString(result.Data["password"]));
561561
}
562+
563+
[Fact]
564+
public void DeserializeWithJsonPropertyName()
565+
{
566+
var kManifest = @"
567+
apiVersion: apiextensions.k8s.io/v1
568+
kind: CustomResourceDefinition
569+
metadata:
570+
name: test-crd
571+
spec:
572+
group: test.crd
573+
names:
574+
kind: Crd
575+
listKind: CrdList
576+
plural: crds
577+
singular: crd
578+
scope: Namespaced
579+
versions:
580+
- name: v1alpha1
581+
schema:
582+
openAPIV3Schema:
583+
description: This is a test crd.
584+
x-kubernetes-int-or-string: true
585+
required:
586+
- metadata
587+
- spec
588+
type: object
589+
served: true
590+
storage: true
591+
";
592+
var result = Yaml.LoadFromString<V1CustomResourceDefinition>(kManifest);
593+
Assert.Single(result?.Spec?.Versions);
594+
var ver = result.Spec.Versions[0];
595+
Assert.Equal(true, ver?.Schema?.OpenAPIV3Schema?.XKubernetesIntOrString);
596+
}
562597
}
563598
}

0 commit comments

Comments
 (0)