Skip to content

Commit

Permalink
Merge pull request #63 from geekspace9/handle-traits
Browse files Browse the repository at this point in the history
Handle traits for query parameters
  • Loading branch information
qdegraaf authored Apr 15, 2021
2 parents a39bfe2 + 40b52e2 commit 09b2a9e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
14 changes: 14 additions & 0 deletions code-generate/parse_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import (
yaml "gopkg.in/yaml.v2"
)

// XXX: using a global variable has a smell... however, its just a code
// generator, not production code
var traits yaml.MapSlice

func parseYaml(data yaml.MapSlice) (objects []RamlType, domains []ServiceDomain) {
types := getPropertyValue(data, "types")
for _, mapItem := range types.(yaml.MapSlice) {
obj := createRamlType(mapItem.Key.(string), mapItem.Value.(yaml.MapSlice))
objects = append(objects, obj)
}
traits = getPropertyValue(data, "traits").(yaml.MapSlice)

domains = make([]ServiceDomain, 0)
apiResources := getPropertyValue(data, "/{projectKey}")
Expand All @@ -28,3 +33,12 @@ func parseYaml(data yaml.MapSlice) (objects []RamlType, domains []ServiceDomain)

return
}

func getTrait(name string) yaml.MapSlice {
for _, t := range traits {
if t.Key == name {
return t.Value.(yaml.MapSlice)
}
}
return nil
}
25 changes: 25 additions & 0 deletions code-generate/parse_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,31 @@ func parseResourceData(val yaml.MapSlice, method *ServiceMethod) {
}
}

for _, name := range method.Traits {
trait := getTrait(name)
if trait == nil {
continue
}
qparams := getPropertyValue(trait, "queryParameters")
if qparams != nil {
for _, item := range qparams.(yaml.MapSlice) {
obj := createRamlTypeAttribute(item.Key.(string), item.Value)
// traits are supposed to be optional
obj.Optional = true
exists := false
for _, existing := range method.QueryParameters {
if existing.Name == obj.Name {
exists = true
break
}
}
if !exists {
method.QueryParameters = append(method.QueryParameters, obj)
}
}
}
}

}

func getTypeInformation(item yaml.MapItem) string {
Expand Down
3 changes: 2 additions & 1 deletion commercetools/service_in_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func (client *Client) StoreLogin(ctx context.Context, storeKey string, value *Cu

// StoreShippingMethodsForMatchingCartInput is input for function StoreShippingMethodsForMatchingCart
type StoreShippingMethodsForMatchingCartInput struct {
CartID string `url:"cartId"`
CartID string `url:"cartId"`
Expand []string `url:"expand,omitempty"`
}

// StoreShippingMethodsForMatchingCart for type StoreShippingMethodsForMatchingCartInput
Expand Down
13 changes: 13 additions & 0 deletions commercetools/service_product_projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ type ProductProjectionSearchInput struct {
FuzzyLevel float64 `url:"fuzzyLevel,omitempty"`
MarkMatchingVariants bool `url:"markMatchingVariants,omitempty"`
Staged bool `url:"staged,omitempty"`
Limit float64 `url:"limit,omitempty"`
Offset float64 `url:"offset,omitempty"`
WithTotal bool `url:"withTotal,omitempty"`
LocaleProjection string `url:"localeProjection,omitempty"`
PriceChannel string `url:"priceChannel,omitempty"`
PriceCountry string `url:"priceCountry,omitempty"`
PriceCurrency string `url:"priceCurrency,omitempty"`
PriceCustomerGroup string `url:"priceCustomerGroup,omitempty"`
StoreProjection string `url:"storeProjection,omitempty"`
Expand []string `url:"expand,omitempty"`
}

/*
Expand Down Expand Up @@ -97,6 +107,9 @@ type ProductProjectionSuggestInput struct {
SearchKeywords map[string]string `url:"searchKeywords"`
Fuzzy bool `url:"fuzzy,omitempty"`
Staged bool `url:"staged,omitempty"`
Limit float64 `url:"limit,omitempty"`
Offset float64 `url:"offset,omitempty"`
WithTotal bool `url:"withTotal,omitempty"`
}

// ProductProjectionSuggest The source of data for suggestions is the searchKeyword field in a product
Expand Down
10 changes: 6 additions & 4 deletions commercetools/service_shipping_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func (client *Client) ShippingMethodUpdateWithKey(ctx context.Context, input *Sh

// ShippingMethodMatchingCartInput is input for function ShippingMethodMatchingCart
type ShippingMethodMatchingCartInput struct {
CartID string `url:"cartId"`
CartID string `url:"cartId"`
Expand []string `url:"expand,omitempty"`
}

// ShippingMethodMatchingCart Get ShippingMethods for a cart
Expand All @@ -188,9 +189,10 @@ func (client *Client) ShippingMethodMatchingCart(ctx context.Context, value *Shi

// ShippingMethodMatchingLocationInput is input for function ShippingMethodMatchingLocation
type ShippingMethodMatchingLocationInput struct {
Country string `url:"country"`
Currency string `url:"currency,omitempty"`
State string `url:"state,omitempty"`
Country string `url:"country"`
Currency string `url:"currency,omitempty"`
State string `url:"state,omitempty"`
Expand []string `url:"expand,omitempty"`
}

// ShippingMethodMatchingLocation Get ShippingMethods for a location
Expand Down

0 comments on commit 09b2a9e

Please sign in to comment.