nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: getkin/kin-openapi
Pull request #682 (2022-11-25 12:01:34)

fix: error path is lost (#681)
see #681 and `TestReversePathInMessageSchemaError`.


Patch:
diff --git a/openapi3/schema.go b/openapi3/schema.go
index 600cb9d..eb01673 100644
--- a/openapi3/schema.go
+++ b/openapi3/schema.go
@@ -1722,11 +1722,8 @@ func (err *SchemaError) Error() string {
 		}
 	}
 
-	if err.Origin != nil {
-		return err.Origin.Error()
-	}
-
 	buf := bytes.NewBuffer(make([]byte, 0, 256))
+
 	if len(err.reversePath) > 0 {
 		buf.WriteString(`Error at "`)
 		reversePath := err.reversePath
@@ -1736,6 +1733,13 @@ func (err *SchemaError) Error() string {
 		}
 		buf.WriteString(`": `)
 	}
+
+	if err.Origin != nil {
+		buf.WriteString(err.Origin.Error())
+
+		return buf.String()
+	}
+
 	reason := err.Reason
 	if reason == "" {
 		buf.WriteString(`Doesn't match schema "`)
@@ -1744,6 +1748,7 @@ func (err *SchemaError) Error() string {
 	} else {
 		buf.WriteString(reason)
 	}
+
 	if !SchemaErrorDetailsDisabled {
 		buf.WriteString("\nSchema:\n  ")
 		encoder := json.NewEncoder(buf)
@@ -1756,6 +1761,7 @@ func (err *SchemaError) Error() string {
 			panic(err)
 		}
 	}
+
 	return buf.String()
 }
 


Test patch:
diff --git a/openapi3/schema_formats_test.go b/openapi3/schema_formats_test.go
index eeb7894..3899fab 100644
--- a/openapi3/schema_formats_test.go
+++ b/openapi3/schema_formats_test.go
@@ -75,3 +75,33 @@ func TestFormatCallback_WrapError(t *testing.T) {
 
 	delete(SchemaStringFormats, "foobar")
 }
+
+func TestReversePathInMessageSchemaError(t *testing.T) {
+	DefineIPv4Format()
+
+	SchemaErrorDetailsDisabled = true
+
+	const spc = `
+components:
+  schemas:
+    Something:
+      type: object
+      properties:
+        ip:
+          type: string
+          format: ipv4
+`
+	l := NewLoader()
+
+	doc, err := l.LoadFromData([]byte(spc))
+	require.NoError(t, err)
+
+	err = doc.Components.Schemas["Something"].Value.VisitJSON(map[string]interface{}{
+		`ip`: `123.0.0.11111`,
+	})
+
+	require.EqualError(t, err, `Error at "/ip": Not an IP address`)
+
+	delete(SchemaStringFormats, "ipv4")
+	SchemaErrorDetailsDisabled = false
+}
diff --git a/openapi3/schema_issue289_test.go b/openapi3/schema_issue289_test.go
index 6ab6b63..56d1d45 100644
--- a/openapi3/schema_issue289_test.go
+++ b/openapi3/schema_issue289_test.go
@@ -35,5 +35,5 @@ openapi: "3.0.1"
 		"name":    "kin-openapi",
 		"address": "127.0.0.1",
 	})
-	require.EqualError(t, err, ErrOneOfConflict.Error())
+	require.ErrorIs(t, err, ErrOneOfConflict)
 }
diff --git a/openapi3filter/issue625_test.go b/openapi3filter/issue625_test.go
index f00940b..f071343 100644
--- a/openapi3filter/issue625_test.go
+++ b/openapi3filter/issue625_test.go
@@ -72,7 +72,7 @@ paths:
 			name:   "failed allof object array",
 			spec:   allOfArraySpec,
 			req:    `/items?test=1.2,3.1`,
