-
Notifications
You must be signed in to change notification settings - Fork 460
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
Put /v1/
prefix as part of all paths instead of URL
#734
Conversation
Is that supposed to be a prefix or a suffix? If I pass in a URL of |
@oralordos Hah, great catch. I was just writing a test and realized that I got this backwards as it failed ... pushing a fix momentarily. |
0a306b2
to
caa5329
Compare
Alright, I corrected the patch, amended the commit message/description above, added support for trimming func TestGetBackendWithConfig_TrimV1Suffix(t *testing.T) {
{
backend := stripe.GetBackendWithConfig(
stripe.APIBackend,
&stripe.BackendConfig{
URL: "https://api.stripe.com/v1",
},
).(*stripe.BackendImplementation)
// The `/v1` suffix has been stripped.
assert.Equal(t, "https://api.stripe.com", backend.URL)
}
// Also support trimming a `/v1/` with an extra trailing slash which is
// probably an often seen mistake.
{
backend := stripe.GetBackendWithConfig(
stripe.APIBackend,
&stripe.BackendConfig{
URL: "https://api.stripe.com/v1/",
},
).(*stripe.BackendImplementation)
assert.Equal(t, "https://api.stripe.com", backend.URL)
}
// No-op otherwise.
{
backend := stripe.GetBackendWithConfig(
stripe.APIBackend,
&stripe.BackendConfig{
URL: "https://api.stripe.com",
},
).(*stripe.BackendImplementation)
assert.Equal(t, "https://api.stripe.com", backend.URL)
}
} |
caa5329
to
8365214
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one minor comment but lgtm otherwise
}, | ||
).(*stripe.BackendImplementation) | ||
|
||
assert.Equal(t, "https://api.stripe.com", backend.URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor but should we also trim the trailing slash so that if you pass https://api.stripe.com/
it works too? And similarly ensure there's a leading slash in the other part of the url passed from CallRaw
? Does not seem like a big deal but I know I've hit that before and since we're already trying to be useful.
Traditionally, stripe-go has done something a little weird in that it considered the `/v1/` in API URLs as part of the URL (e.g., `APIURL` or `UploadURL`) instead of part of the paths of individual API calls. So when calling `POST /v1/charges` we'd call `POST /charges` and rely on the fact that `/v1/` was expected to be present in the URL. This has always rubbed me the wrong way a little bit, and caused a little bit of trouble in #733 as we'd been doing something a little hacky when initializing new configs for backends. This has some potential backwards compatibility problems in that people may have been injecting custom URLs (e.g., if they had a testing setup a little like we do for stripe-mock) that included the `/v1/` suffix. I've tried to address this by trimming a `/v1/` suffix when creating a backend with a configured URL. For example: ``` go switch backendType { case APIBackend: if config.URL == "" { config.URL = apiURL } // For a long time we had the `/v1` suffix as part of a configured URL // rather than in the per-package URLs throughout the library. Continue // to support this for the time being by stripping one that's been // passed for better backwards compatibility. config.URL = strings.TrimSuffix(config.URL, "/v1") config.URL = strings.TrimSuffix(config.URL, "/v1/") ``` I believe that will address the problem. There's some risk that I missed a URL string in the project because there are a lot of them. I tried to minimize the risk there by using a tool-assisted project-wide find + replace, then manually examining every string in the project that looks like a URL path (e.g., starts with `"/`).
8365214
to
4d38e82
Compare
Great point! We can nicen up this code quite a bit by just (1) trimming a trailing slash, then (2) trimming just
Good point. I left this out for now only because we seem to already be compensating for that possibility in
I'd actually prefer that this become a |
Released as 54.2.0. |
* updated rest service to pull data specified in github issue * completed logic to get initial orders and order amendments * updated test class to test rest service additions * moved functions to helpers based on PR comments * conditional logic fix * updated queries to be more performant based on PR comments * update to test class * reworking nested if structures * removing code based on pr comments and further restructure of if statements * added force api version * restructured order amendment and initial order queries modified rest service to get order amendments and initial order data before fetching related data * updated test classes and clean up * updates for non cpq test org Co-authored-by: Brennen Ryder <[email protected]>
Traditionally, stripe-go has done something a little weird in that it
considered the
/v1/
in API URLs as part of the URL (e.g.,APIURL
orUploadURL
) instead of part of the paths of individual API calls. Sowhen calling
POST /v1/charges
we'd callPOST /charges
and rely onthe fact that
/v1/
was expected to be present in the URL.This has always rubbed me the wrong way a little bit, and caused a
little bit of trouble in #733 as we'd been doing something a little
hacky when initializing new configs for backends.
This has some potential backwards compatibility problems in that people
may have been injecting custom URLs (e.g., if they had a testing setup a
little like we do for stripe-mock) that included the
/v1/
suffix. I'vetried to address this by trimming a
/v1/
suffix when creating abackend with a configured URL. For example:
I believe that will address the problem.
There's some risk that I missed a URL string in the project because
there are a lot of them. I tried to minimize the risk there by using a
tool-assisted project-wide find + replace, then manually examining every
string in the project that looks like a URL path (e.g., starts with
"/
).r? @remi-stripe Any thoughts on this?
cc @stripe-internal/api-libraries