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

chore: add CreateHttpRequest #242

Merged
merged 1 commit into from
Apr 28, 2022
Merged
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
32 changes: 24 additions & 8 deletions client/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,20 +358,19 @@ func (r *Runtime) EnableConnectionReuse() {
)
}

// Submit a request and when there is a body on success it will turn that into the result
// all other things are turned into an api error for swagger which retains the status code
func (r *Runtime) Submit(operation *runtime.ClientOperation) (interface{}, error) {
params, readResponse, auth := operation.Params, operation.Reader, operation.AuthInfo
// takes a client operation and creates equivalent http.Request
func (r *Runtime) createHttpRequest(operation *runtime.ClientOperation) (*request, *http.Request, error) {
params, _, auth := operation.Params, operation.Reader, operation.AuthInfo

request, err := newRequest(operation.Method, operation.PathPattern, params)
if err != nil {
return nil, err
return nil, nil, err
}

var accept []string
accept = append(accept, operation.ProducesMediaTypes...)
if err = request.SetHeaderParam(runtime.HeaderAccept, accept...); err != nil {
return nil, err
return nil, nil, err
}

if auth == nil && r.DefaultAuthentication != nil {
Expand Down Expand Up @@ -399,16 +398,33 @@ func (r *Runtime) Submit(operation *runtime.ClientOperation) (interface{}, error
}

if _, ok := r.Producers[cmt]; !ok && cmt != runtime.MultipartFormMime && cmt != runtime.URLencodedFormMime {
return nil, fmt.Errorf("none of producers: %v registered. try %s", r.Producers, cmt)
return nil, nil, fmt.Errorf("none of producers: %v registered. try %s", r.Producers, cmt)
}

req, err := request.buildHTTP(cmt, r.BasePath, r.Producers, r.Formats, auth)
if err != nil {
return nil, err
return nil, nil, err
}
req.URL.Scheme = r.pickScheme(operation.Schemes)
req.URL.Host = r.Host
req.Host = r.Host
return request, req, nil
}

func (r *Runtime) CreateHttpRequest(operation *runtime.ClientOperation) (req *http.Request, err error) {
_, req, err = r.createHttpRequest(operation)
return
}

// Submit a request and when there is a body on success it will turn that into the result
// all other things are turned into an api error for swagger which retains the status code
func (r *Runtime) Submit(operation *runtime.ClientOperation) (interface{}, error) {
_, readResponse, _ := operation.Params, operation.Reader, operation.AuthInfo

request, req, err := r.createHttpRequest(operation)
if err != nil {
return nil, err
}

r.clientOnce.Do(func() {
r.client = &http.Client{
Expand Down