Skip to content

Commit

Permalink
feat: openapi generator generates fake paths
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa authored Jul 10, 2024
1 parent 0542d96 commit 5be71f6
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 41 deletions.
12 changes: 7 additions & 5 deletions kubernetes-model-generator/openapi/generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ Many of these types are used for WebHooks.

## Generated Schemas

| Schema | Description |
|------------------------|---------------------------------------------------------------------|
| kubernetes-config | Types used in the Kuberenetes configuration file ( `.kube/config` ) |
| admission-registration | Additional types required for the admission registration API |
| apiextensions | Additional types required for the apiextension API |
| Schema | Description |
|------------------------|-----------------------------------------------------------------------------------------|
| kubernetes-config | Types used in the Kuberenetes configuration file ( `.kube/config` ) |
| api-machinery-extra | Required types not exposed in the OpenAPI spec |
| admission-registration | Additional types required for the admission registration API |
| apiextensions | Additional types required for the apiextension API |
| gateway-api | https://github.com/kubernetes-sigs/gateway-api (should qualify as an extension instead) |


## Usage
Expand Down
15 changes: 11 additions & 4 deletions kubernetes-model-generator/openapi/generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ require (
k8s.io/apiextensions-apiserver v0.30.2
k8s.io/apimachinery v0.30.2
k8s.io/client-go v0.30.2
k8s.io/kube-openapi v0.0.0-20240423202451-8948a665c108
sigs.k8s.io/gateway-api v1.1.0
)

