From 7e3f2421645acde470d0d51cad47733ccba9a796 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 04:33:25 +0000 Subject: [PATCH] fix(waiting_room_rules): define `body_param_name` for bulk rules endpoint (#3592) --- waiting_rooms/rule.go | 38 +++++++++++++++++++++++--------------- waiting_rooms/rule_test.go | 20 +++++++++++--------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/waiting_rooms/rule.go b/waiting_rooms/rule.go index d6658f36868..fce350263a5 100644 --- a/waiting_rooms/rule.go +++ b/waiting_rooms/rule.go @@ -206,8 +206,16 @@ func (r WaitingRoomRuleAction) IsKnown() bool { type RuleNewParams struct { // Identifier ZoneID param.Field[string] `path:"zone_id,required"` + Rules RuleNewParamsRules `json:"rules,required"` +} + +func (r RuleNewParams) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r.Rules) +} + +type RuleNewParamsRules struct { // The action to take when the expression matches. - Action param.Field[RuleNewParamsAction] `json:"action,required"` + Action param.Field[RuleNewParamsRulesAction] `json:"action,required"` // Criteria defining when there is a match for the current rule. Expression param.Field[string] `json:"expression,required"` // The description of the rule. @@ -216,20 +224,20 @@ type RuleNewParams struct { Enabled param.Field[bool] `json:"enabled"` } -func (r RuleNewParams) MarshalJSON() (data []byte, err error) { +func (r RuleNewParamsRules) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } // The action to take when the expression matches. -type RuleNewParamsAction string +type RuleNewParamsRulesAction string const ( - RuleNewParamsActionBypassWaitingRoom RuleNewParamsAction = "bypass_waiting_room" + RuleNewParamsRulesActionBypassWaitingRoom RuleNewParamsRulesAction = "bypass_waiting_room" ) -func (r RuleNewParamsAction) IsKnown() bool { +func (r RuleNewParamsRulesAction) IsKnown() bool { switch r { - case RuleNewParamsActionBypassWaitingRoom: + case RuleNewParamsRulesActionBypassWaitingRoom: return true } return false @@ -314,16 +322,16 @@ func (r ruleNewResponseEnvelopeResultInfoJSON) RawJSON() string { type RuleUpdateParams struct { // Identifier ZoneID param.Field[string] `path:"zone_id,required"` - Body []RuleUpdateParamsBody `json:"body,required"` + Rules []RuleUpdateParamsRule `json:"rules,required"` } func (r RuleUpdateParams) MarshalJSON() (data []byte, err error) { - return apijson.MarshalRoot(r.Body) + return apijson.MarshalRoot(r.Rules) } -type RuleUpdateParamsBody struct { +type RuleUpdateParamsRule struct { // The action to take when the expression matches. - Action param.Field[RuleUpdateParamsBodyAction] `json:"action,required"` + Action param.Field[RuleUpdateParamsRulesAction] `json:"action,required"` // Criteria defining when there is a match for the current rule. Expression param.Field[string] `json:"expression,required"` // The description of the rule. @@ -332,20 +340,20 @@ type RuleUpdateParamsBody struct { Enabled param.Field[bool] `json:"enabled"` } -func (r RuleUpdateParamsBody) MarshalJSON() (data []byte, err error) { +func (r RuleUpdateParamsRule) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } // The action to take when the expression matches. -type RuleUpdateParamsBodyAction string +type RuleUpdateParamsRulesAction string const ( - RuleUpdateParamsBodyActionBypassWaitingRoom RuleUpdateParamsBodyAction = "bypass_waiting_room" + RuleUpdateParamsRulesActionBypassWaitingRoom RuleUpdateParamsRulesAction = "bypass_waiting_room" ) -func (r RuleUpdateParamsBodyAction) IsKnown() bool { +func (r RuleUpdateParamsRulesAction) IsKnown() bool { switch r { - case RuleUpdateParamsBodyActionBypassWaitingRoom: + case RuleUpdateParamsRulesActionBypassWaitingRoom: return true } return false diff --git a/waiting_rooms/rule_test.go b/waiting_rooms/rule_test.go index 69be96d739e..7d59d6fb099 100644 --- a/waiting_rooms/rule_test.go +++ b/waiting_rooms/rule_test.go @@ -31,11 +31,13 @@ func TestRuleNewWithOptionalParams(t *testing.T) { context.TODO(), "699d98642c564d2e855e9661899b7252", waiting_rooms.RuleNewParams{ - ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), - Action: cloudflare.F(waiting_rooms.RuleNewParamsActionBypassWaitingRoom), - Expression: cloudflare.F("ip.src in {10.20.30.40}"), - Description: cloudflare.F("allow all traffic from 10.20.30.40"), - Enabled: cloudflare.F(true), + ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), + Rules: waiting_rooms.RuleNewParamsRules{ + Action: cloudflare.F(waiting_rooms.RuleNewParamsRulesActionBypassWaitingRoom), + Expression: cloudflare.F("ip.src in {10.20.30.40}"), + Description: cloudflare.F("allow all traffic from 10.20.30.40"), + Enabled: cloudflare.F(true), + }, }, ) if err != nil { @@ -65,18 +67,18 @@ func TestRuleUpdate(t *testing.T) { "699d98642c564d2e855e9661899b7252", waiting_rooms.RuleUpdateParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), - Body: []waiting_rooms.RuleUpdateParamsBody{{ - Action: cloudflare.F(waiting_rooms.RuleUpdateParamsBodyActionBypassWaitingRoom), + Rules: []waiting_rooms.RuleUpdateParamsRule{{ + Action: cloudflare.F(waiting_rooms.RuleUpdateParamsRulesActionBypassWaitingRoom), Expression: cloudflare.F("ip.src in {10.20.30.40}"), Description: cloudflare.F("allow all traffic from 10.20.30.40"), Enabled: cloudflare.F(true), }, { - Action: cloudflare.F(waiting_rooms.RuleUpdateParamsBodyActionBypassWaitingRoom), + Action: cloudflare.F(waiting_rooms.RuleUpdateParamsRulesActionBypassWaitingRoom), Expression: cloudflare.F("ip.src in {10.20.30.40}"), Description: cloudflare.F("allow all traffic from 10.20.30.40"), Enabled: cloudflare.F(true), }, { - Action: cloudflare.F(waiting_rooms.RuleUpdateParamsBodyActionBypassWaitingRoom), + Action: cloudflare.F(waiting_rooms.RuleUpdateParamsRulesActionBypassWaitingRoom), Expression: cloudflare.F("ip.src in {10.20.30.40}"), Description: cloudflare.F("allow all traffic from 10.20.30.40"), Enabled: cloudflare.F(true),