Skip to content

Commit

Permalink
BUG/MINOR: specification: fix open api v3 specification generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mjuraga committed Dec 19, 2024
1 parent 7d130a3 commit d12243a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion configure_data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package dataplaneapi
import (
"context"
"crypto/tls"
"encoding/json"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion configure_data_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@
package dataplaneapi

import (
"encoding/json"
"strings"
"testing"

"github.com/getkin/kin-openapi/openapi2"
"github.com/getkin/kin-openapi/openapi2conv"
)

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)
Expand Down

0 comments on commit d12243a

Please sign in to comment.