Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement of unstable operation during OAS Spec verification #91

Merged
merged 3 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ func (rnr *httpRunner) Run(ctx context.Context, r *httpRequest) error {
if err := rnr.validator.ValidateRequest(ctx, req); err != nil {
return err
}
// reset Request.Body
reqBody, err := r.encodeBody()
if err != nil {
return err
}
rc, ok := reqBody.(io.ReadCloser)
if !ok && reqBody != nil {
rc = io.NopCloser(reqBody)
}
req.Body = rc

res, err = rnr.client.Do(req)
if err != nil {
return err
Expand Down
19 changes: 17 additions & 2 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func TestHTTPRunnerRunUsingGitHubAPI(t *testing.T) {
}
endpoint := "https://api.github.com"
tests := []struct {
req *httpRequest
want int
req *httpRequest
useOpenApi3Validator bool
want int
}{
{
&httpRequest{
Expand All @@ -31,6 +32,7 @@ func TestHTTPRunnerRunUsingGitHubAPI(t *testing.T) {
"Authorization": fmt.Sprintf("token %s", os.Getenv("GITHUB_TOKEN")),
},
},
true,
http.StatusOK,
},
{
Expand All @@ -40,6 +42,7 @@ func TestHTTPRunnerRunUsingGitHubAPI(t *testing.T) {
mediaType: MediaTypeApplicationJSON,
headers: map[string]string{},
},
false,
http.StatusNotFound,
},
}
Expand All @@ -54,6 +57,18 @@ func TestHTTPRunnerRunUsingGitHubAPI(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if tt.useOpenApi3Validator {
c := &httpRunnerConfig{
OpenApi3DocLocation: "testdata/openapi3.yml",
SkipValidateRequest: false,
SkipValidateResponse: false,
}
v, err := newHttpValidator(c)
if err != nil {
t.Fatal(err)
}
r.validator = v
}
if err := r.Run(ctx, tt.req); err != nil {
t.Error(err)
continue
Expand Down
16 changes: 7 additions & 9 deletions testdata/openapi3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: object
properties:
username:
type: string
required:
- username
- email
login:
type: string
id:
type: integer
required:
- data
- login
- id