Skip to content

Commit d30eda3

Browse files
committed
BUG/MINOR: specification: fix open api v3 specification generation
1 parent 0fb4941 commit d30eda3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

configure_data_plane.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package dataplaneapi
2020
import (
2121
"context"
2222
"crypto/tls"
23+
"encoding/json"
2324
"io"
2425
"net/http"
2526
"os"
@@ -751,7 +752,11 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
751752
// setup OpenAPI v3 specification handler
752753
api.Version3GetOpenapiv3SpecificationHandler = version3.GetOpenapiv3SpecificationHandlerFunc(func(params version3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder {
753754
v2 := openapi2.T{}
754-
err = v2.UnmarshalJSON(SwaggerJSON)
755+
v2JSONString := string(SwaggerJSON)
756+
v2JSONString = strings.ReplaceAll(v2JSONString, "#/definitions", "#/components/schemas")
757+
curatedV2 := json.RawMessage([]byte(v2JSONString))
758+
759+
err = v2.UnmarshalJSON(curatedV2)
755760
if err != nil {
756761
e := misc.HandleError(err)
757762
return version3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)

configure_data_plane_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,26 @@
1818
package dataplaneapi
1919

2020
import (
21+
"encoding/json"
22+
"strings"
2123
"testing"
2224

2325
"github.com/getkin/kin-openapi/openapi2"
2426
"github.com/getkin/kin-openapi/openapi2conv"
2527
)
2628

2729
func TestConvOpenAPIV2ToV3(t *testing.T) {
30+
v2JSONString := string(SwaggerJSON)
31+
v2JSONString = strings.ReplaceAll(v2JSONString, "#/definitions", "#/components/schemas")
32+
curatedV2 := json.RawMessage([]byte(v2JSONString))
33+
2834
var v2 openapi2.T
29-
err := v2.UnmarshalJSON(SwaggerJSON)
35+
err := v2.UnmarshalJSON(curatedV2)
3036
if err != nil {
3137
t.Error(err)
3238
return
3339
}
40+
3441
_, err = openapi2conv.ToV3(&v2)
3542
if err != nil {
3643
t.Error(err)

0 commit comments

Comments
 (0)