oxidecomputer / oxide.go

The Go SDK for Oxide.
Mozilla Public License 2.0
17 stars 3 forks source link

Fix OneOf type templates when property types differ #234

Closed karencfv closed 1 month ago

karencfv commented 1 month ago

Overview

A few of our OpenAPI OneOf types contain properties that are of different types. These were not handled properly, as the generator would take the first property type only and set that as the expected type. Sadly this impacted only a single type as the others had been set as string which the JSON decoder happily used. This commit contains a fix for said situation.

Fix

All struct field types that have different property types in the OpenAPI spec have now been set to any.

Manual testing

I have tested manually against a rack by running the following code

func main() {
    client, err := oxide.NewClient(nil)
    if err != nil {
        panic(err)
    }

    startTime, err := time.Parse(time.RFC3339, "2024-09-17T06:25:23.696Z")
    if err != nil {
        panic(err)
    }

    endTime := time.Now()

    ctx := context.Background()
    params := oxide.DiskMetricsListParams{
        Disk:      oxide.NameOrId("5cea3d86-cb2a-43b1-bd3a-2a487b048f44"),
        Metric:    oxide.DiskMetricNameReadBytes,
        Limit:     3,
        StartTime: &startTime,
        EndTime:   &endTime,
    }

    resp, err := client.DiskMetricsList(ctx, params)
    if err != nil {
        panic(err)
    }

    fmt.Printf("%+v\n", resp)
}

The results were as expected

$ go run main.go
&{Items:[{Datum:{Datum:map[start_time:2024-09-18T06:24:22.956977316Z value:1.41800448e+08] Type:cumulative_i64} Timestamp:2024-09-18 06:24:53.186026344 +0000 UTC} {Datum:{Datum:map[start_time:2024-09-18T06:24:22.956977316Z value:1.4213632e+08] Type:cumulative_i64} Timestamp:2024-09-18 06:25:23.187327342 +0000 UTC} {Datum:{Datum:map[start_time:2024-09-18T06:24:22.956977316Z value:1.4213632e+08] Type:cumulative_i64} Timestamp:2024-09-18 06:25:53.188840965 +0000 UTC}] NextPage:eyJ2IjoidjEiLCJwYWdlX3N0YXJ0Ijp7InN0YXJ0X3RpbWUiOiIyMDI0LTA5LTE4VDA2OjI1OjUzLjE4ODg0MDk2NVoiLCJlbmRfdGltZSI6IjIwMjQtMDktMThUMDY6NTM6MDJaIiwib3JkZXIiOm51bGx9fQ==}

Closes: https://github.com/oxidecomputer/oxide.go/issues/233