-
Notifications
You must be signed in to change notification settings - Fork 114
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
Allow empty content type on DELETE
#73
Conversation
We recently added checks in `stripe-mock` to make sure that the right `Content-Type` was being sent. Unfortunately, the logic was not quite right for deletes, where you occasionally see a `Content-Type` in rare cases, but which usually have empty request bodies, and therefore an empty `Content-Type` is allowed. This patch brings in two fixes: 1. The OpenAPI spec has been tweak so as to not incorrectly include `expand` parameters on `DELETE` operations. This means that most `DELETE` operations have no defined request schema at all. 2. Special cases incoming `DELETE` operations so that they can be checked against a schema if they provide parameters, but are also allowed to specify an empty `Content-Type` as well. Between the two improvements, all edges should be covered. The impetus here is to resolve [1] where a `stripe-mock` upgrade is incompatible with the current code. I've verified that with this patch included, `stripe-python`'s test suite runs successfully. [1] stripe/stripe-python#426
@@ -83,14 +83,26 @@ func initTestSpec() { | |||
Content: map[string]spec.MediaType{ | |||
"application/json": { | |||
Schema: &spec.Schema{ | |||
Ref: "#/components/schemas/customer", | |||
Ref: "#/components/schemas/charge", |
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.
This tweaks is an unrelated fix.
// Firstly, `Content-Type` is checked against the schema's media type, then | ||
// string-encoded parameters are coerced to expected types (where possible). | ||
// Finally, we validate the incoming payload against the schema. | ||
func validateAndCoerceRequest( |
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.
Most of this code is the same, but for cleanliness I've pulled it into its own function.
@@ -178,7 +186,7 @@ func TestStubServer_RoutesRequest(t *testing.T) { | |||
&http.Request{Method: "POST", | |||
URL: &url.URL{Path: "/v1/invoices/in_123/pay"}}) | |||
assert.NotNil(t, route) | |||
assert.Equal(t, chargeDeleteMethod, route.operation) | |||
assert.Equal(t, invoicePayMethod, route.operation) |
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.
My tweaks to the test fixtures revealed that these were previously wrong, so they've also been fixed.
Going to self-approve this one so we can start closing out these upgrades: LGTM. |
See the fix here: stripe/stripe-mock#73
See the fix here: stripe/stripe-mock#73
We recently added checks in
stripe-mock
to make sure that the rightContent-Type
was being sent. Unfortunately, the logic was not quiteright for deletes, where you occasionally see a
Content-Type
in rarecases, but which usually have empty request bodies, and therefore an
empty
Content-Type
is allowed.This patch brings in two fixes:
expand
parameters onDELETE
operations. This means that mostDELETE
operations have no defined request schema at all.DELETE
operations so that they can bechecked against a schema if they provide parameters, but are also
allowed to specify an empty
Content-Type
as well.Between the two improvements, all edges should be covered.
The impetus here is to resolve [1] where a
stripe-mock
upgrade isincompatible with the current code. I've verified that with this patch
included,
stripe-python
's test suite runs successfully.[1] stripe/stripe-python#426