nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: deepmap/oapi-codegen
Pull request #24 (2019-06-03 14:13:15)

DeepObject support
Adds support for deepObject parameters.
https://swagger.io/docs/specification/serialization/



Patch:
diff --git a/pkg/runtime/bindparam.go b/pkg/runtime/bindparam.go
index 685bcb2..d40d57c 100644
--- a/pkg/runtime/bindparam.go
+++ b/pkg/runtime/bindparam.go
@@ -388,7 +388,33 @@ func BindQueryParameter(style string, explode bool, required bool, paramName str
 			dv.Set(reflect.ValueOf(output))
 		}
 		return nil
-	case "spaceDelimited", "pipeDelimited", "deepObject":
+	case "deepObject":
+		// Loop through all queryParams and fill the objectMap with all key/value pairs having paramName as key
+		objectMap := map[string]string{}
+		for k, v := range queryParams {
+			if !strings.HasPrefix(k, paramName + "[") {
+				continue
+			}
+			split := strings.Split(k, "[")
+			if len(split) != 2 {
+				return echo.NewHTTPError(http.StatusBadRequest,
+					fmt.Sprintf("parameter '%s=%s' does not match deepObject style", k, v))
+			}
+
+			k = strings.TrimSuffix(split[1], "]")
+			objectMap[k] = v[0]
+		}
+
+		// Marshal and unmarshal the objectMap into dest
+		data, err := json.Marshal(objectMap)
+		if err != nil {
+			return err
+		}
+		if err = json.Unmarshal(data, dest); err != nil {
+			return err
+		}
+		return nil
+	case "spaceDelimited", "pipeDelimited":
 		return echo.NewHTTPError(http.StatusNotImplemented,
 			fmt.Sprintf("query arguments of style '%s' aren't yet supported", style))
 	default:


Test patch:
diff --git a/pkg/runtime/bindparam_test.go b/pkg/runtime/bindparam_test.go
index d445827..bc12c20 100644
--- a/pkg/runtime/bindparam_test.go
+++ b/pkg/runtime/bindparam_test.go
@@ -14,6 +14,7 @@
 package runtime
 
 import (
+	"net/url"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -226,3 +227,26 @@ func TestSplitParameter(t *testing.T) {
 	assert.NoError(t, err)
 	assert.EqualValues(t, expectedExplodedObject, result)
 }
+
+func TestBindQueryParameter(t *testing.T) {
+	type ID struct{
+		FirstName *string	`json:"firstName"`
+		LastName  *string 	`json:"lastName"`
+		Role      string	`json:"role"`
+	}
+
+	expectedName := "Alex"
+	expectedDeepObject := &ID{FirstName: &expectedName, Role: "admin"}
+
+	actual := new(ID)
+	paramName := "id"
+	queryParams := url.Values{
+		"id[firstName]": {"Alex"},
+		"id[role]": {"admin"},
+		"foo": {"bar"},
+	}
+
+	err := BindQueryParameter("deepObject", true, false, paramName, queryParams, &actual)
+	assert.NoError(t, err)
+	assert.Equal(t, expectedDeepObject, actual)
+}
Repository: deepmap/oapi-codegen
Pull request #142 (2020-02-27 20:00:38)

Respect an http error returned by the authentication function
Currently, the `OapiRequestValidator` middleware always responds with a 403 if all authentication functions return an error.  The authentication function should be able to distinguish a 401 (missing credentials) from a 403 (invalid credentials).  The change in this branch makes it so the middleware respects an `echo.HTTPError` if one is returned from an authentication function.  The tests demonstrate how the middleware can be configured to generate a 401 instead of a 403.


Patch:
diff --git a/pkg/middleware/oapi_validate.go b/pkg/middleware/oapi_validate.go
index 2cf2af6..7480936 100644
--- a/pkg/middleware/oapi_validate.go
+++ b/pkg/middleware/oapi_validate.go
@@ -126,6 +126,12 @@ func ValidateRequestFromContext(ctx echo.Context, router *openapi3filter.Router,
 				Internal: err,
 			}
 		case *openapi3filter.SecurityRequirementsError:
+			for _, err := range e.Errors {
+				httpErr, ok := err.(*echo.HTTPError)
+				if ok {
+					return httpErr
+				}
+			}
 			return &echo.HTTPError{
 				Code:     http.StatusForbidden,
 				Message:  e.Error(),
@@ -135,8 +141,8 @@ func ValidateRequestFromContext(ctx echo.Context, router *openapi3filter.Router,
 			// This should never happen today, but if our upstream code changes,
 			// we don't want to crash the server, so handle the unexpected error.
 			return &echo.HTTPError{
-				Code: http.StatusInternalServerError,
-				Message: fmt.Sprintf("error validating request: %s", err),
+				Code:     http.StatusInternalServerError,
+				Message:  fmt.Sprintf("error validating request: %s", err),
 				Internal: err,
 			}
 		}


Test patch:
diff --git a/pkg/middleware/oapi_validate_test.go b/pkg/middleware/oapi_validate_test.go
index aede2ff..4320986 100644
--- a/pkg/middleware/oapi_validate_test.go
+++ b/pkg/middleware/oapi_validate_test.go
@@ -87,6 +87,15 @@ paths:
       responses:
         '204':
           description: no content
+  /protected_resource_401:
+    get:
+      operationId: getProtectedResource
+      security:
+        - BearerAuth:
+          - unauthorized
+      responses:
+        '401':
+          description: no content
 components:
   securitySchemes:
     BearerAuth:
@@ -127,6 +136,9 @@ func TestOapiRequestValidator(t *testing.T) {
 					if s == "someScope" {
 						return nil
 					}
+					if s == "unauthorized" {
+						return echo.ErrUnauthorized
+					}
 				}
 				return errors.New("forbidden")
 			},
@@ -234,4 +246,16 @@ func TestOapiRequestValidator(t *testing.T) {
 		assert.False(t, called, "Handler should not have been called")
 		called = false
 	}
+
+	e.GET("/protected_resource_401", func(c echo.Context) error {
+		called = true
+		return c.NoContent(http.StatusNoContent)
+	})
+	// Call a protected function without credentials
+	{
+		rec := doGet(t, e, "http://deepmap.ai/protected_resource_401")
+		assert.Equal(t, http.StatusUnauthorized, rec.Code)
+		assert.False(t, called, "Handler should not have been called")
+		called = false
+	}
 }
Repository: deepmap/oapi-codegen
Pull request #404 (2021-07-18 12:02:00)

Support standard encoding.TextUnmarshaler interface
Hi,

First of all thank you for this wonderful tool it really makes my life so much easier!

There are various standard types supporting standard encoding.TextUnmarshaler interface.
Here are few very famous ones for example: 
* big.Int 
* net.IP
* google.UUID

And there are thousands of other custom types implementing this interface can be found on GitHub
Currently if you try to use such types as a parameters you're getting binding error like:
```Invalid format for parameter id: error binding string parameter: can not bind to destination of type: array``` in case of net.IP or google.UUID

I know that there was a similar PR #262 but unfortunately it doesn't allow you to use thousands of existing types and forces you to create a new type with Bind(string) error method implemented on it. This is very inconvenient and this PR solves the problem.

hexdigest: @deepmap-marcinr Hi, is there any chance to get this merged?

