Skip to content

Commit

Permalink
Merge pull request fabric8io#2291 from rohanKanojia/pr/manual-type-ma…
Browse files Browse the repository at this point in the history
…p-generator
  • Loading branch information
fusesource-ci authored Jun 22, 2020
2 parents 8bf717a + d75bc9b commit 8e06822
Show file tree
Hide file tree
Showing 26 changed files with 126 additions and 221 deletions.
2 changes: 1 addition & 1 deletion kubernetes-model-generator/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/fabric8io/kubernetes-client/kubernetes-model
module github.com/fabric8io/kubernetes-client/kubernetes-model-generator

go 1.14

Expand Down
2 changes: 2 additions & 0 deletions kubernetes-model-generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/euank/go-kmsg-parser v2.0.0+incompatible/go.mod h1:MhmAMZ8V4CYH4ybgdRwPr2TU5ThnS43puaKEMpja1uw=
github.com/evanphx/json-patch v0.0.0-20190203023257-5858425f7550/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fabric8io/kubernetes-client v1.4.35 h1:uxi2o/28eo/SMD6+6g0dwNj3oAIrocrgac/6wGQzt+Q=
github.com/fabric8io/kubernetes-client v4.10.2+incompatible h1:4qE4aOrv3GBCRo9wQf4VwKkIEznVq7l+4HHesCEGIUk=
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (

"os"

"github.com/fabric8io/kubernetes-client/kubernetes-model/pkg/schemagen"
"github.com/fabric8io/kubernetes-client/kubernetes-model-generator/pkg/schemagen"
)

