kubernetes-retired / cluster-registry

[EOL] Cluster Registry API
https://kubernetes.github.io/cluster-registry/
Apache License 2.0
238 stars 94 forks source link

Fix OpenAPI code generation for MicroTime and Time structures #159

Closed font closed 6 years ago

font commented 6 years ago

Our OpenAPI code generation is not properly detecting the MicroTime and Time custom OpenAPI schema defined in their respective files. For example, MicroTime defines https://github.com/kubernetes/apimachinery/blob/20bbfef868144faf29af69ddb2f01646ead5c1a1/pkg/apis/meta/v1/micro_time.go#L152-L161 which should be picked up by the openapi-gen code generator to generate the following diff output:

diff --git a/pkg/apis/clusterregistry/v1alpha1/zz_generated.openapi.go b/pkg/apis/clusterregistry/v1alpha1/zz_generated.openapi.go
index 01aa6f2e..a5c5a8c2 100644
--- a/pkg/apis/clusterregistry/v1alpha1/zz_generated.openapi.go
+++ b/pkg/apis/clusterregistry/v1alpha1/zz_generated.openapi.go
@@ -22,6 +22,7 @@ package v1alpha1

 import (
    spec "github.com/go-openapi/spec"
+   v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    common "k8s.io/kube-openapi/pkg/common"
 )

@@ -941,23 +942,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
            },
            Dependencies: []string{},
        },
