bold-commerce / go-shopify

Go client for the Shopify API
MIT License
328 stars 255 forks source link

Create Constants for Fields With Well-Defined Values #217

Closed c9845 closed 1 year ago

c9845 commented 1 year ago

Would it be worth defining constants, and an associated type, for struct fields with well-known & defined possible values?

For example, the Metafield type has a Type field. The Type field can only be one of the defined values listed at https://shopify.dev/docs/apps/custom-data/metafields/types#supported-types.

I propose something like the following:


//Define the type.
type metafieldType string

//Define the possible values.
const (
  metafieldTypeBoolean             metafieldType = "boolean"
  metafieldTypeColor               metafieldType = "color"
  metafieldTypeSingleLineTextField metafieldType = "single_line_text_field"
  //...
)

//Metafield type is changed to use the new type.
type Metafield struct {
  //...
  Type  metafieldType  `json:"type,omitempty"`
  //...
}

Why? This makes it so code editors will suggest only possible values for this field. Right now, any string can be provided regardless of if it is a value Shopify will accept. This is really just to prevent typos.

For legacy purposes, string values will still be accepted when assigning to the Type field without issue. So this shouldn't break any existing code.

oliver006 commented 1 year ago

I think that makes sense and would be a good enhancement!

oliver006 commented 1 year ago

Closed by #221