type Schema struct {
Expand Down Expand Up @@ -87,11 +87,6 @@ type Schema struct {
}

func main() {
customTypeNames := map[string]string{
"K8sSubjectAccessReview": "SubjectAccessReview",
"K8sLocalSubjectAccessReview": "LocalSubjectAccessReview",
"JSONSchemaPropsorStringArray": "JSONSchemaPropsOrStringArray",
}
packages := []schemagen.PackageDescriptor{
{"k8s.io/api/admission/v1beta1", "admission.k8s.io", "io.fabric8.kubernetes.api.model.admission", "kubernetes_admission_"},
{"k8s.io/api/admissionregistration/v1beta1", "admissionregistration.k8s.io", "io.fabric8.kubernetes.api.model.admissionregistration.v1beta1", "kubernetes_admissionregistration_v1beta1_"},
Expand All @@ -108,7 +103,7 @@ func main() {
reflect.TypeOf(time.Time{}): reflect.TypeOf(""),
reflect.TypeOf(struct{}{}): reflect.TypeOf(""),
}
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, customTypeNames, "admissionregistration")
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, map[reflect.Type]string{}, "admissionregistration")
if err != nil {
fmt.Fprintf(os.Stderr, "An error occurred: %v", err)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3265,15 +3265,14 @@
"admissionReviewVersions": {
"type": "array",
"description": "",
"javaOmitEmpty": true,
"items": {
"type": "string",
"description": ""
}
},
"clientConfig": {
"$ref": "#/definitions/kubernetes_admissionregistration_v1beta1_WebhookClientConfig",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1beta1.WebhookClientConfig"
"$ref": "#/definitions/kubernetes_admissionregistration_v1_WebhookClientConfig",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1.WebhookClientConfig"
},
"failurePolicy": {
"type": "string",
Expand Down Expand Up @@ -3304,8 +3303,8 @@
"description": "",
"javaOmitEmpty": true,
"items": {
"$ref": "#/definitions/kubernetes_admissionregistration_v1beta1_RuleWithOperations",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1beta1.RuleWithOperations"
"$ref": "#/definitions/kubernetes_admissionregistration_v1_RuleWithOperations",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1.RuleWithOperations"
}
},
"sideEffects": {
Expand Down Expand Up @@ -4262,15 +4261,14 @@
"admissionReviewVersions": {
"type": "array",
"description": "",
"javaOmitEmpty": true,
"items": {
"type": "string",
"description": ""
}
},
"clientConfig": {
"$ref": "#/definitions/kubernetes_admissionregistration_v1beta1_WebhookClientConfig",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1beta1.WebhookClientConfig"
"$ref": "#/definitions/kubernetes_admissionregistration_v1_WebhookClientConfig",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1.WebhookClientConfig"
},
"failurePolicy": {
"type": "string",
Expand All @@ -4297,8 +4295,8 @@
"description": "",
"javaOmitEmpty": true,
"items": {
"$ref": "#/definitions/kubernetes_admissionregistration_v1beta1_RuleWithOperations",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1beta1.RuleWithOperations"
"$ref": "#/definitions/kubernetes_admissionregistration_v1_RuleWithOperations",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1.RuleWithOperations"
}
},
"sideEffects": {
Expand Down Expand Up @@ -4347,15 +4345,15 @@
"apiVersion": {
"type": "string",
"description": "",
"default": "admissionregistration.k8s.io/v1beta1",
"default": "admissionregistration.k8s.io/v1",
"required": true
},
"items": {
"type": "array",
"description": "",
"items": {
"$ref": "#/definitions/kubernetes_admissionregistration_v1beta1_ValidatingWebhookConfiguration",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1beta1.ValidatingWebhookConfiguration"
"$ref": "#/definitions/kubernetes_admissionregistration_v1_ValidatingWebhookConfiguration",
"javaType": "io.fabric8.kubernetes.api.model.admissionregistration.v1.ValidatingWebhookConfiguration"
}
},
"kind": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bytes"
"encoding/json"
"fmt"

// Dependencies of rbac
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -34,7 +35,7 @@ import (

"os"

"github.com/fabric8io/kubernetes-client/kubernetes-model/pkg/schemagen"
"github.com/fabric8io/kubernetes-client/kubernetes-model-generator/pkg/schemagen"
)

type Schema struct {
Expand Down Expand Up @@ -65,15 +66,10 @@ type Schema struct {
CustomResourceDefinitionStatus apiextensions.CustomResourceDefinitionStatus
// Added JSONSchemaPropsorStringArray here because of
// https://github.com/joelittlejohn/jsonschema2pojo/issues/866
JSONSchemaPropsorStringArray apiextensions.JSONSchemaPropsOrStringArray
JSONSchemaPropsOrStringArray apiextensions.JSONSchemaPropsOrStringArray
}

func main() {
customTypeNames := map[string]string{
"K8sSubjectAccessReview": "SubjectAccessReview",
"K8sLocalSubjectAccessReview": "LocalSubjectAccessReview",
"JSONSchemaPropsorStringArray": "JSONSchemaPropsOrStringArray",
}
packages := []schemagen.PackageDescriptor{
{"k8s.io/apimachinery/pkg/util/intstr", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_pkg_util_intstr_"},
{"k8s.io/apimachinery/pkg/runtime", "", "io.fabric8.kubernetes.api.model.runtime", "kubernetes_apimachinery_pkg_runtime_"},
Expand All @@ -87,7 +83,12 @@ func main() {
reflect.TypeOf(time.Time{}): reflect.TypeOf(""),
reflect.TypeOf(struct{}{}): reflect.TypeOf(""),
}
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, customTypeNames, "apiextensions")

// overwriting some times
manualTypeMapping := map[reflect.Type]string{
reflect.TypeOf(apiextensions.JSON{}): "com.fasterxml.jackson.databind.JsonNode",
}
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, manualTypeMapping, "apiextensions")
if err != nil {
fmt.Fprintf(os.Stderr, "An error occurred: %v", err)
return
Expand Down Expand Up @@ -126,16 +127,6 @@ func main() {
result := string(b)
result = strings.Replace(result, "\"additionalProperty\":", "\"additionalProperties\":", -1)

/**
* Hack to fix https://github.com/fabric8io/kubernetes-client/issues/1565 and https://github.com/fabric8io/kubernetes-client/issues/2144
*
* The source golang code uses a type JSON which has a custom serializer and deserializer to ensure that it gets properly
* translated to and from a string. This gets compiled into a JSON.java class which does not have any such serialization support.
* This JSON type sounds a lot like JsonNode, which encapsulates any json value. Use that instead.
*/
result = strings.Replace(result, "{\"$ref\":\"#/definitions/kubernetes_apiextensions_JSON\",\"javaType\":\"io.fabric8.kubernetes.api.model.apiextensions.JSON\"}",
"{\"javaType\":\"com.fasterxml.jackson.databind.JsonNode\"}", -1)

var out bytes.Buffer
err = json.Indent(&out, []byte(result), "", " ")
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
}
},
"additionalProperties": true,
"javaType": "io.fabric8.kubernetes.api.model.apiextensions.JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
Expand Down Expand Up @@ -499,6 +499,7 @@
}
},
"default": {
"$ref": "#/definitions/kubernetes_apiextensions_JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode"
},
"definitions": {
Expand Down Expand Up @@ -528,10 +529,12 @@
"description": "",
"javaOmitEmpty": true,
"items": {
"$ref": "#/definitions/kubernetes_apiextensions_JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode"
}
},
"example": {
"$ref": "#/definitions/kubernetes_apiextensions_JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode"
},
"exclusiveMaximum": {
Expand Down Expand Up @@ -1776,7 +1779,7 @@
"$ref": "#/definitions/kubernetes_apimachinery_pkg_version_Info",
"javaType": "io.fabric8.kubernetes.api.model.version.Info"
},
"JSONSchemaPropsorStringArray": {
"JSONSchemaPropsOrStringArray": {
"$ref": "#/definitions/kubernetes_apiextensions_JSONSchemaPropsOrStringArray",
"javaType": "io.fabric8.kubernetes.api.model.apiextensions.JSONSchemaPropsOrStringArray"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
}
},
"additionalProperties": true,
"javaType": "io.fabric8.kubernetes.api.model.apiextensions.JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
Expand Down Expand Up @@ -499,6 +499,7 @@
}
},
"default": {
"$ref": "#/definitions/kubernetes_apiextensions_JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode"
},
"definitions": {
Expand Down Expand Up @@ -528,10 +529,12 @@
"description": "",
"javaOmitEmpty": true,
"items": {
"$ref": "#/definitions/kubernetes_apiextensions_JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode"
}
},
"example": {
"$ref": "#/definitions/kubernetes_apiextensions_JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode"
},
"exclusiveMaximum": {
Expand Down Expand Up @@ -1776,7 +1779,7 @@
"$ref": "#/definitions/kubernetes_apimachinery_pkg_version_Info",
"javaType": "io.fabric8.kubernetes.api.model.version.Info"
},
"JSONSchemaPropsorStringArray": {
"JSONSchemaPropsOrStringArray": {
"$ref": "#/definitions/kubernetes_apiextensions_JSONSchemaPropsOrStringArray",
"javaType": "io.fabric8.kubernetes.api.model.apiextensions.JSONSchemaPropsOrStringArray"
},
Expand Down Expand Up @@ -2436,6 +2439,7 @@
}
},
"default": {
"$ref": "#/definitions/kubernetes_apiextensions_JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode"
},
"definitions": {
Expand Down Expand Up @@ -2465,10 +2469,12 @@
"description": "",
"javaOmitEmpty": true,
"items": {
"$ref": "#/definitions/kubernetes_apiextensions_JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode"
}
},
"example": {
"$ref": "#/definitions/kubernetes_apiextensions_JSON",
"javaType": "com.fasterxml.jackson.databind.JsonNode"
},
"exclusiveMaximum": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

"os"

"github.com/fabric8io/kubernetes-client/kubernetes-model/pkg/schemagen"
"github.com/fabric8io/kubernetes-client/kubernetes-model-generator/pkg/schemagen"
)

