Skip to content
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

Merged
merged 16 commits into from
Dec 20, 2024

Conversation

sfc-gh-asawicki
Copy link
Collaborator

@sfc-gh-asawicki sfc-gh-asawicki commented Dec 19, 2024

  • generate marshal and depends_on for each resource and data source model
  • replace deprecated FromModel with the new one utilizing the aforementioned marshaling
  • fix test with explicit empty list (and add it to special variables)
  • fix tests with explicit null value (and add it to special variables)
  • generalize multiline handling and test it
  • use multiline strings for definitions in functions and procedures config builders
  • simplify function and procedure definitions
  • format whitespace in function and procedure definitions

For the next PRs (added to the issue):

  • current config building for functions/procedures (especially definitions) is complex:

    • definition is build using multiline golang strong and sprintf
    • whitespace is formatted
    • this is added in the config builder wrapped in special multiline marker
    • hcl-compatible json is generated
    • json converted to hcl
    • hcl formatted using custom formatters
      This should be refined and made simpler (e.g. newline replacement, encoding problems, etc.)
  • marking in config builders generators which fields should be handled as multiline by default (because now e.g. SQL function requires the definition, so it's generated in basic builder as a string input, and not the multiline one; because of that it has to be added again with WithFunctionDefinitionValue(...) which is confusing)

Copy link

Integration tests failure for f2dc3bf06899bba9b305adf39807142f05cc9086

@sfc-gh-asawicki sfc-gh-asawicki marked this pull request as ready for review December 20, 2024 12:00
func ProcedureJavascriptBasicInline(
resourceName string,
id sdk.SchemaObjectIdentifierWithArguments,
returnType datatypes.DataType,
procedureDefinition string,
) *ProcedureJavascriptModel {
return ProcedureJavascript(resourceName, id.DatabaseName(), id.Name(), procedureDefinition, returnType.ToSql(), id.SchemaName())
return ProcedureJavascript(resourceName, id.DatabaseName(), id.Name(), procedureDefinition, returnType.ToSql(), id.SchemaName()).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

procedureDefinition is passed twice in this whole call, and it's a bit confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is on purpose now.

I added to the PR description the next step which explains it.

func ProcedureSqlBasicInline(
resourceName string,
id sdk.SchemaObjectIdentifierWithArguments,
returnType datatypes.DataType,
procedureDefinition string,
) *ProcedureSqlModel {
return ProcedureSql(resourceName, id.DatabaseName(), id.Name(), procedureDefinition, returnType.ToSql(), id.SchemaName())
return ProcedureSql(resourceName, id.DatabaseName(), id.Name(), procedureDefinition, returnType.ToSql(), id.SchemaName()).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -35,6 +35,9 @@ resource "snowflake_share" "test" {
Item{IntField: 2, StringField: "second item"},
).
WithSingleObject("one", 2).
WithTextFieldExplicitNull().
WithListFieldEmpty().
WithMultilineField("some\nmultiline\ncontent").
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link

Integration tests failure for 4a36db81894f99c88b02a5da5b2acaf4d4f6eee6

Copy link

Integration tests cancelled for 18a59381fdb40c2df9b4d7ecf67f969f333a019e

@sfc-gh-asawicki sfc-gh-asawicki merged commit 6fe31ba into dev Dec 20, 2024
8 of 9 checks passed
@sfc-gh-asawicki sfc-gh-asawicki deleted the generate-marshal-json-for-each-model branch December 20, 2024 13:56
sfc-gh-asawicki added a commit that referenced this pull request Dec 20, 2024
- generate marshal and `depends_on` for each resource and data source
model
- replace deprecated `FromModel` with the new one utilizing the
aforementioned marshaling
- fix test with explicit empty list (and add it to special variables)
- fix tests with explicit null value (and add it to special variables)
- generalize multiline handling and test it
- use multiline strings for definitions in functions and procedures
config builders
- simplify function and procedure definitions
- format whitespace in function and procedure definitions

For the next PRs (added to the issue):
- current config building for functions/procedures (especially
definitions) is complex:
  - definition is build using multiline golang strong and sprintf
  - whitespace is formatted
- this is added in the config builder wrapped in special multiline
marker
  - hcl-compatible json is generated
  - json converted to hcl
  - hcl formatted using custom formatters
This should be refined and made simpler (e.g. newline replacement,
encoding problems, etc.)

- marking in config builders generators which fields should be handled
as multiline by default (because now e.g. SQL function requires the
definition, so it's generated in basic builder as a string input, and
not the multiline one; because of that it has to be added again with
`WithFunctionDefinitionValue(...)` which is confusing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants