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

Handle potential naming collisions #20

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

Handle potential naming collisions #20

bendbennett opened this issue Jun 26, 2023 · 0 comments

Comments

@bendbennett
Copy link
Contributor

bendbennett commented Jun 26, 2023

During the generation of data models there is the potential for the generated model names to conflict. There are at least 2 situations in which this could arise:

  • Schemas that contain nested attributes
  • Data sources, provider and resources that contain nested attributes

Schemas that contain nested attributes

For example, in the case of schemas that contain nested attributes, we could have a situation such as the following in which two list_nested attributes within the intermediate representation contain an attribute with the same name

          {
            "name": "list_nested_list_nested_bool_attribute",
            "list_nested": {
              "computed_optional_required": "computed",
              "nested_object": {
                "attributes": [
                  {
                    "name": "list_nested_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_attribute",
                    "list_nested": {
                      "computed_optional_required": "computed",
                      "nested_object": {
                        "attributes": [
                          {
                            "name": "list_attribute",
                            "list": {
                              "computed_optional_required": "computed",
                              "element_type": {
                                "string": {}
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          },

The generated models have a naming collision:

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

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

Data sources, provider and resources that contain nested attributes

An analogous situation could arise with data sources, provider and resources in which the schema contain nested attributes or blocks with the same names.

Possible Solutions

  • In the case of a single schema containing nested attributes, naming collisions such as the example illustrated above could be avoided by prepending each level of nested attribute with the name of the parent attribute.
  • For potential naming collisions across data sources, provider and resources, one option would be to put each data source, provider and resource in a separate package.
bendbennett added a commit that referenced this issue Sep 4, 2023
bendbennett added a commit that referenced this issue Sep 4, 2023
bendbennett added a commit that referenced this issue Sep 5, 2023
bendbennett added a commit that referenced this issue Sep 5, 2023
… "example" to highlight the default behaviour for directory and package generation (#20)
bendbennett added a commit that referenced this issue Sep 5, 2023
bendbennett added a commit that referenced this issue Sep 7, 2023
… and resource (#39)

* Default to empty string for package flag, and use data source, provider, or resource name as package name (#20)

* Adding test coverage to verify package name can be overridden by supplying --package flag (#20)

* Add generated code to separate directories (#20)

* Only create directory and package per data source and resource if packageName flag is not specified (#20)

* Changing the name of data source, provider and resource in ir.json to "example" to highlight the default behaviour for directory and package generation (#20)

* Adding doc comments (#20)
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