From a0384dd483d95391e59ea2171ff8c76ac4fb6c69 Mon Sep 17 00:00:00 2001 From: Maria Ntalla Date: Tue, 17 Dec 2019 13:56:31 +0000 Subject: [PATCH] Add routes for structType and mapType in integration tests --- test/integration/builder/main.go | 4 + .../pkg/generated/openapi_generated.go | 170 +++++++++++++++--- test/integration/testdata/golden.v2.json | 140 +++++++++++++++ 3 files changed, 285 insertions(+), 29 deletions(-) diff --git a/test/integration/builder/main.go b/test/integration/builder/main.go index 355c88590..7c531ff9a 100644 --- a/test/integration/builder/main.go +++ b/test/integration/builder/main.go @@ -115,6 +115,10 @@ func createWebServices() []*restful.WebService { w.Route(buildRouteForType(w, "custom", "Bak")) w.Route(buildRouteForType(w, "custom", "Bac")) w.Route(buildRouteForType(w, "custom", "Bah")) + w.Route(buildRouteForType(w, "maptype", "GranularMap")) + w.Route(buildRouteForType(w, "maptype", "AtomicMap")) + w.Route(buildRouteForType(w, "structtype", "GranularStruct")) + w.Route(buildRouteForType(w, "structtype", "AtomicStruct")) return []*restful.WebService{w} } diff --git a/test/integration/pkg/generated/openapi_generated.go b/test/integration/pkg/generated/openapi_generated.go index b59894f9b..65370068c 100644 --- a/test/integration/pkg/generated/openapi_generated.go +++ b/test/integration/pkg/generated/openapi_generated.go @@ -25,42 +25,30 @@ package generated import ( spec "github.com/go-openapi/spec" common "k8s.io/kube-openapi/pkg/common" - custom "k8s.io/kube-openapi/test/integration/testdata/custom" ) func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { return map[string]common.OpenAPIDefinition{ - "k8s.io/kube-openapi/test/integration/testdata/custom.Bac": common.EmbedOpenAPIDefinitionIntoV2Extension(custom.Bac{}.OpenAPIV3Definition(), custom.Bac{}.OpenAPIDefinition()), - "k8s.io/kube-openapi/test/integration/testdata/custom.Bah": schema_test_integration_testdata_custom_Bah(ref), - "k8s.io/kube-openapi/test/integration/testdata/custom.Bak": custom.Bak{}.OpenAPIDefinition(), - "k8s.io/kube-openapi/test/integration/testdata/custom.Bal": custom.Bal{}.OpenAPIV3Definition(), - "k8s.io/kube-openapi/test/integration/testdata/dummytype.Bar": schema_test_integration_testdata_dummytype_Bar(ref), - "k8s.io/kube-openapi/test/integration/testdata/dummytype.Baz": schema_test_integration_testdata_dummytype_Baz(ref), - "k8s.io/kube-openapi/test/integration/testdata/dummytype.Foo": schema_test_integration_testdata_dummytype_Foo(ref), - "k8s.io/kube-openapi/test/integration/testdata/dummytype.Waldo": schema_test_integration_testdata_dummytype_Waldo(ref), - "k8s.io/kube-openapi/test/integration/testdata/listtype.AtomicList": schema_test_integration_testdata_listtype_AtomicList(ref), - "k8s.io/kube-openapi/test/integration/testdata/listtype.Item": schema_test_integration_testdata_listtype_Item(ref), - "k8s.io/kube-openapi/test/integration/testdata/listtype.MapList": schema_test_integration_testdata_listtype_MapList(ref), - "k8s.io/kube-openapi/test/integration/testdata/listtype.SetList": schema_test_integration_testdata_listtype_SetList(ref), - "k8s.io/kube-openapi/test/integration/testdata/listtype.UntypedList": schema_test_integration_testdata_listtype_UntypedList(ref), - "k8s.io/kube-openapi/test/integration/testdata/uniontype.InlinedUnion": schema_test_integration_testdata_uniontype_InlinedUnion(ref), - "k8s.io/kube-openapi/test/integration/testdata/uniontype.TopLevelUnion": schema_test_integration_testdata_uniontype_TopLevelUnion(ref), - "k8s.io/kube-openapi/test/integration/testdata/uniontype.Union": schema_test_integration_testdata_uniontype_Union(ref), - "k8s.io/kube-openapi/test/integration/testdata/uniontype.Union2": schema_test_integration_testdata_uniontype_Union2(ref), + "k8s.io/kube-openapi/test/integration/testdata/dummytype.Bar": schema_test_integration_testdata_dummytype_Bar(ref), + "k8s.io/kube-openapi/test/integration/testdata/dummytype.Baz": schema_test_integration_testdata_dummytype_Baz(ref), + "k8s.io/kube-openapi/test/integration/testdata/dummytype.Foo": schema_test_integration_testdata_dummytype_Foo(ref), + "k8s.io/kube-openapi/test/integration/testdata/dummytype.Waldo": schema_test_integration_testdata_dummytype_Waldo(ref), + "k8s.io/kube-openapi/test/integration/testdata/listtype.AtomicList": schema_test_integration_testdata_listtype_AtomicList(ref), + "k8s.io/kube-openapi/test/integration/testdata/listtype.Item": schema_test_integration_testdata_listtype_Item(ref), + "k8s.io/kube-openapi/test/integration/testdata/listtype.MapList": schema_test_integration_testdata_listtype_MapList(ref), + "k8s.io/kube-openapi/test/integration/testdata/listtype.SetList": schema_test_integration_testdata_listtype_SetList(ref), + "k8s.io/kube-openapi/test/integration/testdata/listtype.UntypedList": schema_test_integration_testdata_listtype_UntypedList(ref), + "k8s.io/kube-openapi/test/integration/testdata/maptype.AtomicMap": schema_test_integration_testdata_maptype_AtomicMap(ref), + "k8s.io/kube-openapi/test/integration/testdata/maptype.GranularMap": schema_test_integration_testdata_maptype_GranularMap(ref), + "k8s.io/kube-openapi/test/integration/testdata/structtype.AtomicStruct": schema_test_integration_testdata_structtype_AtomicStruct(ref), + "k8s.io/kube-openapi/test/integration/testdata/structtype.GranularStruct": schema_test_integration_testdata_structtype_GranularStruct(ref), + "k8s.io/kube-openapi/test/integration/testdata/uniontype.InlinedUnion": schema_test_integration_testdata_uniontype_InlinedUnion(ref), + "k8s.io/kube-openapi/test/integration/testdata/uniontype.TopLevelUnion": schema_test_integration_testdata_uniontype_TopLevelUnion(ref), + "k8s.io/kube-openapi/test/integration/testdata/uniontype.Union": schema_test_integration_testdata_uniontype_Union(ref), + "k8s.io/kube-openapi/test/integration/testdata/uniontype.Union2": schema_test_integration_testdata_uniontype_Union2(ref), } } -func schema_test_integration_testdata_custom_Bah(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.EmbedOpenAPIDefinitionIntoV2Extension(custom.Bah{}.OpenAPIV3Definition(), common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: custom.Bah{}.OpenAPISchemaType(), - Format: custom.Bah{}.OpenAPISchemaFormat(), - }, - }, - }) -} - func schema_test_integration_testdata_dummytype_Bar(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -325,6 +313,130 @@ func schema_test_integration_testdata_listtype_UntypedList(ref common.ReferenceC } } +func schema_test_integration_testdata_maptype_AtomicMap(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "KeyValue": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-map-type": "atomic", + }, + }, + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + Required: []string{"KeyValue"}, + }, + }, + } +} + +func schema_test_integration_testdata_maptype_GranularMap(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "KeyValue": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-map-type": "granular", + }, + }, + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + Required: []string{"KeyValue"}, + }, + }, + } +} + +func schema_test_integration_testdata_structtype_AtomicStruct(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "Field": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-map-type": "atomic", + }, + }, + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "OtherField": { + SchemaProps: spec.SchemaProps{ + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + Required: []string{"Field", "OtherField"}, + }, + }, + } +} + +func schema_test_integration_testdata_structtype_GranularStruct(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "Field": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-map-type": "granular", + }, + }, + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + "OtherField": { + SchemaProps: spec.SchemaProps{ + Type: []string{"integer"}, + Format: "int32", + }, + }, + }, + Required: []string{"Field", "OtherField"}, + }, + }, + } +} + func schema_test_integration_testdata_uniontype_InlinedUnion(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/test/integration/testdata/golden.v2.json b/test/integration/testdata/golden.v2.json index c541c6f97..6e7f94d36 100644 --- a/test/integration/testdata/golden.v2.json +++ b/test/integration/testdata/golden.v2.json @@ -214,6 +214,82 @@ } } }, + "/test/maptype/atomicmap": { + "get": { + "schemes": [ + "https" + ], + "operationId": "func15", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/maptype.AtomicMap" + } + }, + "404": { + "$ref": "#/responses/NotFound" + } + } + } + }, + "/test/maptype/granularmap": { + "get": { + "schemes": [ + "https" + ], + "operationId": "func14", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/maptype.GranularMap" + } + }, + "404": { + "$ref": "#/responses/NotFound" + } + } + } + }, + "/test/structtype/atomicstruct": { + "get": { + "schemes": [ + "https" + ], + "operationId": "func17", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structtype.AtomicStruct" + } + }, + "404": { + "$ref": "#/responses/NotFound" + } + } + } + }, + "/test/structtype/granularstruct": { + "get": { + "schemes": [ + "https" + ], + "operationId": "func16", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/structtype.GranularStruct" + } + }, + "404": { + "$ref": "#/responses/NotFound" + } + } + } + }, "/test/uniontype/inlinedunion": { "get": { "schemes": [ @@ -403,6 +479,70 @@ } } }, + "maptype.AtomicMap": { + "type": "object", + "required": [ + "KeyValue" + ], + "properties": { + "KeyValue": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "x-kubernetes-map-type": "atomic" + } + } + }, + "maptype.GranularMap": { + "type": "object", + "required": [ + "KeyValue" + ], + "properties": { + "KeyValue": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "x-kubernetes-map-type": "granular" + } + } + }, + "structtype.AtomicStruct": { + "type": "object", + "required": [ + "Field", + "OtherField" + ], + "properties": { + "Field": { + "type": "string", + "x-kubernetes-map-type": "atomic" + }, + "OtherField": { + "type": "integer", + "format": "int32" + } + } + }, + "structtype.GranularStruct": { + "type": "object", + "required": [ + "Field", + "OtherField" + ], + "properties": { + "Field": { + "type": "string", + "x-kubernetes-map-type": "granular" + }, + "OtherField": { + "type": "integer", + "format": "int32" + } + } + }, "uniontype.InlinedUnion": { "type": "object", "required": [