Skip to content

misc: sort type properties before generating.#320

Merged
jmcarp merged 1 commit intomainfrom
jmcarp/sort-types
Aug 18, 2025
Merged

misc: sort type properties before generating.#320
jmcarp merged 1 commit intomainfrom
jmcarp/sort-types

Conversation

@jmcarp
Copy link
Contributor

@jmcarp jmcarp commented Aug 15, 2025

In order to support deterministic generated code, sort the keys in the type properties map before generating.

@jmcarp jmcarp requested a review from a team as a code owner August 15, 2025 15:25
@jmcarp
Copy link
Contributor Author

jmcarp commented Aug 15, 2025

Testing locally. First, generate the sdk multiple types, and print diffs if found:

❯ for ix in {1..10}; do echo $ix; make generate >/dev/null; git diff --exit-code; done

1
2
3
4
5
6
7
8
9
10

Doing the same thing on main:

❯ for ix in {1..10}; do echo $ix; make generate >/dev/null; git diff --exit-code; done

1
2
diff --git a/oxide/types.go b/oxide/types.go
index 5911f85..528188d 100644
--- a/oxide/types.go
+++ b/oxide/types.go
@@ -201,9 +201,6 @@ type AffinityGroupCreate struct {
 	Policy AffinityPolicy `json:"policy,omitempty" yaml:"policy,omitempty"`
 }
 
-// AffinityGroupMemberType is the type definition for a AffinityGroupMemberType.
-type AffinityGroupMemberType string
-
 // AffinityGroupMemberValue is the type definition for a AffinityGroupMemberValue.
 //
 // Required fields:
@@ -223,6 +220,9 @@ type AffinityGroupMemberValue struct {
 	RunState InstanceState `json:"run_state,omitempty" yaml:"run_state,omitempty"`
 }
 
+// AffinityGroupMemberType is the type definition for a AffinityGroupMemberType.
+type AffinityGroupMemberType string
+
 // AffinityGroupMemberInstance is an instance belonging to this group
 //
 // Instances can belong to up to 16 affinity groups.
3
4
5
6
7
8
diff --git a/oxide/types.go b/oxide/types.go
index 5911f85..528188d 100644
--- a/oxide/types.go
+++ b/oxide/types.go
@@ -201,9 +201,6 @@ type AffinityGroupCreate struct {
 	Policy AffinityPolicy `json:"policy,omitempty" yaml:"policy,omitempty"`
 }
 
-// AffinityGroupMemberType is the type definition for a AffinityGroupMemberType.
-type AffinityGroupMemberType string
-
 // AffinityGroupMemberValue is the type definition for a AffinityGroupMemberValue.
 //
 // Required fields:
@@ -223,6 +220,9 @@ type AffinityGroupMemberValue struct {
 	RunState InstanceState `json:"run_state,omitempty" yaml:"run_state,omitempty"`
 }
 
+// AffinityGroupMemberType is the type definition for a AffinityGroupMemberType.
+type AffinityGroupMemberType string
+
 // AffinityGroupMemberInstance is an instance belonging to this group
 //
 // Instances can belong to up to 16 affinity groups.
9
10
diff --git a/oxide/types.go b/oxide/types.go
index 5911f85..528188d 100644
--- a/oxide/types.go
+++ b/oxide/types.go
@@ -201,9 +201,6 @@ type AffinityGroupCreate struct {
 	Policy AffinityPolicy `json:"policy,omitempty" yaml:"policy,omitempty"`
 }
 
-// AffinityGroupMemberType is the type definition for a AffinityGroupMemberType.
-type AffinityGroupMemberType string
-
 // AffinityGroupMemberValue is the type definition for a AffinityGroupMemberValue.
 //
 // Required fields:
@@ -223,6 +220,9 @@ type AffinityGroupMemberValue struct {
 	RunState InstanceState `json:"run_state,omitempty" yaml:"run_state,omitempty"`
 }
 
+// AffinityGroupMemberType is the type definition for a AffinityGroupMemberType.
+type AffinityGroupMemberType string
+
 // AffinityGroupMemberInstance is an instance belonging to this group
 //
 // Instances can belong to up to 16 affinity groups.

Comment on lines 274 to 276
keys := slices.Collect(maps.Keys(m))
sort.Strings(keys)
return keys
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can update this body to be the following. Alternatively, you can eliminate this function and use this at each call site. Either way works for me so I'll approve this and defer to you!

Suggested change
keys := slices.Collect(maps.Keys(m))
sort.Strings(keys)
return keys
keys := slices.Sorted(maps.Keys(m))
return keys

In order to support deterministic generated code, sort the keys in the
type properties map before generating.
@jmcarp jmcarp force-pushed the jmcarp/sort-types branch from c294b21 to 2a47d70 Compare August 18, 2025 17:42
@jmcarp jmcarp merged commit 729a349 into main Aug 18, 2025
1 check passed
@jmcarp jmcarp deleted the jmcarp/sort-types branch August 18, 2025 17:48
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.

2 participants