Patch:
diff --git a/pkg/runtime/bindparam.go b/pkg/runtime/bindparam.go
index f988e7b..751cc7d 100644
--- a/pkg/runtime/bindparam.go
+++ b/pkg/runtime/bindparam.go
@@ -14,6 +14,7 @@
 package runtime
 
 import (
+	"encoding"
 	"encoding/json"
 	"fmt"
 	"net/url"
@@ -65,6 +66,15 @@ func BindStyledParameterWithLocation(style string, explode bool, paramName strin
 		// Headers and cookies aren't escaped.
 	}
 
+	// If the destination implements encoding.TextUnmarshaler we use it for binding
+	if tu, ok := dest.(encoding.TextUnmarshaler); ok {
+		if err := tu.UnmarshalText([]byte(value)); err != nil {
+			return fmt.Errorf("error unmarshaling '%s' text as %T: %s", value, dest, err)
+		}
+
+		return nil
+	}
+
 	// Everything comes in by pointer, dereference it
 	v := reflect.Indirect(reflect.ValueOf(dest))
 


Test patch:
diff --git a/pkg/runtime/bindparam_test.go b/pkg/runtime/bindparam_test.go
index 0fda0b1..c7991a4 100644
--- a/pkg/runtime/bindparam_test.go
+++ b/pkg/runtime/bindparam_test.go
@@ -16,6 +16,7 @@ package runtime
 import (
 	"encoding/json"
 	"fmt"
+	"math/big"
 	"net/url"
 	"testing"
 	"time"
@@ -447,3 +448,13 @@ func TestBindParamsToExplodedObject(t *testing.T) {
 	assert.EqualValues(t, expectedDate, nTDstDate)
 
 }
+
+func TestBindStyledParameterWithLocation(t *testing.T) {
+	expectedBig := big.NewInt(12345678910)
+
+	var dstBigNumber big.Int
+	err := BindStyledParameterWithLocation("simple", false, "id", ParamLocationUndefined,
+		"12345678910", &dstBigNumber)
+	assert.NoError(t, err)
+	assert.Equal(t, *expectedBig, dstBigNumber)
+}
Repository: deepmap/oapi-codegen
Pull request #422 (2021-08-15 10:10:06)

fix: wrong command on README.md
replacing:  `oapi-generate`
with: `oapi-codegen`


Patch:
diff --git a/README.md b/README.md
index fad45ed..63e6ad0 100644
--- a/README.md
+++ b/README.md
@@ -184,7 +184,7 @@ func SetupHandler() {
 
 ```go
 type PetStoreImpl struct {}
-func (*PetStoreImpl) GetPets(r *http.Request, w *http.ResponseWriter) {
+func (*PetStoreImpl) GetPets(w http.ResponseWriter, r *http.Request) {
     // Implement me
 }
 
@@ -482,7 +482,7 @@ you can specify any combination of those.
  Go include paths. Please see below.
 
 So, for example, if you would like to produce only the server code, you could
-run `oapi-generate -generate types,server`. You could generate `types` and
+run `oapi-codegen -generate types,server`. You could generate `types` and
 `server` into separate files, but both are required for the server code.
 
 `oapi-codegen` can filter paths base on their tags in the openapi definition.
diff --git a/pkg/types/date.go b/pkg/types/date.go
index bdf94a9..ffc665c 100644
--- a/pkg/types/date.go
+++ b/pkg/types/date.go
@@ -28,3 +28,7 @@ func (d *Date) UnmarshalJSON(data []byte) error {
 	d.Time = parsed
 	return nil
 }
+
+func (d Date) String() string {
+	return d.Time.Format(DateFormat)
+}


Test patch:
diff --git a/internal/test/parameters/parameters.gen.go b/internal/test/parameters/parameters.gen.go
index e3f388f..dacf717 100644
--- a/internal/test/parameters/parameters.gen.go
+++ b/internal/test/parameters/parameters.gen.go
@@ -1500,13 +1500,13 @@ func NewGetStartingWithNumberRequest(server string, n1param string) (*http.Reque
 
 	operationPath := fmt.Sprintf("/startingWithNumber/%s", pathParam0)
 	if operationPath[0] == '/' {
-		operationPath = operationPath[1:]
-	}
-	operationURL := url.URL{
-		Path: operationPath,
+		operationPath = "." + operationPath
 	}
 
-	queryURL := serverURL.ResolveReference(&operationURL)
+	queryURL, err := serverURL.Parse(operationPath)
+	if err != nil {
+		return nil, err
+	}
 
 	req, err := http.NewRequest("GET", queryURL.String(), nil)
 	if err != nil {
@@ -2537,9 +2537,6 @@ func ParseGetStartingWithNumberResponse(rsp *http.Response) (*GetStartingWithNum
 		HTTPResponse: rsp,
 	}
 
-	switch {
-	}
-
 	return response, nil
 }
 
diff --git a/pkg/types/date_test.go b/pkg/types/date_test.go
index 18bfd4b..3d953be 100644
--- a/pkg/types/date_test.go
+++ b/pkg/types/date_test.go
@@ -2,6 +2,7 @@ package types
 
 import (
 	"encoding/json"
+	"fmt"
 	"testing"
 	"time"
 
@@ -30,3 +31,24 @@ func TestDate_UnmarshalJSON(t *testing.T) {
 	assert.NoError(t, err)
 	assert.Equal(t, testDate, b.DateField.Time)
 }
+
+func TestDate_Stringer(t *testing.T) {
+	t.Run("nil date", func(t *testing.T) {
+		var d *Date
+		assert.Equal(t, "<nil>", fmt.Sprintf("%v", d))
+	})
+
+	t.Run("ptr date", func(t *testing.T) {
+		d := &Date{
+			Time: time.Date(2019, 4, 1, 0, 0, 0, 0, time.UTC),
+		}
+		assert.Equal(t, "2019-04-01", fmt.Sprintf("%v", d))
+	})
+
+	t.Run("value date", func(t *testing.T) {
+		d := Date{
+			Time: time.Date(2019, 4, 1, 0, 0, 0, 0, time.UTC),
+		}
+		assert.Equal(t, "2019-04-01", fmt.Sprintf("%v", d))
+	})
+}
Repository: deepmap/oapi-codegen
Pull request #571 (2022-05-12 16:57:20)

Make UUID an alias of uuid.UUID
Instead of wrapping Google's `uuid.UUID`, and reimplementing the
JSON logic, simply make it an alias instead.

The current version already leaks the implementation detail, so I
don't see any reason to also wrap it, and make its usage harder.

Continuation of #546 and #556.


Patch:
diff --git a/pkg/types/uuid.go b/pkg/types/uuid.go
index 50515d8..1c11f38 100644
--- a/pkg/types/uuid.go
+++ b/pkg/types/uuid.go
@@ -1,27 +1,7 @@
 package types
 
 import (
-	"encoding/json"
-	"errors"
-
 	"github.com/google/uuid"
 )
 
-type UUID uuid.UUID
-
-func (u UUID) MarshalJSON() ([]byte, error) {
-	return json.Marshal(uuid.UUID(u).String())
-}
-
-func (u *UUID) UnmarshalJSON(data []byte) error {
-	var s string
-	if err := json.Unmarshal(data, &s); err != nil {
-		return err
-	}
-	parsed, err := uuid.Parse(s)
-	if err != nil {
-		return errors.New("uuid: failed to pass validation")
-	}
-	*u = UUID(parsed)
-	return nil
-}
+type UUID = uuid.UUID


Test patch:
diff --git a/pkg/types/uuid_test.go b/pkg/types/uuid_test.go
index 4ac689a..bb62040 100644
--- a/pkg/types/uuid_test.go
+++ b/pkg/types/uuid_test.go
@@ -25,7 +25,7 @@ func TestUUID_MarshalJSON_Pass(t *testing.T) {
 	b := struct {
 		UUIDField UUID `json:"uuid"`
 	}{
-		UUIDField: UUID(testUUID),
+		UUIDField: testUUID,
 	}
 	jsonBytes, err := json.Marshal(b)
 	assert.NoError(t, err)
@@ -42,7 +42,7 @@ func TestUUID_UnmarshalJSON_Fail(t *testing.T) {
 }
 
 func TestUUID_UnmarshalJSON_Pass(t *testing.T) {
-	testUUID := UUID(uuid.MustParse("9cb14230-b640-11ec-b909-0242ac120002"))
+	testUUID := uuid.MustParse("9cb14230-b640-11ec-b909-0242ac120002")
 	jsonStr := `{"uuid":"9cb14230-b640-11ec-b909-0242ac120002"}`
 	b := struct {
 		UUIDField UUID `json:"uuid"`
Repository: deepmap/oapi-codegen
Pull request #623 (2022-06-09 11:16:24)

Fix UUID query param binding
Fix for #616.

Adds a case to check if the destination object is an array and then tries to unmarshal using TextUnmarshaler (which UUID implements). If that fails, fallthrough to default.

leedsalex: @deepmap-marcinr Can you please merge this, it is affecting our project as well 

Patch:
diff --git a/pkg/runtime/bindstring.go b/pkg/runtime/bindstring.go
index 6af8c94..19ca08b 100644
--- a/pkg/runtime/bindstring.go
+++ b/pkg/runtime/bindstring.go
@@ -14,6 +14,7 @@
 package runtime
 
 import (
+	"encoding"
 	"errors"
 	"fmt"
 	"reflect"
@@ -85,6 +86,15 @@ func BindStringToObject(src string, dst interface{}) error {
 		if err == nil {
 			v.SetBool(val)
 		}
+	case reflect.Array:
+		if tu, ok := dst.(encoding.TextUnmarshaler); ok {
+			if err := tu.UnmarshalText([]byte(src)); err != nil {
+				return fmt.Errorf("error unmarshaling '%s' text as %T: %s", src, dst, err)
+			}
+
+			return nil
+		}
+		fallthrough
 	case reflect.Struct:
 		// if this is not of type Time or of type Date look to see if this is of type Binder.
 		if dstType, ok := dst.(Binder); ok {


Test patch:
diff --git a/pkg/runtime/bindstring_test.go b/pkg/runtime/bindstring_test.go
index e617404..42b3cab 100644
--- a/pkg/runtime/bindstring_test.go
+++ b/pkg/runtime/bindstring_test.go
@@ -169,4 +169,11 @@ func TestBindStringToObject(t *testing.T) {
 	var dstEmbeddedMockBinder EmbeddedMockBinder
 	assert.NoError(t, BindStringToObject(dateString, &dstEmbeddedMockBinder))
 	assert.EqualValues(t, dateString, dstEmbeddedMockBinder.Time.Format("2006-01-02"))
+
+	// Checks UUID binding
+	uuidString := "bbca1470-5e1f-4c64-ba99-fa7a6d2687b0"
+	var dstUUID types.UUID
+	assert.NoError(t, BindStringToObject(uuidString, &dstUUID))
+	assert.Equal(t, dstUUID.String(), uuidString)
+
 }
Repository: matrixorigin/matrixone
Pull request #5520 (2022-10-10 17:53:50)

report err when primary key contain no exist col
## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue #5402 #5464

## What this PR does / why we need it:


Patch:
diff --git a/pkg/sql/plan/build_ddl.go b/pkg/sql/plan/build_ddl.go
index d3cf43992..4ee479fa7 100644
--- a/pkg/sql/plan/build_ddl.go
+++ b/pkg/sql/plan/build_ddl.go
@@ -387,6 +387,11 @@ func buildTableDefs(defs tree.TableDefs, ctx CompilerContext, tableDef *TableDef
 	}
 
 	if len(primaryKeys) > 0 {
+		for _, primaryKey := range primaryKeys {
+			if _, ok := colNameMap[primaryKey]; !ok {
+				return moerr.NewInvalidInput("column '%s' doesn't exist in table", primaryKey)
+			}
+		}
 		if len(primaryKeys) == 1 {
 			tableDef.Defs = append(tableDef.Defs, &plan.TableDef_DefType{
 				Def: &plan.TableDef_DefType_Pk{


Test patch:
diff --git a/test/cases/dml/insert/insert.test b/test/cases/dml/insert/insert.test
index 128bc23c5..e8bc5f9e3 100755
--- a/test/cases/dml/insert/insert.test
+++ b/test/cases/dml/insert/insert.test
@@ -113,4 +113,8 @@ drop table if exists t1;
 create table t1(a int, b int, c int);
 insert into t1 values(1, 2, 3) on duplicate key update a=5;
 insert into t1 values(1, 2, 3) on duplicate key update a=5, b=6, c=7;
-insert into t1 values(1, 2, 3) on duplicate key update a=values(b)+values(c);
\ No newline at end of file
+insert into t1 values(1, 2, 3) on duplicate key update a=values(b)+values(c);
+
+drop table if exists t1;
+create table t1(a int, primary key(b));
+create table t1(a int, b int, primary key(b, c));
diff --git a/test/result/dml/insert/insert.result b/test/result/dml/insert/insert.result
index db465fb0d..c9e7b71ce 100755
--- a/test/result/dml/insert/insert.result
+++ b/test/result/dml/insert/insert.result
@@ -169,4 +169,9 @@ not supported: INSERT ... ON DUPLICATE KEY UPDATE ...
 insert into t1 values(1, 2, 3) on duplicate key update a=5, b=6, c=7;
 not supported: INSERT ... ON DUPLICATE KEY UPDATE ...
 insert into t1 values(1, 2, 3) on duplicate key update a=values(b)+values(c);
-not supported: INSERT ... ON DUPLICATE KEY UPDATE ...
\ No newline at end of file
+not supported: INSERT ... ON DUPLICATE KEY UPDATE ...
+drop table if exists t1;
+create table t1(a int, primary key(b));
+invalid input: column 'b' doesn't exist in table
+create table t1(a int, b int, primary key(b, c));
+invalid input: column 'c' doesn't exist in table
\ No newline at end of file
Repository: matrixorigin/matrixone
Pull request #5032 (2022-09-15 07:55:12)

support Single quotation mark when load with file
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue #4886 

## What this PR does / why we need it:
support Single quotation mark when load with file


Patch:
diff --git a/pkg/sql/colexec/external/external.go b/pkg/sql/colexec/external/external.go
index 27e46d1e0..5803fc084 100644
--- a/pkg/sql/colexec/external/external.go
+++ b/pkg/sql/colexec/external/external.go
@@ -213,9 +213,29 @@ func makeBatch(param *ExternalParam, plh *ParseLineHandler) *batch.Batch {
 	return batchData
 }
 
+func deleteEnclosed(param *ExternalParam, plh *ParseLineHandler) {
+	close := param.extern.Tail.Fields.EnclosedBy
+	if close == '"' || close == 0 {
+		return
+	}
+	for rowIdx := 0; rowIdx < plh.batchSize; rowIdx++ {
+		Line := plh.simdCsvLineArray[rowIdx]
+		for i := 0; i < len(Line); i++ {
+			len := len(Line[i])
+			if len < 2 {
+				continue
+			}
+			if Line[i][0] == close && Line[i][len-1] == close {
+				Line[i] = Line[i][1 : len-1]
+			}
+		}
+	}
+}
+
 func GetBatchData(param *ExternalParam, plh *ParseLineHandler, proc *process.Process) (*batch.Batch, error) {
 	bat := makeBatch(param, plh)
 	var Line []string
+	deleteEnclosed(param, plh)
 	for rowIdx := 0; rowIdx < plh.batchSize; rowIdx++ {
 		Line = plh.simdCsvLineArray[rowIdx]
 		if len(Line) < len(param.Attrs) {


Test patch:
diff --git a/pkg/sql/colexec/external/external_test.go b/pkg/sql/colexec/external/external_test.go
index 220405bc5..44e2547f1 100644
--- a/pkg/sql/colexec/external/external_test.go
+++ b/pkg/sql/colexec/external/external_test.go
@@ -323,6 +323,11 @@ func Test_GetBatchData(t *testing.T) {
 		param := &ExternalParam{
 			Attrs: atrrs,
 			Cols:  cols,
+			extern: &tree.ExternParam{
+				Tail: &tree.TailParameter{
+					Fields: &tree.Fields{},
+				},
+			},
 		}
 		param.Name2ColIndex = make(map[string]int32)
 		for i := 0; i < len(atrrs); i++ {