From 11ba9083195bed9e97e36ce43e775485634141c6 Mon Sep 17 00:00:00 2001 From: Luc DUZAN Date: Mon, 5 Aug 2024 15:34:28 +0200 Subject: [PATCH] Improve schema Vclusters -> VClusters parse list parameter --- schema/console-default-schema.json | 2 +- schema/console_schema_test.go | 175 ++++++++++++++++++++--------- schema/gateway-default-schema.json | 2 +- schema/gateway_schema_test.go | 111 ++++++++++++++++-- schema/kind.go | 36 ++++-- schema/schema.go | 57 +++++++--- 6 files changed, 294 insertions(+), 89 deletions(-) diff --git a/schema/console-default-schema.json b/schema/console-default-schema.json index d0a809d..f4e0894 100644 --- a/schema/console-default-schema.json +++ b/schema/console-default-schema.json @@ -1 +1 @@ -{"Application":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application","Name":"Application","ParentPathParam":[],"Order":8}}},"ApplicationGroup":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-group","Name":"ApplicationGroup","ParentPathParam":[],"Order":11}}},"ApplicationInstance":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance","Name":"ApplicationInstance","ParentPathParam":[],"Order":9}}},"ApplicationInstancePermission":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance-permission","Name":"ApplicationInstancePermission","ParentPathParam":[],"Order":10}}},"Group":{"Versions":{"2":{"ListPath":"/public/iam/v2/group","Name":"Group","ParentPathParam":[],"Order":1}}},"KafkaCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/kafka-cluster","Name":"KafkaCluster","ParentPathParam":[],"Order":2}}},"KafkaConnectCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/cluster/{cluster}/kafka-connect","Name":"KafkaConnectCluster","ParentPathParam":["cluster"],"Order":3}}},"KsqlDBCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/cluster/{cluster}/ksqldb","Name":"KsqlDBCluster","ParentPathParam":["cluster"],"Order":4}}},"Subject":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/subject","Name":"Subject","ParentPathParam":["cluster"],"Order":6}}},"Topic":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/topic","Name":"Topic","ParentPathParam":["cluster"],"Order":5}}},"TopicPolicy":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/topic-policy","Name":"TopicPolicy","ParentPathParam":[],"Order":7}}},"User":{"Versions":{"2":{"ListPath":"/public/iam/v2/user","Name":"User","ParentPathParam":[],"Order":0}}}} \ No newline at end of file +{"Application":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application","Name":"Application","ParentPathParam":[],"ListQueryParamter":{},"Order":8}}},"ApplicationGroup":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-group","Name":"ApplicationGroup","ParentPathParam":[],"ListQueryParamter":{},"Order":11}}},"ApplicationInstance":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance","Name":"ApplicationInstance","ParentPathParam":[],"ListQueryParamter":{"application":{"FlagName":"application","Required":false,"Type":"string"}},"Order":9}}},"ApplicationInstancePermission":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance-permission","Name":"ApplicationInstancePermission","ParentPathParam":[],"ListQueryParamter":{"filterByApplication":{"FlagName":"application","Required":false,"Type":"string"},"filterByApplicationInstance":{"FlagName":"application-instance","Required":false,"Type":"string"},"filterByGrantedTo":{"FlagName":"granted-to","Required":false,"Type":"string"}},"Order":10}}},"Group":{"Versions":{"2":{"ListPath":"/public/iam/v2/group","Name":"Group","ParentPathParam":[],"ListQueryParamter":{},"Order":1}}},"KafkaCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/kafka-cluster","Name":"KafkaCluster","ParentPathParam":[],"ListQueryParamter":{},"Order":2}}},"KafkaConnectCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/cluster/{cluster}/kafka-connect","Name":"KafkaConnectCluster","ParentPathParam":["cluster"],"ListQueryParamter":{},"Order":3}}},"KsqlDBCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/cluster/{cluster}/ksqldb","Name":"KsqlDBCluster","ParentPathParam":["cluster"],"ListQueryParamter":{},"Order":4}}},"Subject":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/subject","Name":"Subject","ParentPathParam":["cluster"],"ListQueryParamter":{},"Order":6}}},"Topic":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/topic","Name":"Topic","ParentPathParam":["cluster"],"ListQueryParamter":{},"Order":5}}},"TopicPolicy":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/topic-policy","Name":"TopicPolicy","ParentPathParam":[],"ListQueryParamter":{"app-instance":{"FlagName":"application-instance","Required":false,"Type":"string"}},"Order":7}}},"User":{"Versions":{"2":{"ListPath":"/public/iam/v2/user","Name":"User","ParentPathParam":[],"ListQueryParamter":{},"Order":0}}}} \ No newline at end of file diff --git a/schema/console_schema_test.go b/schema/console_schema_test.go index 34224ea..d7f9d29 100644 --- a/schema/console_schema_test.go +++ b/schema/console_schema_test.go @@ -30,10 +30,11 @@ func TestGetKindWithYamlFromOldConsolePlusWithoutOrder(t *testing.T) { "Application": { Versions: map[int]KindVersion{ 1: &ConsoleKindVersion{ - Name: "Application", - ListPath: "/public/self-serve/v1/application", - ParentPathParam: make([]string, 0), - Order: DefaultPriority, + Name: "Application", + ListPath: "/public/self-serve/v1/application", + ParentPathParam: make([]string, 0), + ListQueryParamter: map[string]QueryParameterOption{}, + Order: DefaultPriority, }, }, }, @@ -43,7 +44,14 @@ func TestGetKindWithYamlFromOldConsolePlusWithoutOrder(t *testing.T) { Name: "ApplicationInstance", ListPath: "/public/self-serve/v1/application-instance", ParentPathParam: make([]string, 0), - Order: DefaultPriority, + ListQueryParamter: map[string]QueryParameterOption{ + "application": { + FlagName: "application", + Required: false, + Type: "string", + }, + }, + Order: DefaultPriority, }, }, }, @@ -53,7 +61,24 @@ func TestGetKindWithYamlFromOldConsolePlusWithoutOrder(t *testing.T) { Name: "ApplicationInstancePermission", ListPath: "/public/self-serve/v1/application-instance-permission", ParentPathParam: make([]string, 0), - Order: DefaultPriority, + ListQueryParamter: map[string]QueryParameterOption{ + "filterByApplication": { + FlagName: "application", + Required: false, + Type: "string", + }, + "filterByApplicationInstance": { + FlagName: "application-instance", + Required: false, + Type: "string", + }, + "filterByGrantedTo": { + FlagName: "granted-to", + Required: false, + Type: "string", + }, + }, + Order: DefaultPriority, }, }, }, @@ -63,17 +88,25 @@ func TestGetKindWithYamlFromOldConsolePlusWithoutOrder(t *testing.T) { Name: "TopicPolicy", ListPath: "/public/self-serve/v1/topic-policy", ParentPathParam: make([]string, 0), - Order: DefaultPriority, + ListQueryParamter: map[string]QueryParameterOption{ + "app-instance": { + FlagName: "application-instance", + Required: false, + Type: "string", + }, + }, + Order: DefaultPriority, }, }, }, "Topic": { Versions: map[int]KindVersion{ 2: &ConsoleKindVersion{ - Name: "Topic", - ListPath: "/public/kafka/v2/cluster/{cluster}/topic", - ParentPathParam: []string{"cluster"}, - Order: DefaultPriority, + Name: "Topic", + ListPath: "/public/kafka/v2/cluster/{cluster}/topic", + ParentPathParam: []string{"cluster"}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: DefaultPriority, }, }, }, @@ -105,10 +138,11 @@ func TestGetKindWithYamlFromConsolePlus(t *testing.T) { "Application": { Versions: map[int]KindVersion{ 1: &ConsoleKindVersion{ - Name: "Application", - ListPath: "/public/self-serve/v1/application", - ParentPathParam: []string{}, - Order: 6, + Name: "Application", + ListPath: "/public/self-serve/v1/application", + ParentPathParam: []string{}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: 6, }, }, }, @@ -118,7 +152,14 @@ func TestGetKindWithYamlFromConsolePlus(t *testing.T) { Name: "ApplicationInstance", ListPath: "/public/self-serve/v1/application-instance", ParentPathParam: []string{}, - Order: 7, + ListQueryParamter: map[string]QueryParameterOption{ + "application": { + FlagName: "application", + Required: false, + Type: "string", + }, + }, + Order: 7, }, }, }, @@ -128,17 +169,35 @@ func TestGetKindWithYamlFromConsolePlus(t *testing.T) { Name: "ApplicationInstancePermission", ListPath: "/public/self-serve/v1/application-instance-permission", ParentPathParam: []string{}, - Order: 8, + ListQueryParamter: map[string]QueryParameterOption{ + "filterByApplication": { + FlagName: "application", + Required: false, + Type: "string", + }, + "filterByApplicationInstance": { + FlagName: "application-instance", + Required: false, + Type: "string", + }, + "filterByGrantedTo": { + FlagName: "granted-to", + Required: false, + Type: "string", + }, + }, + Order: 8, }, }, }, "ApplicationGroup": { Versions: map[int]KindVersion{ 1: &ConsoleKindVersion{ - Name: "ApplicationGroup", - ListPath: "/public/self-serve/v1/application-group", - ParentPathParam: []string{}, - Order: 9, + Name: "ApplicationGroup", + ListPath: "/public/self-serve/v1/application-group", + ParentPathParam: []string{}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: 9, }, }, }, @@ -148,63 +207,75 @@ func TestGetKindWithYamlFromConsolePlus(t *testing.T) { Name: "TopicPolicy", ListPath: "/public/self-serve/v1/topic-policy", ParentPathParam: []string{}, - Order: 5, + ListQueryParamter: map[string]QueryParameterOption{ + "app-instance": { + FlagName: "application-instance", + Required: false, + Type: "string", + }, + }, + Order: 5, }, }, }, "Topic": { Versions: map[int]KindVersion{ 2: &ConsoleKindVersion{ - Name: "Topic", - ListPath: "/public/kafka/v2/cluster/{cluster}/topic", - ParentPathParam: []string{"cluster"}, - Order: 3, + Name: "Topic", + ListPath: "/public/kafka/v2/cluster/{cluster}/topic", + ParentPathParam: []string{"cluster"}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: 3, }, }, }, "Subject": { Versions: map[int]KindVersion{ 2: &ConsoleKindVersion{ - Name: "Subject", - ListPath: "/public/kafka/v2/cluster/{cluster}/subject", - ParentPathParam: []string{"cluster"}, - Order: 4, + Name: "Subject", + ListPath: "/public/kafka/v2/cluster/{cluster}/subject", + ParentPathParam: []string{"cluster"}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: 4, }, }, }, "User": { Versions: map[int]KindVersion{ 2: &ConsoleKindVersion{ - Name: "User", - ListPath: "/public/iam/v2/user", - ParentPathParam: []string{}, - Order: 0, + Name: "User", + ListPath: "/public/iam/v2/user", + ParentPathParam: []string{}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: 0, }, }, }, "Group": { Versions: map[int]KindVersion{ 2: &ConsoleKindVersion{ - Name: "Group", - ListPath: "/public/iam/v2/group", - ParentPathParam: []string{}, - Order: 1, + Name: "Group", + ListPath: "/public/iam/v2/group", + ParentPathParam: []string{}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: 1, }, }, }, "KafkaCluster": { Versions: map[int]KindVersion{ 2: &ConsoleKindVersion{ - Name: "KafkaCluster", - ListPath: "/public/console/v2/kafka-cluster", - ParentPathParam: []string{}, - Order: 2, + Name: "KafkaCluster", + ListPath: "/public/console/v2/kafka-cluster", + ParentPathParam: []string{}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: 2, }, }, }, } if !reflect.DeepEqual(kinds, expected) { - t.Error(spew.Printf("got kinds %v, want %v", kinds["Subject"], expected["Subject"])) + t.Error(spew.Printf("got kinds %v, want %v", kinds, expected)) } }) } @@ -230,16 +301,18 @@ func TestGetKindWithMultipleVersion(t *testing.T) { "Topic": { Versions: map[int]KindVersion{ 1: &ConsoleKindVersion{ - Name: "Topic", - ListPath: "/public/v1/cluster/{cluster}/topic", - ParentPathParam: []string{"cluster"}, - Order: DefaultPriority, + Name: "Topic", + ListPath: "/public/v1/cluster/{cluster}/topic", + ParentPathParam: []string{"cluster"}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: DefaultPriority, }, 2: &ConsoleKindVersion{ - Name: "Topic", - ListPath: "/public/v2/cluster/{cluster}/sa/{sa}/topic", - ParentPathParam: []string{"cluster", "sa"}, - Order: 42, + Name: "Topic", + ListPath: "/public/v2/cluster/{cluster}/sa/{sa}/topic", + ParentPathParam: []string{"cluster", "sa"}, + ListQueryParamter: map[string]QueryParameterOption{}, + Order: 42, }, }, }, diff --git a/schema/gateway-default-schema.json b/schema/gateway-default-schema.json index f5f55c7..6a86dac 100644 --- a/schema/gateway-default-schema.json +++ b/schema/gateway-default-schema.json @@ -1 +1 @@ -{"VClusters":{"Versions":{"2":{"ListPath":"/gateway/v2/vclusters","Name":"VClusters","ParentPathParam":[],"Order":7}}},"AliasTopics":{"Versions":{"2":{"ListPath":"/gateway/v2/alias-topics","Name":"AliasTopics","ParentPathParam":[],"Order":8}}},"ConcentrationRules":{"Versions":{"2":{"ListPath":"/gateway/v2/concentration-rules","Name":"ConcentrationRules","ParentPathParam":[],"Order":9}}},"GatewayGroups":{"Versions":{"2":{"ListPath":"/gateway/v2/gateway-groups","Name":"GatewayGroups","ParentPathParam":[],"Order":10}}},"ServiceAccounts":{"Versions":{"2":{"ListPath":"/gateway/v2/service-accounts","Name":"ServiceAccounts","ParentPathParam":[],"Order":11}}},"Interceptors":{"Versions":{"2":{"ListPath":"/gateway/v2/interceptors","Name":"Interceptors","ParentPathParam":[],"Order":12}}}} \ No newline at end of file +{"AliasTopics":{"Versions":{"2":{"ListPath":"/gateway/v2/alias-topics","Name":"AliasTopics","ParentPathParam":[],"ListQueryParameter":{"name":{"FlagName":"name","Required":false,"Type":"string"},"showDefaults":{"FlagName":"show-defaults","Required":false,"Type":"boolean"},"vcluster":{"FlagName":"vcluster","Required":false,"Type":"string"}},"Order":8}}},"ConcentrationRules":{"Versions":{"2":{"ListPath":"/gateway/v2/concentration-rules","Name":"ConcentrationRules","ParentPathParam":[],"ListQueryParameter":{"name":{"FlagName":"name","Required":false,"Type":"string"},"showDefaults":{"FlagName":"show-defaults","Required":false,"Type":"boolean"},"vcluster":{"FlagName":"vcluster","Required":false,"Type":"string"}},"Order":9}}},"GatewayGroups":{"Versions":{"2":{"ListPath":"/gateway/v2/gateway-groups","Name":"GatewayGroups","ParentPathParam":[],"ListQueryParameter":{"showDefaults":{"FlagName":"show-defaults","Required":false,"Type":"boolean"}},"Order":10}}},"Interceptors":{"Versions":{"2":{"ListPath":"/gateway/v2/interceptors","Name":"Interceptors","ParentPathParam":[],"ListQueryParameter":{"global":{"FlagName":"global","Required":false,"Type":"boolean"},"group":{"FlagName":"group","Required":false,"Type":"string"},"name":{"FlagName":"name","Required":false,"Type":"string"},"username":{"FlagName":"username","Required":false,"Type":"string"},"vcluster":{"FlagName":"vcluster","Required":false,"Type":"string"}},"Order":12}}},"ServiceAccounts":{"Versions":{"2":{"ListPath":"/gateway/v2/service-accounts","Name":"ServiceAccounts","ParentPathParam":[],"ListQueryParameter":{"name":{"FlagName":"name","Required":false,"Type":"string"},"showDefaults":{"FlagName":"show-defaults","Required":false,"Type":"boolean"},"type":{"FlagName":"type","Required":false,"Type":"string"},"vcluster":{"FlagName":"vcluster","Required":false,"Type":"string"}},"Order":11}}},"VClusters":{"Versions":{"2":{"ListPath":"/gateway/v2/vclusters","Name":"VClusters","ParentPathParam":[],"ListQueryParameter":{},"Order":7}}}} \ No newline at end of file diff --git a/schema/gateway_schema_test.go b/schema/gateway_schema_test.go index 7ccb668..761ca5e 100644 --- a/schema/gateway_schema_test.go +++ b/schema/gateway_schema_test.go @@ -26,13 +26,14 @@ func TestGetKindWithYamlFromGateway(t *testing.T) { } expected := KindCatalog{ - "Vclusters": { + "VClusters": { Versions: map[int]KindVersion{ 2: &GatewayKindVersion{ - Name: "Vclusters", - ListPath: "/gateway/v2/vclusters", - ParentPathParam: []string{}, - Order: 7, + Name: "VClusters", + ListPath: "/gateway/v2/vclusters", + ParentPathParam: []string{}, + ListQueryParameter: map[string]QueryParameterOption{}, + Order: 7, }, }, }, @@ -42,7 +43,24 @@ func TestGetKindWithYamlFromGateway(t *testing.T) { Name: "AliasTopics", ListPath: "/gateway/v2/alias-topics", ParentPathParam: []string{}, - Order: 8, + ListQueryParameter: map[string]QueryParameterOption{ + "name": { + FlagName: "name", + Required: false, + Type: "string", + }, + "vcluster": { + FlagName: "vcluster", + Required: false, + Type: "string", + }, + "showDefaults": { + FlagName: "show-defaults", + Required: false, + Type: "boolean", + }, + }, + Order: 8, }, }, }, @@ -52,7 +70,24 @@ func TestGetKindWithYamlFromGateway(t *testing.T) { Name: "ConcentrationRules", ListPath: "/gateway/v2/concentration-rules", ParentPathParam: []string{}, - Order: 9, + ListQueryParameter: map[string]QueryParameterOption{ + "vcluster": { + FlagName: "vcluster", + Required: false, + Type: "string", + }, + "name": { + FlagName: "name", + Required: false, + Type: "string", + }, + "showDefaults": { + FlagName: "show-defaults", + Required: false, + Type: "boolean", + }, + }, + Order: 9, }, }, }, @@ -62,7 +97,14 @@ func TestGetKindWithYamlFromGateway(t *testing.T) { Name: "GatewayGroups", ListPath: "/gateway/v2/gateway-groups", ParentPathParam: []string{}, - Order: 10, + ListQueryParameter: map[string]QueryParameterOption{ + "showDefaults": { + FlagName: "show-defaults", + Required: false, + Type: "boolean", + }, + }, + Order: 10, }, }, }, @@ -72,7 +114,29 @@ func TestGetKindWithYamlFromGateway(t *testing.T) { Name: "ServiceAccounts", ListPath: "/gateway/v2/service-accounts", ParentPathParam: []string{}, - Order: 11, + ListQueryParameter: map[string]QueryParameterOption{ + "name": { + FlagName: "name", + Required: false, + Type: "string", + }, + "type": { + FlagName: "type", + Required: false, + Type: "string", + }, + "vcluster": { + FlagName: "vcluster", + Required: false, + Type: "string", + }, + "showDefaults": { + FlagName: "show-defaults", + Required: false, + Type: "boolean", + }, + }, + Order: 11, }, }, }, @@ -82,7 +146,34 @@ func TestGetKindWithYamlFromGateway(t *testing.T) { Name: "Interceptors", ListPath: "/gateway/v2/interceptors", ParentPathParam: []string{}, - Order: 12, + ListQueryParameter: map[string]QueryParameterOption{ + "username": { + FlagName: "username", + Required: false, + Type: "string", + }, + "name": { + FlagName: "name", + Required: false, + Type: "string", + }, + "global": { + FlagName: "global", + Required: false, + Type: "boolean", + }, + "vcluster": { + FlagName: "vcluster", + Required: false, + Type: "string", + }, + "group": { + FlagName: "group", + Required: false, + Type: "string", + }, + }, + Order: 12, }, }, }, diff --git a/schema/kind.go b/schema/kind.go index f2c080d..610a1e3 100644 --- a/schema/kind.go +++ b/schema/kind.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/conduktor/ctl/resource" + "github.com/conduktor/ctl/utils" ) type KindVersion interface { @@ -19,11 +20,24 @@ type KindVersion interface { GetOrder() int } +// two logics: uniformize flag name and kebab case +func ComputeFlagName(name string) string { + kebab := utils.UpperCamelToKebab(name) + kebab = strings.TrimPrefix(kebab, "filter-by-") + return strings.Replace(kebab, "app-instance", "application-instance", 1) +} + +type QueryParameterOption struct { + FlagName string + Required bool + Type string +} type ConsoleKindVersion struct { - ListPath string - Name string - ParentPathParam []string - Order int `json:1000` //same value DefaultPriority + ListPath string + Name string + ParentPathParam []string + ListQueryParamter map[string]QueryParameterOption + Order int `json:1000` //same value DefaultPriority } func (c *ConsoleKindVersion) GetListPath() string { @@ -42,11 +56,17 @@ func (c *ConsoleKindVersion) GetOrder() int { return c.Order } +type GetParameter struct { + Name string + Mandatory bool +} + type GatewayKindVersion struct { - ListPath string - Name string - ParentPathParam []string - Order int `json:1000` //same value DefaultPriority + ListPath string + Name string + ParentPathParam []string + ListQueryParameter map[string]QueryParameterOption + Order int `json:1000` //same value DefaultPriority } func (c *GatewayKindVersion) GetListPath() string { diff --git a/schema/schema.go b/schema/schema.go index 1d4de81..4f6a7a3 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -31,18 +31,19 @@ func New(schema []byte) (*Schema, error) { }, nil } -func getKinds[T KindVersion](s *Schema, strict bool, buildKindVersion func(path, kind string, order int, put *v3high.Operation, strict bool) (T, error)) (map[string]Kind, error) { +func getKinds[T KindVersion](s *Schema, strict bool, buildKindVersion func(path, kind string, order int, put *v3high.Operation, get *v3high.Operation, strict bool) (T, error)) (map[string]Kind, error) { result := make(map[string]Kind, 0) for path := s.doc.Model.Paths.PathItems.First(); path != nil; path = path.Next() { put := path.Value().Put - if put != nil { + get := path.Value().Get + if put != nil && get != nil { cliTag := findCliTag(path.Value().Put.Tags) if cliTag != "" { tagParsed, err := parseTag(cliTag) if err != nil { return nil, err } - newKind, err := buildKindVersion(path.Key(), tagParsed.kind, tagParsed.order, put, strict) + newKind, err := buildKindVersion(path.Key(), tagParsed.kind, tagParsed.order, put, get, strict) if err != nil { return nil, err } @@ -69,19 +70,34 @@ func (s *Schema) GetGatewayKinds(strict bool) (map[string]Kind, error) { return getKinds(s, strict, buildGatewayKindVersion) } -func buildConsoleKindVersion(path, kind string, order int, put *v3high.Operation, strict bool) (*ConsoleKindVersion, error) { +func buildConsoleKindVersion(path, kind string, order int, put *v3high.Operation, get *v3high.Operation, strict bool) (*ConsoleKindVersion, error) { newKind := &ConsoleKindVersion{ - Name: kind, - ListPath: path, - ParentPathParam: make([]string, 0, len(put.Parameters)), - Order: order, + Name: kind, + ListPath: path, + ParentPathParam: make([]string, 0, len(put.Parameters)), + ListQueryParamter: make(map[string]QueryParameterOption, len(get.Parameters)), + Order: order, } - for _, parameter := range put.Parameters { - if parameter.In == "path" && *parameter.Required { - newKind.ParentPathParam = append(newKind.ParentPathParam, parameter.Name) + for _, putParameter := range put.Parameters { + if putParameter.In == "path" && *putParameter.Required { + newKind.ParentPathParam = append(newKind.ParentPathParam, putParameter.Name) } } + for _, getParameter := range get.Parameters { + if getParameter.In == "query" { + schemaTypes := getParameter.Schema.Schema().Type + if len(schemaTypes) == 1 { + schemaType := schemaTypes[0] + name := getParameter.Name + newKind.ListQueryParamter[name] = QueryParameterOption{ + FlagName: ComputeFlagName(name), + Required: *getParameter.Required, + Type: schemaType, + } + } + } + } if strict { err := checkThatPathParamAreInSpec(newKind, put.RequestBody) if err != nil { @@ -96,17 +112,18 @@ func buildConsoleKindVersion(path, kind string, order int, put *v3high.Operation return newKind, nil } -func buildGatewayKindVersion(path, kind string, order int, put *v3high.Operation, strict bool) (*GatewayKindVersion, error) { +func buildGatewayKindVersion(path, kind string, order int, put *v3high.Operation, get *v3high.Operation, strict bool) (*GatewayKindVersion, error) { //for the moment there is the same but this might evolve latter - consokeKind, err := buildConsoleKindVersion(path, kind, order, put, strict) + consokeKind, err := buildConsoleKindVersion(path, kind, order, put, get, strict) if err != nil { return nil, err } return &GatewayKindVersion{ - Name: consokeKind.Name, - ListPath: consokeKind.ListPath, - ParentPathParam: consokeKind.ParentPathParam, - Order: consokeKind.Order, + Name: consokeKind.Name, + ListPath: consokeKind.ListPath, + ParentPathParam: consokeKind.ParentPathParam, + ListQueryParameter: consokeKind.ListQueryParamter, + Order: consokeKind.Order, }, nil } @@ -143,7 +160,11 @@ func parseTag(tag string) (tagParseResult, error) { return tagParseResult{}, fmt.Errorf("Invalid order number in tag: %s", orderStr) } - return tagParseResult{kind: utils.KebabToUpperCamel(kind), version: version, order: order}, nil + finalKind := utils.KebabToUpperCamel(kind) + if finalKind == "Vclusters" { + finalKind = "VClusters" + } + return tagParseResult{kind: finalKind, version: version, order: order}, nil } func checkThatPathParamAreInSpec(kind *ConsoleKindVersion, requestBody *v3high.RequestBody) error {