-			errStr: `parameter "test" in query has an error: Value must be an integer`,
+			errStr: `parameter "test" in query has an error: Error at "/0": Value must be an integer`,
 		},
 		{
 			name: "success oneof object array",
Repository: getkin/kin-openapi
Pull request #704 (2022-12-14 05:40:59)

Use and update GetBody() member of request
Fix for https://github.com/getkin/kin-openapi/issues/703.



Patch:
diff --git a/openapi3filter/validate_request.go b/openapi3filter/validate_request.go
index 4acb9ff..8a74772 100644
--- a/openapi3filter/validate_request.go
+++ b/openapi3filter/validate_request.go
@@ -5,6 +5,7 @@ import (
 	"context"
 	"errors"
 	"fmt"
+	"io"
 	"io/ioutil"
 	"net/http"
 	"sort"
@@ -216,7 +217,19 @@ func ValidateRequestBody(ctx context.Context, input *RequestValidationInput, req
 			}
 		}
 		// Put the data back into the input
-		req.Body = ioutil.NopCloser(bytes.NewReader(data))
+		req.Body = nil
+		if req.GetBody != nil {
+			if req.Body, err = req.GetBody(); err != nil {
+				req.Body = nil
+			}
+		}
+		if req.Body == nil {
+			req.ContentLength = int64(len(data))
+			req.GetBody = func() (io.ReadCloser, error) {
+				return io.NopCloser(bytes.NewReader(data)), nil
+			}
+			req.Body, _ = req.GetBody() // no error return
+		}
 	}
 
 	if len(data) == 0 {
@@ -292,8 +305,14 @@ func ValidateRequestBody(ctx context.Context, input *RequestValidationInput, req
 			}
 		}
 		// Put the data back into the input
-		req.Body = ioutil.NopCloser(bytes.NewReader(data))
+		if req.Body != nil {
+			req.Body.Close()
+		}
 		req.ContentLength = int64(len(data))
+		req.GetBody = func() (io.ReadCloser, error) {
+			return io.NopCloser(bytes.NewReader(data)), nil
+		}
+		req.Body, _ = req.GetBody() // no error return
 	}
 
 	return nil


Test patch:
diff --git a/openapi3filter/validate_request_test.go b/openapi3filter/validate_request_test.go
index 450ee59..8da550c 100644
--- a/openapi3filter/validate_request_test.go
+++ b/openapi3filter/validate_request_test.go
@@ -212,6 +212,12 @@ components:
 			assert.Equal(t, contentLen, bodySize, "expect ContentLength %d to equal body size %d", contentLen, bodySize)
 			bodyModified := originalBodySize != bodySize
 			assert.Equal(t, bodyModified, tc.expectedModification, "expect request body modification happened: %t, expected %t", bodyModified, tc.expectedModification)
+
+			validationInput.Request.Body, err = validationInput.Request.GetBody()
+			assert.NoError(t, err, "unable to re-generate body by GetBody(): %v", err)
+			body2, err := io.ReadAll(validationInput.Request.Body)
+			assert.NoError(t, err, "unable to read request body: %v", err)
+			assert.Equal(t, body, body2, "body by GetBody() is not matched")
 		})
 	}
 }
Repository: getkin/kin-openapi
Pull request #754 (2023-01-27 12:24:43)

openapi3: empty scopes are valid
accoriding to v3.1.0 documentation the scopes field can be empty.
https://spec.openapis.org/oas/v3.1.0#fixed-fields-24


Patch:
diff --git a/openapi3/security_scheme.go b/openapi3/security_scheme.go
index 788c73e..76cc21f 100644
--- a/openapi3/security_scheme.go
+++ b/openapi3/security_scheme.go
@@ -363,8 +363,8 @@ func (flow *OAuthFlow) Validate(ctx context.Context, opts ...ValidationOption) e
 		}
 	}
 
-	if v := flow.Scopes; len(v) == 0 {
-		return errors.New("field 'scopes' is empty or missing")
+	if flow.Scopes == nil {
+		return errors.New("field 'scopes' is missing")
 	}
 
 	return validateExtensions(ctx, flow.Extensions)


Test patch:
diff --git a/openapi3/security_scheme_test.go b/openapi3/security_scheme_test.go
index 48ea046..790414c 100644
--- a/openapi3/security_scheme_test.go
+++ b/openapi3/security_scheme_test.go
@@ -197,7 +197,7 @@ var securitySchemeExamples = []securitySchemeExample{
     }
   }
 }`),
-		valid: false,
+		valid: true,
 	},
 
 	{