-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Generate marshal json for each model #3307
Changes from 15 commits
8b3ae57
719eccf
2045da9
aebab06
9c333df
f2dc3bf
aba6a58
69f5b23
e4d1cc8
032927a
a854877
6d1580f
c18396d
3451830
4a36db8
18a5938
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,46 @@ | ||
package config | ||
|
||
import "encoding/json" | ||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type nullVariable struct{} | ||
type emptyListVariable struct{} | ||
|
||
// MarshalJSON returns the JSON encoding of nullVariable. | ||
func (v nullVariable) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(nil) | ||
// MarshalJSON returns the JSON encoding of emptyListVariable. | ||
func (v emptyListVariable) MarshalJSON() ([]byte, error) { | ||
return json.Marshal([]any{}) | ||
} | ||
|
||
// NullVariable returns nullVariable which implements Variable. | ||
func NullVariable() nullVariable { | ||
return nullVariable{} | ||
// EmptyListVariable returns Variable representing an empty list. This is because the current hcl parser handles empty SetVariable incorrectly. | ||
func EmptyListVariable() emptyListVariable { | ||
return emptyListVariable{} | ||
} | ||
|
||
type replacementPlaceholderVariable struct { | ||
placeholder ReplacementPlaceholder | ||
} | ||
|
||
// MarshalJSON returns the JSON encoding of replacementPlaceholderVariable. | ||
func (v replacementPlaceholderVariable) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(v.placeholder) | ||
} | ||
|
||
// ReplacementPlaceholderVariable returns Variable containing one of the ReplacementPlaceholder which is later replaced by HclFormatter. | ||
func ReplacementPlaceholderVariable(placeholder ReplacementPlaceholder) replacementPlaceholderVariable { | ||
return replacementPlaceholderVariable{placeholder} | ||
} | ||
|
||
type multilineWrapperVariable struct { | ||
content string | ||
} | ||
|
||
// MarshalJSON returns the JSON encoding of multilineWrapperVariable. | ||
func (v multilineWrapperVariable) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(fmt.Sprintf(`%[1]s%[2]s%[1]s`, SnowflakeProviderConfigMultilineMarker, v.content)) | ||
} | ||
|
||
// MultilineWrapperVariable returns Variable containing multiline content wrapped with SnowflakeProviderConfigMultilineMarker later replaced by HclFormatter. | ||
func MultilineWrapperVariable(content string) multilineWrapperVariable { | ||
return multilineWrapperVariable{content} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model/gen.ResourceConfigBuilderModel*/ -}} | ||
|
||
{{- $modelName := .Name | printf "%sModel" -}} | ||
{{- $nameLowerCase := FirstLetterLowercase .Name -}} | ||
{{- $modelVar := FirstLetter $nameLowerCase }} | ||
/////////////////////////////////////////////////////// | ||
// set proper json marshalling and handle depends on // | ||
/////////////////////////////////////////////////////// | ||
|
||
func ({{ $modelVar }} *{{ $modelName }}) MarshalJSON() ([]byte, error) { | ||
type Alias {{ $modelName }} | ||
return json.Marshal(&struct { | ||
*Alias | ||
DependsOn []string `json:"depends_on,omitempty"` | ||
}{ | ||
Alias: (*Alias)({{ $modelVar }}), | ||
DependsOn: {{ $modelVar }}.DependsOn(), | ||
}) | ||
} | ||
|
||
func ({{ $modelVar }} *{{ $modelName }}) WithDependsOn(values ...string) *{{ $modelName }} { | ||
{{ $modelVar }}.SetDependsOn(values...) | ||
return {{ $modelVar }} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: test the behavior of
\t
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do it in one of the next PRs