Skip to content

Commit

Permalink
feat: improve openapi generator support for apiextensions
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa authored Jul 9, 2024
1 parent f1dd712 commit c0a20aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions kubernetes-model-generator/openapi/generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.0
require (
github.com/getkin/kin-openapi v0.125.0
k8s.io/api v0.30.2
k8s.io/apiextensions-apiserver v0.30.2
k8s.io/apimachinery v0.30.2
k8s.io/client-go v0.30.2
)
Expand Down
2 changes: 2 additions & 0 deletions kubernetes-model-generator/openapi/generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.30.2 h1:+ZhRj+28QT4UOH+BKznu4CBgPWgkXO7XAvMcMl0qKvI=
k8s.io/api v0.30.2/go.mod h1:ULg5g9JvOev2dG0u2hig4Z7tQ2hHIuS+m8MNZ+X6EmI=
k8s.io/apiextensions-apiserver v0.30.2 h1:l7Eue2t6QiLHErfn2vwK4KgF4NeDgjQkCXtEbOocKIE=
k8s.io/apiextensions-apiserver v0.30.2/go.mod h1:lsJFLYyK40iguuinsb3nt+Sj6CmodSI4ACDLep1rgjw=
k8s.io/apimachinery v0.30.2 h1:fEMcnBj6qkzzPGSVsAZtQThU62SmQ4ZymlXRC5yFSCg=
k8s.io/apimachinery v0.30.2/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
k8s.io/client-go v0.30.2 h1:sBIVJdojUNPDU/jObC+18tXWcTJVcwyqS9diGdWHk50=
Expand Down
28 changes: 18 additions & 10 deletions kubernetes-model-generator/openapi/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package main

import (
"github.com/getkin/kin-openapi/openapi3"
v1admission "k8s.io/api/admission/v1"
v1beta1admission "k8s.io/api/admission/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
configapi "k8s.io/client-go/tools/clientcmd/api/v1"
admissionV1 "k8s.io/api/admission/v1"
admissionV1Beta1 "k8s.io/api/admission/v1beta1"
apiextensionsV1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsV1Beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
configapiV1 "k8s.io/client-go/tools/clientcmd/api/v1"
"os"
"path/filepath"
"reflect"
Expand All @@ -45,17 +47,23 @@ func main() {
panic(err)
}
schemas := []Schemas{
{[]reflect.Type{reflect.TypeOf(configapi.Config{})}, "kubernetes-config"},
{[]reflect.Type{reflect.TypeOf(configapiV1.Config{})}, "kubernetes-config"},
{[]reflect.Type{
reflect.TypeOf(v1admission.AdmissionRequest{}),
reflect.TypeOf(v1beta1admission.AdmissionRequest{}),
}, "admission-registration"},
{[]reflect.Type{
reflect.TypeOf(metav1.MicroTime{}),
reflect.TypeOf(metaV1.MicroTime{}),
// reflect.TypeOf(metav1.GroupKind{}),
// reflect.TypeOf(metav1.GroupVersionKind{}),
// reflect.TypeOf(metav1.GroupVersionResource{}),
}, "api-machinery-extra"},
{[]reflect.Type{
reflect.TypeOf(admissionV1.AdmissionRequest{}),
reflect.TypeOf(admissionV1Beta1.AdmissionRequest{}),
}, "admission-registration"},
{[]reflect.Type{
reflect.TypeOf(apiextensionsV1.ConversionReview{}),
reflect.TypeOf(apiextensionsV1Beta1.ConversionReview{}),
reflect.TypeOf(apiextensionsV1Beta1.SelectableField{}),
reflect.TypeOf(apiextensionsV1Beta1.ValidationRule{}),
}, "apiextensions"},
}
generate(schemas, targetDirectory)
}
Expand Down

0 comments on commit c0a20aa

Please sign in to comment.