Skip to content

Commit

Permalink
Resolve issue CiscoDevNet#267
Browse files Browse the repository at this point in the history
  • Loading branch information
seconroy committed Aug 7, 2024
1 parent af47a0b commit ff2e905
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gen/definitions/profile_parcels/transport_routing_bgp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ attributes:
- model_name: refId
tf_name: ipv4_table_map_route_policy_id
data_path: [addressFamily, name]
# exclude_null: true
always_include_parent: true
exclude_test: true
example: a509839f-33aa-492a-ab8e-6a6fe70d7d79
# # test_value:
Expand Down Expand Up @@ -305,7 +305,7 @@ attributes:
- model_name: refId
tf_name: ipv6_table_map_route_policy_id
data_path: [ipv6AddressFamily, name]
# exclude_null: true
always_include_parent: true
exclude_test: true
example: a509839f-33aa-492a-ab8e-6a6fe70d7d79
# test_value:
Expand Down
5 changes: 5 additions & 0 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ type YamlConfigAttribute struct {
TestValue string `yaml:"test_value"`
MinimumTestValue string `yaml:"minimum_test_value"`
AlwaysInclude bool `yaml:"always_include"`
AlwaysIncludeParent bool `yaml:"always_include_parent"`
Attributes []YamlConfigAttribute `yaml:"attributes"`
ConditionalAttribute YamlConfigConditionalAttribute `yaml:"conditional_attribute"`
ConditionalListLength string `yaml:"conditional_list_length"`
Expand Down Expand Up @@ -720,6 +721,10 @@ func parseProfileParcelAttribute(attr *YamlConfigAttribute, model gjson.Result,
attr.TfName = SnakeCase(attr.ModelName)
}

if attr.AlwaysIncludeParent {
fmt.Println(path)
}

if r.Get("type").String() == "object" || !r.Get("type").Exists() {
noGlobal := false

Expand Down
1 change: 1 addition & 0 deletions gen/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ attribute:
test_value: str(required=False) # Value used for acceptance test
minimum_test_value: any(str(), int(), bool(), num(), required=False) # Value used for "minimum" resource acceptance test
always_include: bool(required=False) # Include attribute always in payload
always_include_parent: bool(required=false) # Include attributes parent always in payload
attributes: list(include('attribute'), required=False) # List of attributes, only relevant if type is "List" or "Set"
conditional_attribute: include('conditional_attribute', required=False) # Add attribute to payload only if condition is true
conditional_list_length: str(required=False) # Add attribute to payload only if referenced list has a length greater than 0
Expand Down
8 changes: 8 additions & 0 deletions gen/templates/profile_parcels/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
} else {{end}}{{if and .DefaultValuePresent (not .ExcludeNull)}}if data.{{toGoName .TfName}}.IsNull() {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
{{if or .DefaultValue .DefaultValueEmptyString}}body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.DefaultValue}}{{if eq .Type "String"}}"{{end}}){{end}}
} else {{else if .AlwaysIncludeParent }}if data.{{toGoName .TfName}}.IsNull() {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}optionType", "default")
} else {{else}}if !data.{{toGoName .TfName}}.IsNull(){{end}} {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "global")
{{- if isListSet .}}
Expand All @@ -197,6 +199,8 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
} else {{end}}{{if and .DefaultValuePresent (not .ExcludeNull)}}if item.{{toGoName .TfName}}.IsNull() {
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
{{if or .DefaultValue .DefaultValueEmptyString}}itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.DefaultValue}}{{if eq .Type "String"}}"{{end}}){{end}}
} else {{else if .AlwaysIncludeParent }}if data.{{toGoName .TfName}}.IsNull() {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}optionType", "default")
} else {{else}}if !item.{{toGoName .TfName}}.IsNull(){{end}} {
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "global")
{{- if isListSet .}}
Expand All @@ -223,6 +227,8 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
} else {{end}}{{if and .DefaultValuePresent (not .ExcludeNull)}}if childItem.{{toGoName .TfName}}.IsNull() {
itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
{{if or .DefaultValue .DefaultValueEmptyString}}itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.DefaultValue}}{{if eq .Type "String"}}"{{end}}){{end}}
} else {{else if .AlwaysIncludeParent }}if data.{{toGoName .TfName}}.IsNull() {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}optionType", "default")
} else {{else}}if !childItem.{{toGoName .TfName}}.IsNull(){{end}} {
itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "global")
{{- if isListSet .}}
Expand All @@ -249,6 +255,8 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
} else {{end}}{{if and .DefaultValuePresent (not .ExcludeNull)}}if childChildItem.{{toGoName .TfName}}.IsNull() {
itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
{{if or .DefaultValue .DefaultValueEmptyString}}itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.DefaultValue}}{{if eq .Type "String"}}"{{end}}){{end}}
} else {{else if .AlwaysIncludeParent }}if data.{{toGoName .TfName}}.IsNull() {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}optionType", "default")
} else {{else}}if !childChildItem.{{toGoName .TfName}}.IsNull(){{end}} {
itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "global")
{{- if isListSet .}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,9 @@ func (data TransportRoutingBGP) toBody(ctx context.Context) string {
body, _ = sjson.Set(body, path+"addressFamily.originate.optionType", "global")
body, _ = sjson.Set(body, path+"addressFamily.originate.value", data.Ipv4Originate.ValueBool())
}
if !data.Ipv4TableMapRoutePolicyId.IsNull() {
if data.Ipv4TableMapRoutePolicyId.IsNull() {
body, _ = sjson.Set(body, path+"addressFamily.name.optionType", "default")
} else {
body, _ = sjson.Set(body, path+"addressFamily.name.refId.optionType", "global")
body, _ = sjson.Set(body, path+"addressFamily.name.refId.value", data.Ipv4TableMapRoutePolicyId.ValueString())
}
Expand Down Expand Up @@ -1039,7 +1041,9 @@ func (data TransportRoutingBGP) toBody(ctx context.Context) string {
body, _ = sjson.Set(body, path+"ipv6AddressFamily.originate.optionType", "global")
body, _ = sjson.Set(body, path+"ipv6AddressFamily.originate.value", data.Ipv6Originate.ValueBool())
}
if !data.Ipv6TableMapRoutePolicyId.IsNull() {
if data.Ipv6TableMapRoutePolicyId.IsNull() {
body, _ = sjson.Set(body, path+"ipv6AddressFamily.name.optionType", "default")
} else {
body, _ = sjson.Set(body, path+"ipv6AddressFamily.name.refId.optionType", "global")
body, _ = sjson.Set(body, path+"ipv6AddressFamily.name.refId.value", data.Ipv6TableMapRoutePolicyId.ValueString())
}
Expand Down

0 comments on commit ff2e905

Please sign in to comment.