mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Revert "Merge pull request #71137 from sttts/sttts-crd-openapi-spec-recursive-v2-prune"
This reverts commit3ea3cfc3be
, reversing changes made tofab7009997
.
This commit is contained in:
parent
3ea3cfc3be
commit
ad2b916d7c
@ -36,6 +36,7 @@ import (
|
|||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
|
|
||||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
||||||
|
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||||
informers "k8s.io/apiextensions-apiserver/pkg/client/informers/internalversion/apiextensions/internalversion"
|
informers "k8s.io/apiextensions-apiserver/pkg/client/informers/internalversion/apiextensions/internalversion"
|
||||||
listers "k8s.io/apiextensions-apiserver/pkg/client/listers/apiextensions/internalversion"
|
listers "k8s.io/apiextensions-apiserver/pkg/client/listers/apiextensions/internalversion"
|
||||||
apiextensionsfeatures "k8s.io/apiextensions-apiserver/pkg/features"
|
apiextensionsfeatures "k8s.io/apiextensions-apiserver/pkg/features"
|
||||||
@ -130,10 +131,18 @@ func (c *DiscoveryController) sync(version schema.GroupVersion) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Convert internal CustomResourceValidation to versioned CustomResourceValidation
|
||||||
|
versionedSchema := new(v1beta1.CustomResourceValidation)
|
||||||
|
if validationSchema == nil {
|
||||||
|
versionedSchema = nil
|
||||||
|
} else {
|
||||||
|
if err := v1beta1.Convert_apiextensions_CustomResourceValidation_To_v1beta1_CustomResourceValidation(validationSchema, versionedSchema, nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
// We aggregate the schema even if it's nil as it maybe a removal of the schema for this CRD,
|
// We aggregate the schema even if it's nil as it maybe a removal of the schema for this CRD,
|
||||||
// and the aggreated OpenAPI spec should reflect this change.
|
// and the aggreated OpenAPI spec should reflect this change.
|
||||||
crdspec, etag, err := apiextensionsopenapi.CustomResourceDefinitionOpenAPISpec(&crd.Spec, version.Version, validationSchema)
|
crdspec, etag, err := apiextensionsopenapi.CustomResourceDefinitionOpenAPISpec(&crd.Spec, version.Version, versionedSchema)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -50,17 +50,8 @@ func ValidateCustomResource(customResource interface{}, validator *validate.Sche
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvertJSONSchemaProps converts the schema from apiextensions.JSONSchemaPropos to go-openapi/spec.Schema.
|
// ConvertJSONSchemaProps converts the schema from apiextensions.JSONSchemaPropos to go-openapi/spec.Schema
|
||||||
func ConvertJSONSchemaProps(in *apiextensions.JSONSchemaProps, out *spec.Schema) error {
|
func ConvertJSONSchemaProps(in *apiextensions.JSONSchemaProps, out *spec.Schema) error {
|
||||||
return ConvertJSONSchemaPropsWithPostProcess(in, out, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PostProcessFunc post-processes one node of a spec.Schema.
|
|
||||||
type PostProcessFunc func(*spec.Schema) error
|
|
||||||
|
|
||||||
// ConvertJSONSchemaPropsWithPostProcess converts the schema from apiextensions.JSONSchemaPropos to go-openapi/spec.Schema
|
|
||||||
// and run a post process step on each JSONSchemaProps node.
|
|
||||||
func ConvertJSONSchemaPropsWithPostProcess(in *apiextensions.JSONSchemaProps, out *spec.Schema, postProcess PostProcessFunc) error {
|
|
||||||
if in == nil {
|
if in == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -95,43 +86,41 @@ func ConvertJSONSchemaPropsWithPostProcess(in *apiextensions.JSONSchemaProps, ou
|
|||||||
out.Example = *(in.Example)
|
out.Example = *(in.Example)
|
||||||
}
|
}
|
||||||
|
|
||||||
if in.Enum != nil {
|
out.Enum = make([]interface{}, len(in.Enum))
|
||||||
out.Enum = make([]interface{}, len(in.Enum))
|
for k, v := range in.Enum {
|
||||||
for k, v := range in.Enum {
|
out.Enum[k] = v
|
||||||
out.Enum[k] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := convertSliceOfJSONSchemaProps(&in.AllOf, &out.AllOf, postProcess); err != nil {
|
if err := convertSliceOfJSONSchemaProps(&in.AllOf, &out.AllOf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := convertSliceOfJSONSchemaProps(&in.OneOf, &out.OneOf, postProcess); err != nil {
|
if err := convertSliceOfJSONSchemaProps(&in.OneOf, &out.OneOf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := convertSliceOfJSONSchemaProps(&in.AnyOf, &out.AnyOf, postProcess); err != nil {
|
if err := convertSliceOfJSONSchemaProps(&in.AnyOf, &out.AnyOf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if in.Not != nil {
|
if in.Not != nil {
|
||||||
in, out := &in.Not, &out.Not
|
in, out := &in.Not, &out.Not
|
||||||
*out = new(spec.Schema)
|
*out = new(spec.Schema)
|
||||||
if err := ConvertJSONSchemaPropsWithPostProcess(*in, *out, postProcess); err != nil {
|
if err := ConvertJSONSchemaProps(*in, *out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
out.Properties, err = convertMapOfJSONSchemaProps(in.Properties, postProcess)
|
out.Properties, err = convertMapOfJSONSchemaProps(in.Properties)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
out.PatternProperties, err = convertMapOfJSONSchemaProps(in.PatternProperties, postProcess)
|
out.PatternProperties, err = convertMapOfJSONSchemaProps(in.PatternProperties)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
out.Definitions, err = convertMapOfJSONSchemaProps(in.Definitions, postProcess)
|
out.Definitions, err = convertMapOfJSONSchemaProps(in.Definitions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -146,7 +135,7 @@ func ConvertJSONSchemaPropsWithPostProcess(in *apiextensions.JSONSchemaProps, ou
|
|||||||
if in.AdditionalProperties != nil {
|
if in.AdditionalProperties != nil {
|
||||||
in, out := &in.AdditionalProperties, &out.AdditionalProperties
|
in, out := &in.AdditionalProperties, &out.AdditionalProperties
|
||||||
*out = new(spec.SchemaOrBool)
|
*out = new(spec.SchemaOrBool)
|
||||||
if err := convertJSONSchemaPropsorBool(*in, *out, postProcess); err != nil {
|
if err := convertJSONSchemaPropsorBool(*in, *out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,7 +143,7 @@ func ConvertJSONSchemaPropsWithPostProcess(in *apiextensions.JSONSchemaProps, ou
|
|||||||
if in.AdditionalItems != nil {
|
if in.AdditionalItems != nil {
|
||||||
in, out := &in.AdditionalItems, &out.AdditionalItems
|
in, out := &in.AdditionalItems, &out.AdditionalItems
|
||||||
*out = new(spec.SchemaOrBool)
|
*out = new(spec.SchemaOrBool)
|
||||||
if err := convertJSONSchemaPropsorBool(*in, *out, postProcess); err != nil {
|
if err := convertJSONSchemaPropsorBool(*in, *out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,7 +151,7 @@ func ConvertJSONSchemaPropsWithPostProcess(in *apiextensions.JSONSchemaProps, ou
|
|||||||
if in.Items != nil {
|
if in.Items != nil {
|
||||||
in, out := &in.Items, &out.Items
|
in, out := &in.Items, &out.Items
|
||||||
*out = new(spec.SchemaOrArray)
|
*out = new(spec.SchemaOrArray)
|
||||||
if err := convertJSONSchemaPropsOrArray(*in, *out, postProcess); err != nil {
|
if err := convertJSONSchemaPropsOrArray(*in, *out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +161,7 @@ func ConvertJSONSchemaPropsWithPostProcess(in *apiextensions.JSONSchemaProps, ou
|
|||||||
*out = make(spec.Dependencies, len(*in))
|
*out = make(spec.Dependencies, len(*in))
|
||||||
for key, val := range *in {
|
for key, val := range *in {
|
||||||
newVal := new(spec.SchemaOrStringArray)
|
newVal := new(spec.SchemaOrStringArray)
|
||||||
if err := convertJSONSchemaPropsOrStringArray(&val, newVal, postProcess); err != nil {
|
if err := convertJSONSchemaPropsOrStringArray(&val, newVal); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
(*out)[key] = *newVal
|
(*out)[key] = *newVal
|
||||||
@ -185,20 +174,14 @@ func ConvertJSONSchemaPropsWithPostProcess(in *apiextensions.JSONSchemaProps, ou
|
|||||||
out.ExternalDocs.URL = in.ExternalDocs.URL
|
out.ExternalDocs.URL = in.ExternalDocs.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
if postProcess != nil {
|
|
||||||
if err := postProcess(out); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertSliceOfJSONSchemaProps(in *[]apiextensions.JSONSchemaProps, out *[]spec.Schema, postProcess PostProcessFunc) error {
|
func convertSliceOfJSONSchemaProps(in *[]apiextensions.JSONSchemaProps, out *[]spec.Schema) error {
|
||||||
if in != nil {
|
if in != nil {
|
||||||
for _, jsonSchemaProps := range *in {
|
for _, jsonSchemaProps := range *in {
|
||||||
schema := spec.Schema{}
|
schema := spec.Schema{}
|
||||||
if err := ConvertJSONSchemaPropsWithPostProcess(&jsonSchemaProps, &schema, postProcess); err != nil {
|
if err := ConvertJSONSchemaProps(&jsonSchemaProps, &schema); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*out = append(*out, schema)
|
*out = append(*out, schema)
|
||||||
@ -207,27 +190,25 @@ func convertSliceOfJSONSchemaProps(in *[]apiextensions.JSONSchemaProps, out *[]s
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertMapOfJSONSchemaProps(in map[string]apiextensions.JSONSchemaProps, postProcess PostProcessFunc) (map[string]spec.Schema, error) {
|
func convertMapOfJSONSchemaProps(in map[string]apiextensions.JSONSchemaProps) (map[string]spec.Schema, error) {
|
||||||
if in == nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
out := make(map[string]spec.Schema)
|
out := make(map[string]spec.Schema)
|
||||||
for k, jsonSchemaProps := range in {
|
if len(in) != 0 {
|
||||||
schema := spec.Schema{}
|
for k, jsonSchemaProps := range in {
|
||||||
if err := ConvertJSONSchemaPropsWithPostProcess(&jsonSchemaProps, &schema, postProcess); err != nil {
|
schema := spec.Schema{}
|
||||||
return nil, err
|
if err := ConvertJSONSchemaProps(&jsonSchemaProps, &schema); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out[k] = schema
|
||||||
}
|
}
|
||||||
out[k] = schema
|
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertJSONSchemaPropsOrArray(in *apiextensions.JSONSchemaPropsOrArray, out *spec.SchemaOrArray, postProcess PostProcessFunc) error {
|
func convertJSONSchemaPropsOrArray(in *apiextensions.JSONSchemaPropsOrArray, out *spec.SchemaOrArray) error {
|
||||||
if in.Schema != nil {
|
if in.Schema != nil {
|
||||||
in, out := &in.Schema, &out.Schema
|
in, out := &in.Schema, &out.Schema
|
||||||
*out = new(spec.Schema)
|
*out = new(spec.Schema)
|
||||||
if err := ConvertJSONSchemaPropsWithPostProcess(*in, *out, postProcess); err != nil {
|
if err := ConvertJSONSchemaProps(*in, *out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,7 +216,7 @@ func convertJSONSchemaPropsOrArray(in *apiextensions.JSONSchemaPropsOrArray, out
|
|||||||
in, out := &in.JSONSchemas, &out.Schemas
|
in, out := &in.JSONSchemas, &out.Schemas
|
||||||
*out = make([]spec.Schema, len(*in))
|
*out = make([]spec.Schema, len(*in))
|
||||||
for i := range *in {
|
for i := range *in {
|
||||||
if err := ConvertJSONSchemaPropsWithPostProcess(&(*in)[i], &(*out)[i], postProcess); err != nil {
|
if err := ConvertJSONSchemaProps(&(*in)[i], &(*out)[i]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,24 +224,24 @@ func convertJSONSchemaPropsOrArray(in *apiextensions.JSONSchemaPropsOrArray, out
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertJSONSchemaPropsorBool(in *apiextensions.JSONSchemaPropsOrBool, out *spec.SchemaOrBool, postProcess PostProcessFunc) error {
|
func convertJSONSchemaPropsorBool(in *apiextensions.JSONSchemaPropsOrBool, out *spec.SchemaOrBool) error {
|
||||||
out.Allows = in.Allows
|
out.Allows = in.Allows
|
||||||
if in.Schema != nil {
|
if in.Schema != nil {
|
||||||
in, out := &in.Schema, &out.Schema
|
in, out := &in.Schema, &out.Schema
|
||||||
*out = new(spec.Schema)
|
*out = new(spec.Schema)
|
||||||
if err := ConvertJSONSchemaPropsWithPostProcess(*in, *out, postProcess); err != nil {
|
if err := ConvertJSONSchemaProps(*in, *out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertJSONSchemaPropsOrStringArray(in *apiextensions.JSONSchemaPropsOrStringArray, out *spec.SchemaOrStringArray, postProcess PostProcessFunc) error {
|
func convertJSONSchemaPropsOrStringArray(in *apiextensions.JSONSchemaPropsOrStringArray, out *spec.SchemaOrStringArray) error {
|
||||||
out.Property = in.Property
|
out.Property = in.Property
|
||||||
if in.Schema != nil {
|
if in.Schema != nil {
|
||||||
in, out := &in.Schema, &out.Schema
|
in, out := &in.Schema, &out.Schema
|
||||||
*out = new(spec.Schema)
|
*out = new(spec.Schema)
|
||||||
if err := ConvertJSONSchemaPropsWithPostProcess(*in, *out, postProcess); err != nil {
|
if err := ConvertJSONSchemaProps(*in, *out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ go_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
|
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions:go_default_library",
|
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions:go_default_library",
|
||||||
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation:go_default_library",
|
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||||
"//vendor/github.com/go-openapi/spec:go_default_library",
|
"//vendor/github.com/go-openapi/spec:go_default_library",
|
||||||
@ -28,8 +28,7 @@ go_test(
|
|||||||
srcs = ["conversion_test.go"],
|
srcs = ["conversion_test.go"],
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions:go_default_library",
|
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
|
||||||
"//vendor/github.com/go-openapi/spec:go_default_library",
|
"//vendor/github.com/go-openapi/spec:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -17,29 +17,33 @@ limitations under the License.
|
|||||||
package openapi
|
package openapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/go-openapi/spec"
|
"github.com/go-openapi/spec"
|
||||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||||
"k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConvertJSONSchemaPropsToOpenAPIv2Schema converts our internal OpenAPI v3 schema
|
// ConvertJSONSchemaPropsToOpenAPIv2Schema converts our internal OpenAPI v3 schema
|
||||||
// (*apiextensions.JSONSchemaProps) to an OpenAPI v2 schema (*spec.Schema).
|
// (*apiextensions.JSONSchemaProps) to an OpenAPI v2 schema (*spec.Schema).
|
||||||
// NOTE: we use versioned type (v1beta1) here so that we can properly marshal the object
|
// NOTE: we use versioned type (v1beta1) here so that we can properly marshal the object
|
||||||
// using the JSON tags
|
// using the JSON tags
|
||||||
func ConvertJSONSchemaPropsToOpenAPIv2Schema(in *apiextensions.JSONSchemaProps) (*spec.Schema, error) {
|
func ConvertJSONSchemaPropsToOpenAPIv2Schema(in *v1beta1.JSONSchemaProps) (*spec.Schema, error) {
|
||||||
if in == nil {
|
if in == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Marshal JSONSchemaProps into JSON and unmarshal the data into spec.Schema
|
||||||
|
data, err := json.Marshal(*in)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
out := new(spec.Schema)
|
out := new(spec.Schema)
|
||||||
validation.ConvertJSONSchemaPropsWithPostProcess(in, out, func(p *spec.Schema) error {
|
if err := out.UnmarshalJSON(data); err != nil {
|
||||||
// Remove unsupported fields in OpenAPI v2
|
return nil, err
|
||||||
p.OneOf = nil
|
}
|
||||||
p.AnyOf = nil
|
// Remove unsupported fields in OpenAPI v2
|
||||||
p.Not = nil
|
out.OneOf = nil
|
||||||
|
out.AnyOf = nil
|
||||||
return nil
|
out.Not = nil
|
||||||
})
|
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,12 @@ limitations under the License.
|
|||||||
package openapi
|
package openapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-openapi/spec"
|
"github.com/go-openapi/spec"
|
||||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
||||||
@ -30,16 +30,18 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
testStr2 := "test2"
|
testStr2 := "test2"
|
||||||
testFloat64 := float64(6.4)
|
testFloat64 := float64(6.4)
|
||||||
testInt64 := int64(64)
|
testInt64 := int64(64)
|
||||||
testApiextensionsJSON := apiextensions.JSON(testStr)
|
raw, _ := json.Marshal(testStr)
|
||||||
|
raw2, _ := json.Marshal(testStr2)
|
||||||
|
testApiextensionsJSON := v1beta1.JSON{Raw: raw}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
in *apiextensions.JSONSchemaProps
|
in *v1beta1.JSONSchemaProps
|
||||||
expected *spec.Schema
|
expected *spec.Schema
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "id",
|
name: "id",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
ID: testStr,
|
ID: testStr,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -47,7 +49,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "$schema",
|
name: "$schema",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Schema: "test",
|
Schema: "test",
|
||||||
},
|
},
|
||||||
expected: &spec.Schema{
|
expected: &spec.Schema{
|
||||||
@ -58,14 +60,14 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "$ref",
|
name: "$ref",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Ref: &testStr,
|
Ref: &testStr,
|
||||||
},
|
},
|
||||||
expected: spec.RefSchema(testStr),
|
expected: spec.RefSchema(testStr),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "description",
|
name: "description",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Description: testStr,
|
Description: testStr,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -73,7 +75,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "type and format",
|
name: "type and format",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Type: testStr,
|
Type: testStr,
|
||||||
Format: testStr2,
|
Format: testStr2,
|
||||||
},
|
},
|
||||||
@ -82,7 +84,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "title",
|
name: "title",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Title: testStr,
|
Title: testStr,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -90,7 +92,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default",
|
name: "default",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Default: &testApiextensionsJSON,
|
Default: &testApiextensionsJSON,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -98,7 +100,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "maximum and exclusiveMaximum",
|
name: "maximum and exclusiveMaximum",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Maximum: &testFloat64,
|
Maximum: &testFloat64,
|
||||||
ExclusiveMaximum: true,
|
ExclusiveMaximum: true,
|
||||||
},
|
},
|
||||||
@ -107,7 +109,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "minimum and exclusiveMinimum",
|
name: "minimum and exclusiveMinimum",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Minimum: &testFloat64,
|
Minimum: &testFloat64,
|
||||||
ExclusiveMinimum: true,
|
ExclusiveMinimum: true,
|
||||||
},
|
},
|
||||||
@ -116,7 +118,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "maxLength",
|
name: "maxLength",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
MaxLength: &testInt64,
|
MaxLength: &testInt64,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -124,7 +126,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "minLength",
|
name: "minLength",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
MinLength: &testInt64,
|
MinLength: &testInt64,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -132,7 +134,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pattern",
|
name: "pattern",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Pattern: testStr,
|
Pattern: testStr,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -140,7 +142,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "maxItems",
|
name: "maxItems",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
MaxItems: &testInt64,
|
MaxItems: &testInt64,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -148,7 +150,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "minItems",
|
name: "minItems",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
MinItems: &testInt64,
|
MinItems: &testInt64,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -156,7 +158,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "uniqueItems",
|
name: "uniqueItems",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
UniqueItems: true,
|
UniqueItems: true,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -164,7 +166,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multipleOf",
|
name: "multipleOf",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
MultipleOf: &testFloat64,
|
MultipleOf: &testFloat64,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -172,15 +174,15 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "enum",
|
name: "enum",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Enum: []apiextensions.JSON{apiextensions.JSON(testStr), apiextensions.JSON(testStr2)},
|
Enum: []v1beta1.JSON{{Raw: raw}, {Raw: raw2}},
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
WithEnum(testStr, testStr2),
|
WithEnum(testStr, testStr2),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "maxProperties",
|
name: "maxProperties",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
MaxProperties: &testInt64,
|
MaxProperties: &testInt64,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -188,7 +190,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "minProperties",
|
name: "minProperties",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
MinProperties: &testInt64,
|
MinProperties: &testInt64,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -196,7 +198,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "required",
|
name: "required",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Required: []string{testStr, testStr2},
|
Required: []string{testStr, testStr2},
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -204,9 +206,9 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "items single props",
|
name: "items single props",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Items: &apiextensions.JSONSchemaPropsOrArray{
|
Items: &v1beta1.JSONSchemaPropsOrArray{
|
||||||
Schema: &apiextensions.JSONSchemaProps{
|
Schema: &v1beta1.JSONSchemaProps{
|
||||||
Type: "boolean",
|
Type: "boolean",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -221,9 +223,9 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "items array props",
|
name: "items array props",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Items: &apiextensions.JSONSchemaPropsOrArray{
|
Items: &v1beta1.JSONSchemaPropsOrArray{
|
||||||
JSONSchemas: []apiextensions.JSONSchemaProps{
|
JSONSchemas: []v1beta1.JSONSchemaProps{
|
||||||
{Type: "boolean"},
|
{Type: "boolean"},
|
||||||
{Type: "string"},
|
{Type: "string"},
|
||||||
},
|
},
|
||||||
@ -242,8 +244,8 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "allOf",
|
name: "allOf",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
AllOf: []apiextensions.JSONSchemaProps{
|
AllOf: []v1beta1.JSONSchemaProps{
|
||||||
{Type: "boolean"},
|
{Type: "boolean"},
|
||||||
{Type: "string"},
|
{Type: "string"},
|
||||||
},
|
},
|
||||||
@ -253,8 +255,8 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "oneOf",
|
name: "oneOf",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
OneOf: []apiextensions.JSONSchemaProps{
|
OneOf: []v1beta1.JSONSchemaProps{
|
||||||
{Type: "boolean"},
|
{Type: "boolean"},
|
||||||
{Type: "string"},
|
{Type: "string"},
|
||||||
},
|
},
|
||||||
@ -271,8 +273,8 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "anyOf",
|
name: "anyOf",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
AnyOf: []apiextensions.JSONSchemaProps{
|
AnyOf: []v1beta1.JSONSchemaProps{
|
||||||
{Type: "boolean"},
|
{Type: "boolean"},
|
||||||
{Type: "string"},
|
{Type: "string"},
|
||||||
},
|
},
|
||||||
@ -289,8 +291,8 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "not",
|
name: "not",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Not: &apiextensions.JSONSchemaProps{
|
Not: &v1beta1.JSONSchemaProps{
|
||||||
Type: "boolean",
|
Type: "boolean",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -301,90 +303,10 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "nested logic",
|
|
||||||
in: &apiextensions.JSONSchemaProps{
|
|
||||||
AllOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{
|
|
||||||
Not: &apiextensions.JSONSchemaProps{
|
|
||||||
Type: "boolean",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
AnyOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{Type: "boolean"},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
OneOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{Type: "boolean"},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
AnyOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{
|
|
||||||
Not: &apiextensions.JSONSchemaProps{
|
|
||||||
Type: "boolean",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
AnyOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{Type: "boolean"},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
OneOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{Type: "boolean"},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
OneOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{
|
|
||||||
Not: &apiextensions.JSONSchemaProps{
|
|
||||||
Type: "boolean",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
AnyOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{Type: "boolean"},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
OneOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{Type: "boolean"},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
Not: &apiextensions.JSONSchemaProps{
|
|
||||||
Not: &apiextensions.JSONSchemaProps{
|
|
||||||
Type: "boolean",
|
|
||||||
},
|
|
||||||
AnyOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{Type: "boolean"},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
OneOf: []apiextensions.JSONSchemaProps{
|
|
||||||
{Type: "boolean"},
|
|
||||||
{Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expected: new(spec.Schema).
|
|
||||||
WithAllOf(spec.Schema{}, spec.Schema{}, spec.Schema{}, *spec.StringProperty()),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "properties",
|
name: "properties",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Properties: map[string]apiextensions.JSONSchemaProps{
|
Properties: map[string]v1beta1.JSONSchemaProps{
|
||||||
testStr: {Type: "boolean"},
|
testStr: {Type: "boolean"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -393,10 +315,10 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "additionalProperties",
|
name: "additionalProperties",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
AdditionalProperties: &apiextensions.JSONSchemaPropsOrBool{
|
AdditionalProperties: &v1beta1.JSONSchemaPropsOrBool{
|
||||||
Allows: true,
|
Allows: true,
|
||||||
Schema: &apiextensions.JSONSchemaProps{Type: "boolean"},
|
Schema: &v1beta1.JSONSchemaProps{Type: "boolean"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &spec.Schema{
|
expected: &spec.Schema{
|
||||||
@ -410,8 +332,8 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "patternProperties",
|
name: "patternProperties",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
PatternProperties: map[string]apiextensions.JSONSchemaProps{
|
PatternProperties: map[string]v1beta1.JSONSchemaProps{
|
||||||
testStr: {Type: "boolean"},
|
testStr: {Type: "boolean"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -425,10 +347,10 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "dependencies schema",
|
name: "dependencies schema",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Dependencies: apiextensions.JSONSchemaDependencies{
|
Dependencies: v1beta1.JSONSchemaDependencies{
|
||||||
testStr: apiextensions.JSONSchemaPropsOrStringArray{
|
testStr: v1beta1.JSONSchemaPropsOrStringArray{
|
||||||
Schema: &apiextensions.JSONSchemaProps{Type: "boolean"},
|
Schema: &v1beta1.JSONSchemaProps{Type: "boolean"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -444,9 +366,9 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "dependencies string array",
|
name: "dependencies string array",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Dependencies: apiextensions.JSONSchemaDependencies{
|
Dependencies: v1beta1.JSONSchemaDependencies{
|
||||||
testStr: apiextensions.JSONSchemaPropsOrStringArray{
|
testStr: v1beta1.JSONSchemaPropsOrStringArray{
|
||||||
Property: []string{testStr2},
|
Property: []string{testStr2},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -463,10 +385,10 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "additionalItems",
|
name: "additionalItems",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
AdditionalItems: &apiextensions.JSONSchemaPropsOrBool{
|
AdditionalItems: &v1beta1.JSONSchemaPropsOrBool{
|
||||||
Allows: true,
|
Allows: true,
|
||||||
Schema: &apiextensions.JSONSchemaProps{Type: "boolean"},
|
Schema: &v1beta1.JSONSchemaProps{Type: "boolean"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &spec.Schema{
|
expected: &spec.Schema{
|
||||||
@ -480,9 +402,9 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "definitions",
|
name: "definitions",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Definitions: apiextensions.JSONSchemaDefinitions{
|
Definitions: v1beta1.JSONSchemaDefinitions{
|
||||||
testStr: apiextensions.JSONSchemaProps{Type: "boolean"},
|
testStr: v1beta1.JSONSchemaProps{Type: "boolean"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &spec.Schema{
|
expected: &spec.Schema{
|
||||||
@ -495,8 +417,8 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "externalDocs",
|
name: "externalDocs",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
ExternalDocs: &apiextensions.ExternalDocumentation{
|
ExternalDocs: &v1beta1.ExternalDocumentation{
|
||||||
Description: testStr,
|
Description: testStr,
|
||||||
URL: testStr2,
|
URL: testStr2,
|
||||||
},
|
},
|
||||||
@ -506,7 +428,7 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "example",
|
name: "example",
|
||||||
in: &apiextensions.JSONSchemaProps{
|
in: &v1beta1.JSONSchemaProps{
|
||||||
Example: &testApiextensionsJSON,
|
Example: &testApiextensionsJSON,
|
||||||
},
|
},
|
||||||
expected: new(spec.Schema).
|
expected: new(spec.Schema).
|
||||||
@ -515,14 +437,12 @@ func Test_ConvertJSONSchemaPropsToOpenAPIv2Schema(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
out, err := ConvertJSONSchemaPropsToOpenAPIv2Schema(test.in)
|
||||||
out, err := ConvertJSONSchemaPropsToOpenAPIv2Schema(test.in)
|
if err != nil {
|
||||||
if err != nil {
|
t.Errorf("unexpected error in converting openapi schema: %v", test.name)
|
||||||
t.Fatalf("unexpected error in converting openapi schema: %v", err)
|
}
|
||||||
}
|
if !reflect.DeepEqual(out, test.expected) {
|
||||||
if !reflect.DeepEqual(*out, *test.expected) {
|
t.Errorf("result of conversion test '%v' didn't match, want: %v; got: %v", test.name, *test.expected, *out)
|
||||||
t.Errorf("unexpected result:\n want=%v\n got=%v\n\n%s", *test.expected, *out, diff.ObjectDiff(*test.expected, *out))
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/go-openapi/spec"
|
"github.com/go-openapi/spec"
|
||||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
||||||
|
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -205,7 +206,7 @@ func scaleStatusSchema() *spec.Schema {
|
|||||||
// NOTE: in apiserver we general operates on internal types. We are using versioned (v1beta1)
|
// NOTE: in apiserver we general operates on internal types. We are using versioned (v1beta1)
|
||||||
// validation schema here because we need the json tags to properly marshal the object to
|
// validation schema here because we need the json tags to properly marshal the object to
|
||||||
// JSON.
|
// JSON.
|
||||||
func CustomResourceDefinitionOpenAPISpec(crdSpec *apiextensions.CustomResourceDefinitionSpec, version string, validationSchema *apiextensions.CustomResourceValidation) (*spec.Swagger, string, error) {
|
func CustomResourceDefinitionOpenAPISpec(crdSpec *apiextensions.CustomResourceDefinitionSpec, version string, validationSchema *v1beta1.CustomResourceValidation) (*spec.Swagger, string, error) {
|
||||||
schema := &spec.Schema{}
|
schema := &spec.Schema{}
|
||||||
if validationSchema != nil && validationSchema.OpenAPIV3Schema != nil {
|
if validationSchema != nil && validationSchema.OpenAPIV3Schema != nil {
|
||||||
var err error
|
var err error
|
||||||
|
Loading…
Reference in New Issue
Block a user