diff --git a/configure_data_plane.go b/configure_data_plane.go index 032ab547..a2e56b13 100644 --- a/configure_data_plane.go +++ b/configure_data_plane.go @@ -20,6 +20,7 @@ package dataplaneapi import ( "context" "crypto/tls" + "encoding/json" "io" "net/http" "os" @@ -754,7 +755,11 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m // setup OpenAPI v3 specification handler api.Version3GetOpenapiv3SpecificationHandler = version3.GetOpenapiv3SpecificationHandlerFunc(func(params version3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder { v2 := openapi2.T{} - err = v2.UnmarshalJSON(SwaggerJSON) + v2JSONString := string(SwaggerJSON) + v2JSONString = strings.ReplaceAll(v2JSONString, "#/definitions", "#/components/schemas") + curatedV2 := json.RawMessage([]byte(v2JSONString)) + + err = v2.UnmarshalJSON(curatedV2) if err != nil { e := misc.HandleError(err) return version3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e) diff --git a/configure_data_plane_test.go b/configure_data_plane_test.go index eb99d7db..862f7e6a 100644 --- a/configure_data_plane_test.go +++ b/configure_data_plane_test.go @@ -18,6 +18,8 @@ package dataplaneapi import ( + "encoding/json" + "strings" "testing" "github.com/getkin/kin-openapi/openapi2" @@ -25,12 +27,17 @@ import ( ) func TestConvOpenAPIV2ToV3(t *testing.T) { + v2JSONString := string(SwaggerJSON) + v2JSONString = strings.ReplaceAll(v2JSONString, "#/definitions", "#/components/schemas") + curatedV2 := json.RawMessage([]byte(v2JSONString)) + var v2 openapi2.T - err := v2.UnmarshalJSON(SwaggerJSON) + err := v2.UnmarshalJSON(curatedV2) if err != nil { t.Error(err) return } + _, err = openapi2conv.ToV3(&v2) if err != nil { t.Error(err)