Fix x-kubernetes-int-or-string in CRD can not be desterilized correctly. (#747)

* bug fix

* add ut
This commit is contained in:
Binyang2014
2021-12-03 10:00:29 -08:00
committed by GitHub
parent e45fa773ba
commit 6c539873b5
2 changed files with 36 additions and 1 deletions

View File

@@ -225,7 +225,7 @@ namespace k8s
continue; continue;
} }
var yamlAttribute = new YamlMemberAttribute { Alias = jsonAttribute.PropertyName }; var yamlAttribute = new YamlMemberAttribute { Alias = jsonAttribute.PropertyName, ApplyNamingConventions = false };
builder.WithAttributeOverride(type, property.Name, yamlAttribute); builder.WithAttributeOverride(type, property.Name, yamlAttribute);
} }
} }

View File

@@ -559,5 +559,40 @@ data:
Assert.Equal("bXktYXBw", Encoding.UTF8.GetString(result.Data["username"])); Assert.Equal("bXktYXBw", Encoding.UTF8.GetString(result.Data["username"]));
Assert.Equal("Mzk1MjgkdmRnN0pi", Encoding.UTF8.GetString(result.Data["password"])); Assert.Equal("Mzk1MjgkdmRnN0pi", Encoding.UTF8.GetString(result.Data["password"]));
} }
[Fact]
public void DeserializeWithJsonPropertyName()
{
var kManifest = @"
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: test-crd
spec:
group: test.crd
names:
kind: Crd
listKind: CrdList
plural: crds
singular: crd
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: This is a test crd.
x-kubernetes-int-or-string: true
required:
- metadata
- spec
type: object
served: true
storage: true
";
var result = Yaml.LoadFromString<V1CustomResourceDefinition>(kManifest);
Assert.Single(result?.Spec?.Versions);
var ver = result.Spec.Versions[0];
Assert.Equal(true, ver?.Schema?.OpenAPIV3Schema?.XKubernetesIntOrString);
}
} }
} }