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

Consider adding comments to model field structs #19

Open
bendbennett opened this issue Jun 23, 2023 · 0 comments
Open

Consider adding comments to model field structs #19

bendbennett opened this issue Jun 23, 2023 · 0 comments

Comments

@bendbennett
Copy link
Contributor

During the generation of data models, there can be a significant number of models that are generated for nested attributes and/or nested blocks.

For example, using the following intermediate representation (IR):

{
  "datasources": [
    {
      "name": "datasource",
      "schema": {
        "attributes": [
          {
            "name": "list_nested_list_nested_bool_attribute",
            "list_nested": {
              "computed_optional_required": "computed",
              "nested_object": {
                "attributes": [
                  {
                    "name": "list_nested_bool_attribute",
                    "list_nested": {
                      "computed_optional_required": "computed",
                      "nested_object": {
                        "attributes": [
                          {
                            "name": "bool_attribute",
                            "bool": {
                              "computed_optional_required": "computed"
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          },
          {
            "name": "list_nested_list_nested_list_attribute",
            "list_nested": {
              "computed_optional_required": "computed",
              "nested_object": {
                "attributes": [
                  {
                    "name": "list_nested_list_attribute",
                    "list_nested": {
                      "computed_optional_required": "computed",
                      "nested_object": {
                        "attributes": [
                          {
                            "name": "list_attribute",
                            "list": {
                              "computed_optional_required": "computed",
                              "element_type": {
                                "string": {}
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  ],
  "provider": {
    "name": "provider"
  }
}

Results in the generation of the following models:

type datasourceModel struct {
	ListNestedListNestedBoolAttribute types.List `tfsdk:"list_nested_list_nested_bool_attribute"`
	ListNestedListNestedListAttribute types.List `tfsdk:"list_nested_list_nested_list_attribute"`
}

type listNestedListNestedBoolAttributeModel struct {
	ListNestedBoolAttribute types.List `tfsdk:"list_nested_bool_attribute"`
}

type listNestedBoolAttributeModel struct {
	BoolAttribute types.Bool `tfsdk:"bool_attribute"`
}

type listNestedListNestedListAttributeModel struct {
	ListNestedListAttribute types.List `tfsdk:"list_nested_list_attribute"`
}

type listNestedListAttributeModel struct {
	ListAttribute types.List `tfsdk:"list_attribute"`
}

Within other providers, for instance TLS, comments have been added to the models to make it more clear which nested model "belongs" to which model struct field.

In this instance, autogenerates comments indicating the relationships between the models would look something like the following:

type datasourceModel struct {
	ListNestedListNestedBoolAttribute types.List `tfsdk:"list_nested_list_nested_bool_attribute"` //< listNestedListNestedBoolAttributeModel
	ListNestedListNestedListAttribute types.List `tfsdk:"list_nested_list_nested_list_attribute"` //< listNestedListNestedListAttributeModel
}

type listNestedListNestedBoolAttributeModel struct {
	ListNestedBoolAttribute types.List `tfsdk:"list_nested_bool_attribute"` // < listNestedBoolAttributeModel
}

type listNestedBoolAttributeModel struct {
	BoolAttribute types.Bool `tfsdk:"bool_attribute"`
}

type listNestedListNestedListAttributeModel struct {
	ListNestedListAttribute types.List `tfsdk:"list_nested_list_attribute"` // < listNestedListAttributeModel
}

type listNestedListAttributeModel struct {
	ListAttribute types.List `tfsdk:"list_attribute"`
}

We may want to consider adding these comments to help with the navigation between and association of models and nested models.

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

No branches or pull requests

1 participant