Skip to content

Fix OneOf type templates when property types differ #234

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

Merged
merged 4 commits into from
Sep 18, 2024

Conversation

karencfv
Copy link
Collaborator

@karencfv karencfv commented Sep 18, 2024

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: #233

@karencfv karencfv changed the title Fix OneOf type templates when types differ Fix OneOf type templates when property types differ Sep 18, 2024
@karencfv karencfv merged commit 7b8deef into oxidecomputer:main Sep 18, 2024
1 check passed
@karencfv karencfv deleted the fix-oneof branch September 18, 2024 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

oneOf subtypes not linked correctly to parent type
1 participant