stytchauth / stytch-go

Official Stytch Backend SDK for Go
MIT License
47 stars 10 forks source link

Use pointer types for Go optional structs #136

Closed logan-stytch closed 1 year ago

logan-stytch commented 1 year ago

This would be a breaking change (and push us to v11), but would uniformly fix issues like the one reported today of the unwieldiness of certain search operations.

Organizations.Search() currently has the problem that a Query must be given or it fails to be parsed properly. For example, this is totally valid in cURL:

curl -X POST --url https://test.stytch.com/v1/b2b/organizations/search \
    -H "Content-Type: application/json" \
    -u "$projectID:$secret"

but this fails in the Go SDK:

    client, err := b2bstytchapi.NewClient("project-id", "secret")
    if err != nil {
        panic(err)
    }

    params := &members.SearchParams{
        OrganizationIds: []string{"organization-id"},
    }

    response, err := client.Organizations.Members.Search(context.Background(), params)
    if err != nil {
        panic(err)
    }

    fmt.Println(response)

We had already special-cased Users.Search, but it doesn't address the underlying issue: there are a number of types that should be pointers that instead get sent as "zero structs" and then misinterpreted by the API.

Testing

On v11, the code above succeeds:

    client, err := b2bstytchapi.NewClient("project-id", "secret")
    if err != nil {
        panic(err)
    }

    params := &members.SearchParams{
        OrganizationIds: []string{"organization-id"},
    }

    response, err := client.Organizations.Members.Search(context.Background(), params)
    if err != nil {
        panic(err)
    }

    fmt.Println(response)