Skip to content

Commit cca860b

Browse files
author
Marcin Romaszewicz
committed
Client code generation
Generate some client side wrappers from an OpenAPI specification which conform to the server side.
1 parent 3e48e0d commit cca860b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

request_helpers.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"encoding/json"
2929
"fmt"
3030
"io"
31+
"net/http"
3132
"net/http/httptest"
3233
"strings"
3334
"testing"
@@ -48,6 +49,7 @@ type RequestBuilder struct {
4849
Headers map[string]string
4950
Body []byte
5051
Error error
52+
Cookies []*http.Cookie
5153
}
5254

5355
// Path operations
@@ -113,6 +115,16 @@ func (r *RequestBuilder) WithJsonBody(obj interface{}) *RequestBuilder {
113115
return r.WithJsonContentType()
114116
}
115117

118+
// Cookie operations
119+
func (r *RequestBuilder) WithCookie(c *http.Cookie) *RequestBuilder {
120+
r.Cookies = append(r.Cookies, c)
121+
return r
122+
}
123+
124+
func (r *RequestBuilder) WithCookieNameValue(name, value string) *RequestBuilder {
125+
return r.WithCookie(&http.Cookie{Name: name, Value: value})
126+
}
127+
116128
// This function performs the request, it takes a pointer to a testing context
117129
// to print messages, and a pointer to an echo context for request handling.
118130
func (r *RequestBuilder) Go(t *testing.T, e *echo.Echo) *CompletedRequest {
@@ -130,6 +142,10 @@ func (r *RequestBuilder) Go(t *testing.T, e *echo.Echo) *CompletedRequest {
130142
for h, v := range r.Headers {
131143
req.Header.Add(h, v)
132144
}
145+
for _, c := range r.Cookies {
146+
req.AddCookie(c)
147+
}
148+
133149
rec := httptest.NewRecorder()
134150
e.ServeHTTP(rec, req)
135151

0 commit comments

Comments
 (0)