type Schema struct {
Expand Down Expand Up @@ -99,11 +99,6 @@ type Schema struct {
}

func main() {
customTypeNames := map[string]string{
"K8sSubjectAccessReview": "SubjectAccessReview",
"K8sLocalSubjectAccessReview": "LocalSubjectAccessReview",
"JSONSchemaPropsorStringArray": "JSONSchemaPropsOrStringArray",
}
packages := []schemagen.PackageDescriptor{
{"k8s.io/apimachinery/pkg/util/intstr", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_pkg_util_intstr_"},
{"k8s.io/apimachinery/pkg/runtime", "", "io.fabric8.kubernetes.api.model.runtime", "kubernetes_apimachinery_pkg_runtime_"},
Expand All @@ -122,7 +117,7 @@ func main() {
reflect.TypeOf(time.Time{}): reflect.TypeOf(""),
reflect.TypeOf(struct{}{}): reflect.TypeOf(""),
}
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, customTypeNames, "apps")
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, map[reflect.Type]string{},"apps")
if err != nil {
fmt.Fprintf(os.Stderr, "An error occurred: %v", err)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

"os"

"github.com/fabric8io/kubernetes-client/kubernetes-model/pkg/schemagen"
"github.com/fabric8io/kubernetes-client/kubernetes-model-generator/pkg/schemagen"
)

type Schema struct {
Expand Down Expand Up @@ -67,11 +67,6 @@ type Schema struct {
}

func main() {
customTypeNames := map[string]string{
"K8sSubjectAccessReview": "SubjectAccessReview",
"K8sLocalSubjectAccessReview": "LocalSubjectAccessReview",
"JSONSchemaPropsorStringArray": "JSONSchemaPropsOrStringArray",
}
packages := []schemagen.PackageDescriptor{
{"k8s.io/apimachinery/pkg/util/intstr", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_pkg_util_intstr_"},
{"k8s.io/apimachinery/pkg/runtime", "", "io.fabric8.kubernetes.api.model.runtime", "kubernetes_apimachinery_pkg_runtime_"},
Expand All @@ -87,7 +82,7 @@ func main() {
reflect.TypeOf(time.Time{}): reflect.TypeOf(""),
reflect.TypeOf(struct{}{}): reflect.TypeOf(""),
}
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, customTypeNames, "autoscaling")
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, map[reflect.Type]string{},"autoscaling")
if err != nil {
fmt.Fprintf(os.Stderr, "An error occurred: %v", err)
return
Expand Down
Loading

0 comments on commit 8e06822

Please sign in to comment.