require (
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/swag v0.22.8 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -24,13 +30,14 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
k8s.io/utils v0.0.0-20240423183400-0849a56e8f22 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
42 changes: 22 additions & 20 deletions kubernetes-model-generator/openapi/generator/go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk=
github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/getkin/kin-openapi v0.125.0 h1:jyQCyf2qXS1qvs2U00xQzkGCqYPhEhZDmSmVt65fXno=
github.com/getkin/kin-openapi v0.125.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q=
github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs=
github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.8 h1:/9RjDSQ0vbFR+NyjGMkFTsA1IA0fmhKSThmfGZjicbw=
github.com/go-openapi/swag v0.22.8/go.mod h1:6QT22icPLEqAM/z/TChgb4WAveCHF92+2gF0CNjHpPI=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand All @@ -27,8 +27,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down Expand Up @@ -62,8 +62,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand All @@ -77,8 +77,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -120,13 +120,15 @@ k8s.io/client-go v0.30.2 h1:sBIVJdojUNPDU/jObC+18tXWcTJVcwyqS9diGdWHk50=
k8s.io/client-go v0.30.2/go.mod h1:JglKSWULm9xlJLx4KCkfLLQ7XwtlbflV6uFFSHTMgVs=
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/kube-openapi v0.0.0-20240423202451-8948a665c108 h1:Q8Z7VlGhcJgBHJHYugJ/K/7iB8a2eSxCyxdVjJp+lLY=
k8s.io/kube-openapi v0.0.0-20240423202451-8948a665c108/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
k8s.io/utils v0.0.0-20240423183400-0849a56e8f22 h1:ao5hUqGhsqdm+bYbjH/pRkCs0unBGe9UyDahzs9zQzQ=
k8s.io/utils v0.0.0-20240423183400-0849a56e8f22/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/gateway-api v1.1.0 h1:DsLDXCi6jR+Xz8/xd0Z1PYl2Pn0TyaFMOPPZIj4inDM=
sigs.k8s.io/gateway-api v1.1.0/go.mod h1:ZH4lHrL2sDi0FHZ9jjneb8kKnGzFWyrTya35sWUTrRs=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
79 changes: 67 additions & 12 deletions kubernetes-model-generator/openapi/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,29 @@ import (
"os"
"path/filepath"
"reflect"
gatewayApiV1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayApiV1Beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
"strings"
"time"
)

type Schemas struct {
type Schema struct {
Types []reflect.Type
Name string
Paths map[reflect.Type]string
}

func NewTypeSchema(types []reflect.Type, name string) Schema {
return Schema{types, name, make(map[reflect.Type]string)}
}

func NewPathSchema(paths map[reflect.Type]string, name string) Schema {
schema := Schema{make([]reflect.Type, 0), name, paths}
for t := range paths {
schema.Types = append(schema.Types, t)

}
return schema
}

func main() {
Expand All @@ -48,9 +64,9 @@ func main() {
if err != nil {
panic(err)
}
schemas := []Schemas{
{[]reflect.Type{reflect.TypeOf(configapiV1.Config{})}, "kubernetes-config"},
{[]reflect.Type{
schemas := []Schema{
NewTypeSchema([]reflect.Type{reflect.TypeOf(configapiV1.Config{})}, "kubernetes-config"),
NewTypeSchema([]reflect.Type{
reflect.TypeOf(metaV1.MicroTime{}),
reflect.TypeOf(metaV1.CreateOptions{}),
reflect.TypeOf(metaV1.DeleteOptions{}),
Expand All @@ -62,13 +78,13 @@ func main() {
reflect.TypeOf(metaV1.RootPaths{}),
reflect.TypeOf(metaV1.GroupKind{}),
reflect.TypeOf(metaV1.TypeMeta{}), // TODO: can be removed, it's an inline type not directly used
}, "api-machinery-extra"},
{[]reflect.Type{
}, "api-machinery-extra"),
NewTypeSchema([]reflect.Type{
reflect.TypeOf(admissionV1.AdmissionReview{}),
reflect.TypeOf(admissionV1Beta1.AdmissionReview{}),
reflect.TypeOf(admissionregistrationV1.Rule{}),
}, "admission-registration"},
{[]reflect.Type{
}, "admission-registration"),
NewTypeSchema([]reflect.Type{
reflect.TypeOf(apiextensionsV1.ConversionReview{}),
reflect.TypeOf(apiextensionsV1.JSONSchemaPropsOrArray{}),
reflect.TypeOf(apiextensionsV1.JSONSchemaPropsOrBool{}),
Expand All @@ -79,12 +95,26 @@ func main() {
reflect.TypeOf(apiextensionsV1Beta1.JSONSchemaPropsOrStringArray{}),
reflect.TypeOf(apiextensionsV1Beta1.SelectableField{}),
reflect.TypeOf(apiextensionsV1Beta1.ValidationRule{}),
}, "apiextensions"},
}, "apiextensions"),
NewPathSchema(map[reflect.Type]string{
reflect.TypeOf(gatewayApiV1.GatewayList{}): "/apis/" + gatewayApiV1.GroupName + "/v1/namespaces/{namespace}/gateways",
reflect.TypeOf(gatewayApiV1.Gateway{}): "/apis/" + gatewayApiV1.GroupName + "/v1/namespaces/{namespace}/gateways/{name}",
reflect.TypeOf(gatewayApiV1.GatewayClassList{}): "/apis/" + gatewayApiV1.GroupName + "/v1/gatewayclasses",
reflect.TypeOf(gatewayApiV1.GatewayClass{}): "/apis/" + gatewayApiV1.GroupName + "/v1/gatewayclasses/{name}",
reflect.TypeOf(gatewayApiV1.HTTPRouteList{}): "/apis/" + gatewayApiV1.GroupName + "/v1/namespaces/{namespace}/httproutes",
reflect.TypeOf(gatewayApiV1.HTTPRoute{}): "/apis/" + gatewayApiV1.GroupName + "/v1/namespaces/{namespace}/httproutes/{name}",
reflect.TypeOf(gatewayApiV1Beta1.GatewayList{}): "/apis/" + gatewayApiV1.GroupName + "/v1beta1/namespaces/{namespace}/gateways",
reflect.TypeOf(gatewayApiV1Beta1.Gateway{}): "/apis/" + gatewayApiV1.GroupName + "/v1beta1/namespaces/{namespace}/gateways/{name}",
reflect.TypeOf(gatewayApiV1Beta1.GatewayClassList{}): "/apis/" + gatewayApiV1.GroupName + "/v1beta1/gatewayclasses",
reflect.TypeOf(gatewayApiV1Beta1.GatewayClass{}): "/apis/" + gatewayApiV1.GroupName + "/v1beta1/gatewayclasses/{name}",
reflect.TypeOf(gatewayApiV1Beta1.HTTPRouteList{}): "/apis/" + gatewayApiV1.GroupName + "/v1beta1/namespaces/{namespace}/httproutes",
reflect.TypeOf(gatewayApiV1Beta1.HTTPRoute{}): "/apis/" + gatewayApiV1.GroupName + "/v1beta1/namespaces/{namespace}/httproutes/{name}",
}, "gateway-api"),
}
generate(schemas, targetDirectory)
}

func generate(schemas []Schemas, targetDirectory string) {
func generate(schemas []Schema, targetDirectory string) {
for _, schema := range schemas {
swagger := &openapi3.T{
OpenAPI: "3.0.0",
Expand All @@ -95,7 +125,7 @@ func generate(schemas []Schemas, targetDirectory string) {
Components: &openapi3.Components{
Schemas: extractSchemas(schema.Types),
},
Paths: &openapi3.Paths{},
Paths: extractPaths(schema.Paths),
}
json, err := swagger.MarshalJSON()
if err != nil {
Expand Down Expand Up @@ -126,6 +156,7 @@ func generateType(schemas openapi3.Schemas, t reflect.Type) {
}
value := &openapi3.SchemaRef{Value: openapi3.NewObjectSchema()}
schemas[getKey(t)] = value

value.Value.Properties = make(map[string]*openapi3.SchemaRef)
// Gather fields
fields := extractFields(make([]reflect.StructField, 0), t)
Expand Down Expand Up @@ -194,7 +225,10 @@ func openApiKind(t reflect.Type) *openapi3.SchemaRef {
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32:
return &openapi3.SchemaRef{
Value: openapi3.NewIntegerSchema(),
Value: &openapi3.Schema{
Type: &openapi3.Types{openapi3.TypeInteger},
Format: "int32",
},
}
case reflect.Int64, reflect.Uint64:
return &openapi3.SchemaRef{
Expand Down Expand Up @@ -233,6 +267,27 @@ func openApiKind(t reflect.Type) *openapi3.SchemaRef {
}
}

// Create fake paths so that the OpenAPI generator can compute group, version, plural, scope (namespaced/cluster)
func extractPaths(paths map[reflect.Type]string) *openapi3.Paths {
oApiPaths := openapi3.NewPaths()
for t, path := range paths {
pathItem := &openapi3.PathItem{}
pathItem.Get = openapi3.NewOperation()
pathItem.Get.AddResponse(200, openapi3.NewResponse().WithDescription("OK").WithJSONSchemaRef(&openapi3.SchemaRef{
Ref: "#/components/schemas/" + getKey(t),
}))
if strings.Contains(path, "{namespace}") {
pathItem.Get.AddParameter(openapi3.NewPathParameter("namespace"))
}
if strings.Contains(path, "{name}") {
pathItem.Get.AddParameter(openapi3.NewPathParameter("name"))
}
oApiPaths.Set(path, pathItem)

}
return oApiPaths
}

func getKey(t reflect.Type) string {
pkg := ""
for _, segment := range strings.Split(t.PkgPath(), "/") {
Expand Down

0 comments on commit 5be71f6

Please sign in to comment.