Skip to content

Commit

Permalink
Fix model template
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Sep 11, 2024
1 parent 53b31be commit 054fa0a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gen/templates/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (data *{{camelCase .Name}}) fromBodyPartial(ctx context.Context, res gjson.
{{- range .Attributes}}
{{- if and (not .Value) (not .WriteOnly) (not .Reference)}}
{{- if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool")}}
if value := res.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); value.Exists() {
if value := res.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}"); value.Exists() && !data.{{toGoName .TfName}}.IsNull() {
data.{{toGoName .TfName}} = types.{{.Type}}Value(value.{{if eq .Type "Int64"}}Int{{else if eq .Type "Float64"}}Float{{else}}{{.Type}}{{end}}())
} else {{if .DefaultValue}}if data.{{toGoName .TfName}}.Value{{.Type}}() != {{if eq .Type "String"}}"{{end}}{{.DefaultValue}}{{if eq .Type "String"}}"{{end}} {{end}}{
data.{{toGoName .TfName}} = types.{{.Type}}Null()
Expand Down
14 changes: 7 additions & 7 deletions internal/provider/model_meraki_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,17 @@ func (data *Admin) fromBody(ctx context.Context, res gjson.Result) {
// easily change across versions of the backend API.) For List/Set/Map attributes, the func only updates the
// "managed" elements, instead of all elements.
func (data *Admin) fromBodyPartial(ctx context.Context, res gjson.Result) {
if value := res.Get("email"); value.Exists() {
if value := res.Get("email"); value.Exists() && !data.Email.IsNull() {
data.Email = types.StringValue(value.String())
} else {
data.Email = types.StringNull()
}
if value := res.Get("name"); value.Exists() {
if value := res.Get("name"); value.Exists() && !data.Name.IsNull() {
data.Name = types.StringValue(value.String())
} else {
data.Name = types.StringNull()
}
if value := res.Get("orgAccess"); value.Exists() {
if value := res.Get("orgAccess"); value.Exists() && !data.OrgAccess.IsNull() {
data.OrgAccess = types.StringValue(value.String())
} else {
data.OrgAccess = types.StringNull()
Expand Down Expand Up @@ -229,12 +229,12 @@ func (data *Admin) fromBodyPartial(ctx context.Context, res gjson.Result) {

continue
}
if value := res.Get("access"); value.Exists() {
if value := res.Get("access"); value.Exists() && !data.Access.IsNull() {
data.Access = types.StringValue(value.String())
} else {
data.Access = types.StringNull()
}
if value := res.Get("id"); value.Exists() {
if value := res.Get("id"); value.Exists() && !data.Id.IsNull() {
data.Id = types.StringValue(value.String())
} else {
data.Id = types.StringNull()
Expand Down Expand Up @@ -277,12 +277,12 @@ func (data *Admin) fromBodyPartial(ctx context.Context, res gjson.Result) {

continue
}
if value := res.Get("access"); value.Exists() {
if value := res.Get("access"); value.Exists() && !data.Access.IsNull() {
data.Access = types.StringValue(value.String())
} else {
data.Access = types.StringNull()
}
if value := res.Get("tag"); value.Exists() {
if value := res.Get("tag"); value.Exists() && !data.Tag.IsNull() {
data.Tag = types.StringValue(value.String())
} else {
data.Tag = types.StringNull()
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/model_meraki_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ func (data *Network) fromBody(ctx context.Context, res gjson.Result) {
// easily change across versions of the backend API.) For List/Set/Map attributes, the func only updates the
// "managed" elements, instead of all elements.
func (data *Network) fromBodyPartial(ctx context.Context, res gjson.Result) {
if value := res.Get("name"); value.Exists() {
if value := res.Get("name"); value.Exists() && !data.Name.IsNull() {
data.Name = types.StringValue(value.String())
} else {
data.Name = types.StringNull()
}
if value := res.Get("notes"); value.Exists() {
if value := res.Get("notes"); value.Exists() && !data.Notes.IsNull() {
data.Notes = types.StringValue(value.String())
} else {
data.Notes = types.StringNull()
}
if value := res.Get("timeZone"); value.Exists() {
if value := res.Get("timeZone"); value.Exists() && !data.TimeZone.IsNull() {
data.TimeZone = types.StringValue(value.String())
} else {
data.TimeZone = types.StringNull()
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/model_meraki_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (data *Organization) fromBody(ctx context.Context, res gjson.Result) {
// easily change across versions of the backend API.) For List/Set/Map attributes, the func only updates the
// "managed" elements, instead of all elements.
func (data *Organization) fromBodyPartial(ctx context.Context, res gjson.Result) {
if value := res.Get("name"); value.Exists() {
if value := res.Get("name"); value.Exists() && !data.Name.IsNull() {
data.Name = types.StringValue(value.String())
} else {
data.Name = types.StringNull()
Expand Down Expand Up @@ -161,12 +161,12 @@ func (data *Organization) fromBodyPartial(ctx context.Context, res gjson.Result)

continue
}
if value := res.Get("name"); value.Exists() {
if value := res.Get("name"); value.Exists() && !data.Name.IsNull() {
data.Name = types.StringValue(value.String())
} else {
data.Name = types.StringNull()
}
if value := res.Get("value"); value.Exists() {
if value := res.Get("value"); value.Exists() && !data.Value.IsNull() {
data.Value = types.StringValue(value.String())
} else {
data.Value = types.StringNull()
Expand Down

0 comments on commit 054fa0a

Please sign in to comment.