-       "k8s.io/apimachinery/pkg/apis/meta/v1.MicroTime": {
-           Schema: spec.Schema{
-               SchemaProps: spec.SchemaProps{
-                   Description: "MicroTime is version of Time with microsecond level precision.",
-                   Properties: map[string]spec.Schema{
-                       "Time": {
-                           SchemaProps: spec.SchemaProps{
-                               Type:   []string{"string"},
-                               Format: "date-time",
-                           },
-                       },
-                   },
-                   Required: []string{"Time"},
-               },
-           },
-           Dependencies: []string{},
-       },
+       "k8s.io/apimachinery/pkg/apis/meta/v1.MicroTime": v1.MicroTime{}.OpenAPIDefinition(),
        "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta": {
            Schema: spec.Schema{
                SchemaProps: spec.SchemaProps{
@@ -1400,23 +1385,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
            Dependencies: []string{
                "k8s.io/apimachinery/pkg/apis/meta/v1.StatusCause"},
        },
-       "k8s.io/apimachinery/pkg/apis/meta/v1.Time": {
-           Schema: spec.Schema{
-               SchemaProps: spec.SchemaProps{
-                   Description: "Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON.  Wrappers are provided for many of the factory methods that the time package offers.",
-                   Properties: map[string]spec.Schema{
-                       "Time": {
-                           SchemaProps: spec.SchemaProps{
-                               Type:   []string{"string"},
-                               Format: "date-time",
-                           },
-                       },
-                   },
-                   Required: []string{"Time"},
-               },
-           },
-           Dependencies: []string{},
-       },
+       "k8s.io/apimachinery/pkg/apis/meta/v1.Time": v1.Time{}.OpenAPIDefinition(),
        "k8s.io/apimachinery/pkg/apis/meta/v1.Timestamp": {
            Schema: spec.Schema{
                SchemaProps: spec.SchemaProps{

To reproduce this, add --v=10 and possibly also --logtostderr (or just look for the file /tmp/openapi-gen.*) in the openapi-gen step at: https://github.com/kubernetes/cluster-registry/blob/cc52bb00104bda72a2a14fdf49d71630e81c1fe8/hack/update-codegen.sh#L114-L120 The problem appears to arise due to missing imports, particularly this one:

I1220 16:35:12.455910    9557 parse.go:418] type checker: /tmp/gopathnU5sCI0j/src/k8s.io/apimachinery/pkg/apis/meta/v1/micro_time.go:23:10: could not import k8s.io/kube-openapi/pkg/common (unable to import "k8s.io/kube-openapi/pkg/common": cannot find package "k8s.io/kube-openapi/pkg/common" in any of:
    /usr/local/go/src/k8s.io/kube-openapi/pkg/common (from $GOROOT)
    /tmp/gopathnU5sCI0j/src/k8s.io/kube-openapi/pkg/common (from $GOPATH))

/sig multicluster

pmorie commented 6 years ago

@luksa - didn’t you recently hit this in service-catalog?

On Wed, Dec 20, 2017 at 8:13 PM Ivan Font notifications@github.com wrote:

Our OpenAPI code generation is not properly detecting the MicroTime and Time custom OpenAPI schema defined in their respective files. For example, MicroTime defines https://github.com/kubernetes/apimachinery/blob/20bbfef868144faf29af69ddb2f01646ead5c1a1/pkg/apis/meta/v1/micro_time.go#L152-L161 which should be picked up by the openapi-gen code generator to generate the following diff output:

diff --git a/pkg/apis/clusterregistry/v1alpha1/zz_generated.openapi.go b/pkg/apis/clusterregistry/v1alpha1/zz_generated.openapi.go index 01aa6f2e..a5c5a8c2 100644--- a/pkg/apis/clusterregistry/v1alpha1/zz_generated.openapi.go+++ b/pkg/apis/clusterregistry/v1alpha1/zz_generated.openapi.go@@ -22,6 +22,7 @@ package v1alpha1

import ( spec "github.com/go-openapi/spec"+ v1 "k8s.io/apimachinery/pkg/apis/meta/v1" common "k8s.io/kube-openapi/pkg/common" ) @@ -941,23 +942,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA }, Dependencies: []string{}, },- "k8s.io/apimachinery/pkg/apis/meta/v1.MicroTime": {- Schema: spec.Schema{- SchemaProps: spec.SchemaProps{- Description: "MicroTime is version of Time with microsecond level precision.",- Properties: map[string]spec.Schema{- "Time": {- SchemaProps: spec.SchemaProps{- Type: []string{"string"},- Format: "date-time",- },- },- },- Required: []string{"Time"},- },- },- Dependencies: []string{},- },+ "k8s.io/apimachinery/pkg/apis/meta/v1.MicroTime": v1.MicroTime{}.OpenAPIDefinition(), "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta": { Schema: spec.Schema{ SchemaProps: spec.SchemaProps{@@ -1400,23 +1385,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA Dependencies: []string{ "k8s.io/apimachinery/pkg/apis/meta/v1.StatusCause"}, },- "k8s.io/apimachinery/pkg/apis/meta/v1.Time": {- Schema: spec.Schema{- SchemaProps: spec.SchemaProps{- Description: "Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.",- Properties: map[string]spec.Schema{- "Time": {- SchemaProps: spec.SchemaProps{- Type: []string{"string"},- Format: "date-time",- },- },- },- Required: []string{"Time"},- },- },- Dependencies: []string{},- },+ "k8s.io/apimachinery/pkg/apis/meta/v1.Time": v1.Time{}.OpenAPIDefinition(), "k8s.io/apimachinery/pkg/apis/meta/v1.Timestamp": { Schema: spec.Schema{ SchemaProps: spec.SchemaProps{

To reproduce this, add --v=10 and possibly also --logtostderr (or just look for the file /tmp/openapi-gen.*) in the openapi-gen step at: https://github.com/kubernetes/cluster-registry/blob/cc52bb00104bda72a2a14fdf49d71630e81c1fe8/hack/update-codegen.sh#L114-L120 The problem appears to arise due to missing imports, particularly this one:

I1220 16:35:12.455910 9557 parse.go:418] type checker: /tmp/gopathnU5sCI0j/src/k8s.io/apimachinery/pkg/apis/meta/v1/micro_time.go:23:10: could not import k8s.io/kube-openapi/pkg/common (unable to import "k8s.io/kube-openapi/pkg/common": cannot find package "k8s.io/kube-openapi/pkg/common" in any of: /usr/local/go/src/k8s.io/kube-openapi/pkg/common (from $GOROOT) /tmp/gopathnU5sCI0j/src/k8s.io/kube-openapi/pkg/common (from $GOPATH))

/sig multicluster

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kubernetes/cluster-registry/issues/159, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWXmLUl4FC5-apAnXvaRGAQCOc7DRbDks5tCbDOgaJpZM4RJOaa .