Skip to content

Commit d12243a

Browse files
committed
BUG/MINOR: specification: fix open api v3 specification generation
1 parent 7d130a3 commit d12243a

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"
@@ -754,7 +755,11 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
754755
// setup OpenAPI v3 specification handler
755756
api.Version3GetOpenapiv3SpecificationHandler = version3.GetOpenapiv3SpecificationHandlerFunc(func(params version3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder {
756757
v2 := openapi2.T{}
757-
err = v2.UnmarshalJSON(SwaggerJSON)
758+
v2JSONString := string(SwaggerJSON)
759+
v2JSONString = strings.ReplaceAll(v2JSONString, "#/definitions", "#/components/schemas")
760+
curatedV2 := json.RawMessage([]byte(v2JSONString))
761+
762+
err = v2.UnmarshalJSON(curatedV2)
758763
if err != nil {
759764
e := misc.HandleError(err)
760765
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)