Skip to content

Commit

Permalink
work around spec issue for organization address
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Dec 13, 2023
1 parent 582277b commit 4999927
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
9 changes: 8 additions & 1 deletion internal/organizations/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func (c *Client) Create() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true

// API spec says organization address.address is required,
// but the address is not included by default
defaultIncludes := []string{"address.address"}

include := c.Servicer.Includes(defaultIncludes)
exclude := c.Servicer.Excludes(nil)

req := metal.NewOrganizationInput()
req.Name = &name

Expand All @@ -70,7 +77,7 @@ func (c *Client) Create() *cobra.Command {
req.Logo = &logo
}

org, _, err := c.Service.CreateOrganization(context.Background()).OrganizationInput(*req).Include(c.Servicer.Includes(nil)).Exclude(c.Servicer.Excludes(nil)).Execute()
org, _, err := c.Service.CreateOrganization(context.Background()).OrganizationInput(*req).Include(include).Exclude(exclude).Execute()
if err != nil {
return fmt.Errorf("Could not create Organization: %w", err)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/organizations/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ func (c *Client) Retrieve() *cobra.Command {

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
include := c.Servicer.Includes(nil)

// API spec says organization address.address is required,
// but the address is not included by default
defaultIncludes := []string{"address.address"}

include := c.Servicer.Includes(defaultIncludes)
exclude := c.Servicer.Excludes(nil)

if organizationID == "" {
Expand Down
9 changes: 8 additions & 1 deletion internal/organizations/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ func (c *Client) Update() *cobra.Command {
cmd.SilenceUsage = true
req := metal.NewOrganizationInput()

// API spec says organization address is required,
// but the address is not included by default
defaultIncludes := []string{"address"}

include := c.Servicer.Includes(defaultIncludes)
exclude := c.Servicer.Excludes(nil)

if name != "" {
req.Name = &name
}
Expand All @@ -62,7 +69,7 @@ func (c *Client) Update() *cobra.Command {
req.Website = &website
}

org, _, err := c.Service.UpdateOrganization(context.Background(), organizationID).OrganizationInput(*req).Execute()
org, _, err := c.Service.UpdateOrganization(context.Background(), organizationID).OrganizationInput(*req).Include(include).Exclude(exclude).Execute()
if err != nil {
return fmt.Errorf("Could not update Organization: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion test/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@ func CreateTestOrganization(name string) (string, error) {
addr.SetZipCode("02108")
organizationInput.Address = addr

resp, _, err := TestApiClient.OrganizationsApi.CreateOrganization(context.Background()).OrganizationInput(*organizationInput).Execute()
// API spec says organization address.address is required,
// but the address is not included by default
defaultIncludes := []string{"address.address"}

resp, _, err := TestApiClient.OrganizationsApi.CreateOrganization(context.Background()).OrganizationInput(*organizationInput).Include(defaultIncludes).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `OrganizationsApi.CreateOrganization``: %v\n", err)
return "", err
Expand Down

0 comments on commit 4999927

Please sign in to comment.