Repository: cloudflare/cloudflare-go (go)

Issue:
Attempts to create a pool with 0 origins will always fail
### Confirmation

- [X] My issue isn't already found on the issue tracker.
- [X] I have replicated my issue using the latest version of the library and it is still present.

### cloudflare-go version

v0.72.0

### Go environment

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/kelvin/Library/Caches/go-build"
GOENV="/Users/kelvin/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/kelvin/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/kelvin/go"
GOPRIVATE=""
GOROOT="/opt/homebrew/Cellar/go/1.20.5/libexec"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.5/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.5"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z1/4lpjdpw96m12m3xgtvvl3m1r0000gn/T/go-build158583462=/tmp/go-build -gno-record-gcc-switches -fno-common"

### Expected output

Pool created successfully

### Actual output

error: the minimum_origins must be in range [1, 0]: validation failed (1002)


### Code demonstrating the issue
```
package main

import (
	"context"
	"fmt"
	"github.com/cloudflare/cloudflare-go"
)

func main() {
	api, err := cloudflare.New("<redacted>", "<redacted>")
	if err != nil {
		panic(err)
	}
	accountId := cloudflare.AccountIdentifier("<redacted>")
	testPool := cloudflare.LoadBalancerPool{
		Description:    "Primary data center - Provider XYZ",
		Name:           "primary-dc-1",
		Enabled:        true,
		MinimumOrigins: 0,
		Origins:        []cloudflare.LoadBalancerOrigin{},
	}
	createPoolParams := cloudflare.CreateLoadBalancerPoolParams{LoadBalancerPool: testPool}
	pool, err := api.CreateLoadBalancerPool(context.Background(), accountId, createPoolParams)
	if err != nil {
		panic(err)
	}
	fmt.Printf("pool: %+v\n", pool)
}
```

### Steps to reproduce

Create a pool with no origins and MinimumOrigins set to 0

### References

_No response_

Pull request:
Fixing bug with minimumOrigins=0
Provide a general summary of your changes in the title above. You should
remove this overview, any sections and any section descriptions you
don't need below before submitting. There isn't a strict requirement to
use this template if you can structure your description and still cover
these points.

## Description

Closes #1337

## Has your change been tested?

Confirmed pool gets created properly with the code snippet from issue #1337

## Screenshots (if appropriate):

## Types of changes

What sort of change does your code introduce/modify?

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)

Folks will have to use a int pointer for minimumOrigins instead of int for LoadBalancerPool.

## Checklist:

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [ ] This change is using publicly documented in [cloudflare/api-schemas](https://github.com/cloudflare/api-schemas) 
      and relies on stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/


Patch:
diff --git a/.changelog/1338.txt b/.changelog/1338.txt
new file mode 100644
index 000000000..ce00f1f98
--- /dev/null
+++ b/.changelog/1338.txt
@@ -0,0 +1,3 @@
+```release-note:bug
+load_balancing: Fix pool creation with MinimumOrigins set to 0
+```
diff --git a/load_balancing.go b/load_balancing.go
index 4f6422d07..dbbcd6b2d 100644
--- a/load_balancing.go
+++ b/load_balancing.go
@@ -17,7 +17,7 @@ type LoadBalancerPool struct {
 	Description       string                      `json:"description"`
 	Name              string                      `json:"name"`
 	Enabled           bool                        `json:"enabled"`
-	MinimumOrigins    int                         `json:"minimum_origins,omitempty"`
+	MinimumOrigins    *int                        `json:"minimum_origins,omitempty"`
 	Monitor           string                      `json:"monitor,omitempty"`
 	Origins           []LoadBalancerOrigin        `json:"origins"`
 	NotificationEmail string                      `json:"notification_email,omitempty"`


Test patch:
diff --git a/load_balancing_test.go b/load_balancing_test.go
index cef7d1b5d..2bed0cab9 100644
--- a/load_balancing_test.go
+++ b/load_balancing_test.go
@@ -115,7 +115,7 @@ func TestCreateLoadBalancerPool(t *testing.T) {
 		Description:    "Primary data center - Provider XYZ",
 		Name:           "primary-dc-1",
 		Enabled:        true,
-		MinimumOrigins: 1,
+		MinimumOrigins: IntPtr(1),
 		Monitor:        "f1aba936b94213e5b8dca0c0dbf1f9cc",
 		Latitude:       fptr(55),
 		Longitude:      fptr(-12.5),
@@ -183,6 +183,71 @@ func TestCreateLoadBalancerPool(t *testing.T) {
 	}
 }
 
+func TestCreateLoadBalancerPool_MinimumOriginsZero(t *testing.T) {
+	setup()
+	defer teardown()
+
+	handler := func(w http.ResponseWriter, r *http.Request) {
+		assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
+		w.Header().Set("content-type", "application/json")
+		b, err := io.ReadAll(r.Body)
+		defer r.Body.Close()
+		if assert.NoError(t, err) {
+			assert.JSONEq(t, `{
+              "description": "Primary data center - Provider XYZ",
+              "name": "primary-dc-2",
+              "minimum_origins": 0,
+              "enabled": true,
+              "check_regions": null,
+              "origins": null
+            }`, string(b))
+		}
+		fmt.Fprint(w, `{
+            "success": true,
+            "errors": [],
+            "messages": [],
+            "result": {
+              "description": "Primary data center - Provider XYZ",
+              "created_on": "2014-01-01T05:20:00.12345Z",
+              "modified_on": "2014-02-01T05:20:00.12345Z",
+              "id": "f6fea70e5154b4c563bd549ef405b7d7",
+              "enabled": true,
+              "minimum_origins": 0,
+              "name": "primary-dc-2",
+              "notification_email": "",
+              "check_regions": null,
+              "origins": []
+            }
+        }`)
+	}
+
+	mux.HandleFunc("/accounts/"+testAccountID+"/load_balancers/pools", handler)
+	createdOn, _ := time.Parse(time.RFC3339, "2014-01-01T05:20:00.12345Z")
+	modifiedOn, _ := time.Parse(time.RFC3339, "2014-02-01T05:20:00.12345Z")
+	want := LoadBalancerPool{
+		ID:                "f6fea70e5154b4c563bd549ef405b7d7",
+		CreatedOn:         &createdOn,
+		ModifiedOn:        &modifiedOn,
+		Description:       "Primary data center - Provider XYZ",
+		Name:              "primary-dc-2",
+		Enabled:           true,
+		MinimumOrigins:    IntPtr(0),
+		Origins:           []LoadBalancerOrigin{},
+		NotificationEmail: "",
+	}
+	request := LoadBalancerPool{
+		Description:    "Primary data center - Provider XYZ",
+		Name:           "primary-dc-2",
+		Enabled:        true,
+		MinimumOrigins: IntPtr(0),
+	}
+
+	actual, err := client.CreateLoadBalancerPool(context.Background(), AccountIdentifier(testAccountID), CreateLoadBalancerPoolParams{LoadBalancerPool: request})
+	if assert.NoError(t, err) {
+		assert.Equal(t, want, actual)
+	}
+}
+
 func TestCreateLoadBalancerPool_ZoneIsNotSupported(t *testing.T) {
 	setup()
 	defer teardown()