Skip to content

Commit 86897d9

Browse files
committed
BUG/MINOR: specification: fix open api v3 specification generation
1 parent 80947b6 commit 86897d9

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

configure_data_plane.go

Lines changed: 6 additions & 1 deletion
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"
@@ -934,7 +935,11 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
934935
// setup OpenAPI v3 specification handler
935936
api.Version3GetOpenapiv3SpecificationHandler = version3.GetOpenapiv3SpecificationHandlerFunc(func(params version3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder {
936937
v2 := openapi2.T{}
937-
err = v2.UnmarshalJSON(SwaggerJSON)
938+
v2JSONString := string(SwaggerJSON)
939+
v2JSONString = strings.ReplaceAll(v2JSONString, "#/definitions", "#/components/schemas")
940+
curatedV2 := json.RawMessage([]byte(v2JSONString))
941+
942+
err = v2.UnmarshalJSON(curatedV2)
938943
if err != nil {
939944
e := misc.HandleError(err)
940945
return version3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)

configure_data_plane_test.go

Lines changed: 8 additions & 1 deletion
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)