go-openapi / runtime

openapi runtime interfaces
Apache License 2.0
248 stars 148 forks source link

Refactor newRequest function to remove error return value #312

Closed s4s7 closed 8 months ago

s4s7 commented 8 months ago

Summary

This PR refactors the newRequest function in the Swagger HTTP client to remove the error return value, as it is unnecessary. The function does not perform any operations that can result in an error, so the error return value has been removed for simplicity and clarity.

Changes

Before:

func newRequest(method, pathPattern string, writer runtime.ClientRequestWriter) (*request, error) {
    return &request{
        pathPattern: pathPattern,
        method:      method,
        writer:      writer,
        header:      make(http.Header),
        query:       make(url.Values),
        timeout:     DefaultTimeout,
        getBody:     getRequestBuffer,
    }, nil
}

After:

func newRequest(method, pathPattern string, writer runtime.ClientRequestWriter) *request {
    return &request{
        pathPattern: pathPattern,
        method:      method,
        writer:      writer,
        header:      make(http.Header),
        query:       make(url.Values),
        timeout:     DefaultTimeout,
        getBody:     getRequestBuffer,
    }
}

Rationale

Removing the error return value simplifies the function signature and makes it clear that the function does not generate any errors that need to be handled. This change enhances the readability and maintainability of the code.

codecov[bot] commented 8 months ago

Codecov Report

Attention: Patch coverage is 66.66667% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 81.88%. Comparing base (91a8d68) to head (1cc63fa). Report is 8 commits behind head on master.

Files Patch % Lines
client/runtime.go 50.00% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #312 +/- ## ========================================== + Coverage 81.67% 81.88% +0.20% ========================================== Files 49 49 Lines 4066 3351 -715 ========================================== - Hits 3321 2744 -577 + Misses 632 495 -137 + Partials 113 112 -1 ``` | [Flag](https://app.codecov.io/gh/go-openapi/runtime/pull/312/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-openapi) | Coverage Δ | | |---|---|---| | [1.19](https://app.codecov.io/gh/go-openapi/runtime/pull/312/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-openapi) | `81.88% <66.66%> (+0.20%)` | :arrow_up: | | [oldstable](https://app.codecov.io/gh/go-openapi/runtime/pull/312/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-openapi) | `81.88% <66.66%> (+0.20%)` | :arrow_up: | | [stable](https://app.codecov.io/gh/go-openapi/runtime/pull/312/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-openapi) | `81.88% <66.66%> (+0.20%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-openapi#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.