Skip to content

Commit 41f4c7a

Browse files
authored
fix(stacks/vcs): StackVCSRepo nested-struct incorrectly serializing attributes (#1029)
hashicorp/jsonapi and by extension google/jsonapi packages have issues serializing nested-structs that are not relationship, but attr. Converting to json struct tag directive for the time being
1 parent 6aa1267 commit 41f4c7a

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

stack.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ type StackVCSRepo struct {
7575
OAuthTokenID string `jsonapi:"attr,oauth-token-id,omitempty"`
7676
}
7777

78+
// StackVCSRepoOptions
79+
type StackVCSRepoOptions struct {
80+
Identifier string `json:"identifier"`
81+
Branch string `json:"branch,omitempty"`
82+
GHAInstallationID string `json:"github-app-installation-id,omitempty"`
83+
OAuthTokenID string `json:"oauth-token-id,omitempty"`
84+
}
85+
7886
// Stack represents a stack.
7987
type Stack struct {
8088
ID string `jsonapi:"primary,stacks"`
@@ -172,11 +180,11 @@ type StackReadOptions struct {
172180
// StackCreateOptions represents the options for creating a stack. The project
173181
// relation is required.
174182
type StackCreateOptions struct {
175-
Type string `jsonapi:"primary,stacks"`
176-
Name string `jsonapi:"attr,name"`
177-
Description *string `jsonapi:"attr,description,omitempty"`
178-
VCSRepo *StackVCSRepo `jsonapi:"attr,vcs-repo"`
179-
Project *Project `jsonapi:"relation,project"`
183+
Type string `jsonapi:"primary,stacks"`
184+
Name string `jsonapi:"attr,name"`
185+
Description *string `jsonapi:"attr,description,omitempty"`
186+
VCSRepo *StackVCSRepoOptions `jsonapi:"attr,vcs-repo"`
187+
Project *Project `jsonapi:"relation,project"`
180188
}
181189

182190
// StackUpdateOptions represents the options for updating a stack.
@@ -326,7 +334,7 @@ func (s StackCreateOptions) valid() error {
326334
return s.VCSRepo.valid()
327335
}
328336

329-
func (s StackVCSRepo) valid() error {
337+
func (s StackVCSRepoOptions) valid() error {
330338
if s.Identifier == "" {
331339
return ErrRequiredVCSRepo
332340
}

stack_integration_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestStackCreateAndList(t *testing.T) {
3131

3232
stack1, err := client.Stacks.Create(ctx, StackCreateOptions{
3333
Name: "aa-test-stack",
34-
VCSRepo: &StackVCSRepo{
34+
VCSRepo: &StackVCSRepoOptions{
3535
Identifier: "hashicorp-guides/pet-nulls-stack",
3636
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
3737
},
@@ -45,7 +45,7 @@ func TestStackCreateAndList(t *testing.T) {
4545

4646
stack2, err := client.Stacks.Create(ctx, StackCreateOptions{
4747
Name: "zz-test-stack",
48-
VCSRepo: &StackVCSRepo{
48+
VCSRepo: &StackVCSRepoOptions{
4949
Identifier: "hashicorp-guides/pet-nulls-stack",
5050
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
5151
},
@@ -143,7 +143,7 @@ func TestStackReadUpdateDelete(t *testing.T) {
143143

144144
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
145145
Name: "test-stack",
146-
VCSRepo: &StackVCSRepo{
146+
VCSRepo: &StackVCSRepoOptions{
147147
Identifier: "brandonc/pet-nulls-stack",
148148
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
149149
Branch: "main",
@@ -200,7 +200,7 @@ func TestStackReadUpdateForceDelete(t *testing.T) {
200200

201201
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
202202
Name: "test-stack",
203-
VCSRepo: &StackVCSRepo{
203+
VCSRepo: &StackVCSRepoOptions{
204204
Identifier: "brandonc/pet-nulls-stack",
205205
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
206206
Branch: "main",
@@ -356,7 +356,7 @@ func TestStackConverged(t *testing.T) {
356356

357357
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
358358
Name: "test-stack",
359-
VCSRepo: &StackVCSRepo{
359+
VCSRepo: &StackVCSRepoOptions{
360360
Identifier: "brandonc/pet-nulls-stack",
361361
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
362362
},

stack_plan_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestStackPlanList(t *testing.T) {
2929

3030
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
3131
Name: "aa-test-stack",
32-
VCSRepo: &StackVCSRepo{
32+
VCSRepo: &StackVCSRepoOptions{
3333
Identifier: "brandonc/pet-nulls-stack",
3434
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
3535
},

stack_source_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestStackSourceCreateUploadAndRead(t *testing.T) {
2626
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
2727
Project: orgTest.DefaultProject,
2828
Name: "test-stack",
29-
VCSRepo: &StackVCSRepo{
29+
VCSRepo: &StackVCSRepoOptions{
3030
Identifier: "hashicorp-guides/pet-nulls-stack",
3131
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
3232
},

0 commit comments

Comments
 (0)