Repository: deepmap/oapi-codegen
Pull request #410 (2021-07-24 14:57:36)

fix: regenerate parameters.gen.go
This PR just regenerates `parameters.gen.go` .

CI failed on master branch because committed `parameters.gen.go` was different from generated one. The reason for this is that #402 was merged without being rebased after #387 and #396.


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))
+	})
+}