-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
surface: Set status and content-type in response fields (#385)
Ensures both V2 and V3 derived APIs include the content/type values in the surface fields names like '200 application/json'.
- Loading branch information
1 parent
dd1001c
commit 987797b
Showing
8 changed files
with
440 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package surface_v1 | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
openapiv2 "github.com/google/gnostic/openapiv2" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"google.golang.org/protobuf/encoding/protojson" | ||
"google.golang.org/protobuf/testing/protocmp" | ||
) | ||
|
||
func TestModelOpenAPIV2(t *testing.T) { | ||
refFile := "testdata/v2.0/petstore.json" | ||
modelFile := "testdata/v2.0/petstore.model.json" | ||
|
||
bFile, err := os.ReadFile(refFile) | ||
if err != nil { | ||
t.Logf("Failed to read file: %+v", err) | ||
t.FailNow() | ||
} | ||
bModel, err := os.ReadFile(modelFile) | ||
if err != nil { | ||
t.Logf("Failed to read file: %+v", err) | ||
t.FailNow() | ||
} | ||
|
||
docv2, err := openapiv2.ParseDocument(bFile) | ||
if err != nil { | ||
t.Logf("Failed to parse document: %+v", err) | ||
t.FailNow() | ||
} | ||
|
||
m, err := NewModelFromOpenAPI2(docv2, refFile) | ||
if err != nil { | ||
t.Logf("Failed to create model: %+v", err) | ||
t.FailNow() | ||
} | ||
|
||
var model Model | ||
if err := protojson.Unmarshal(bModel, &model); err != nil { | ||
t.Logf("Failed to unmarshal model: %+v", err) | ||
t.FailNow() | ||
} | ||
|
||
cmpOpts := []cmp.Option{ | ||
protocmp.Transform(), | ||
} | ||
if diff := cmp.Diff(&model, m, cmpOpts...); diff != "" { | ||
t.Errorf("Model mismatch (-want +got):\n%s", diff) | ||
} | ||
x, _ := protojson.Marshal(m) | ||
t.Logf("Model: %s", x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package surface_v1 | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
openapiv3 "github.com/google/gnostic/openapiv3" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"google.golang.org/protobuf/encoding/protojson" | ||
"google.golang.org/protobuf/testing/protocmp" | ||
) | ||
|
||
func TestModelOpenAPIV3(t *testing.T) { | ||
refFile := "testdata/v3.0/petstore.json" | ||
modelFile := "testdata/v3.0/petstore.model.json" | ||
|
||
bFile, err := os.ReadFile(refFile) | ||
if err != nil { | ||
t.Logf("Failed to read file: %+v", err) | ||
t.FailNow() | ||
} | ||
bModel, err := os.ReadFile(modelFile) | ||
if err != nil { | ||
t.Logf("Failed to read file: %+v", err) | ||
t.FailNow() | ||
} | ||
|
||
docv3, err := openapiv3.ParseDocument(bFile) | ||
if err != nil { | ||
t.Logf("Failed to parse document: %+v", err) | ||
t.FailNow() | ||
} | ||
|
||
m, err := NewModelFromOpenAPI3(docv3, refFile) | ||
if err != nil { | ||
t.Logf("Failed to create model: %+v", err) | ||
t.FailNow() | ||
} | ||
|
||
var model Model | ||
if err := protojson.Unmarshal(bModel, &model); err != nil { | ||
t.Logf("Failed to unmarshal model: %+v", err) | ||
t.FailNow() | ||
} | ||
|
||
cmpOpts := []cmp.Option{ | ||
protocmp.Transform(), | ||
} | ||
if diff := cmp.Diff(&model, m, cmpOpts...); diff != "" { | ||
t.Errorf("Model mismatch (-want +got):\n%s", diff) | ||
} | ||
x, _ := protojson.Marshal(m) | ||
t.Logf("Model: %s", x) | ||
} |
Oops, something went wrong.