Skip to content

Conversation

@bflad
Copy link
Contributor

@bflad bflad commented Jun 21, 2023

Closes #25

This breaking change ensures there is consistency that specification implementations can use CustomType with all types, in this case object types underlying any attribute type.

For existing implementations, such as:

{
            "name": "list_object_attribute",
            "list": {
              "computed_optional_required": "computed",
              "element_type": {
                "object": [
                  {
                    "name": "obj_string_attr",
                    "string": {}
                  }
                ]
              }
            }
          },

Are now defined as:

{
            "name": "list_object_attribute",
            "list": {
              "computed_optional_required": "computed",
              "element_type": {
                "object": {
                  "attribute_types": [
                    {
                      "name": "obj_string_attr",
                      "string": {}
                    }
                  ]
                }
              }
            }
          },

Note that there is now a slight inconsistency between how CustomType is defined on collection types (ListType, MapType, and SetType) that are already element types and need to include their own element type. The CustomType is specified along side the element type, rather than explicitly having an ElementType delineation.

Currently:

          {
            "name": "map_list_string_attribute",
            "map": {
              "computed_optional_required": "computed",
              "element_type": {
                "list": {
                  "custom_type": {
                    "import": "github.com/hashicorp/terraform-plugin-framework/types/basetypes",
                    "type": "basetypes.ListType",
                    "value_type": "basetypes.ListValue"
                  },
                  "string": {}
                }
              }
            }
          },

It may make sense to reintroduce what was originally designed in the specification with the verbose ElementType property for clarity.

          {
            "name": "map_list_string_attribute",
            "map": {
              "computed_optional_required": "computed",
              "element_type": {
                "list": {
                  "custom_type": {
                    "import": "github.com/hashicorp/terraform-plugin-framework/types/basetypes",
                    "type": "basetypes.ListType",
                    "value_type": "basetypes.ListValue"
                  },
                  "element_type": {
                    "string": {}
                  }
                }
              }
            }
          },

Reference: #25

This breaking change ensures there is consistency that specification implementations can use `CustomType` with all types, in this case object types underlying any attribute type.

For existing implementations, such as:

```json
{
            "name": "list_object_attribute",
            "list": {
              "computed_optional_required": "computed",
              "element_type": {
                "object": [
                  {
                    "name": "obj_string_attr",
                    "string": {}
                  }
                ]
              }
            }
          },
```

Are now defined as:

```json
{
            "name": "list_object_attribute",
            "list": {
              "computed_optional_required": "computed",
              "element_type": {
                "object": {
                  "attribute_types": [
                    {
                      "name": "obj_string_attr",
                      "string": {}
                    }
                  ]
                }
              }
            }
          },
```

Note that there is now a slight inconsistency between how `CustomType` is defined on collection types (`ListType`, `MapType`, and `SetType`) that are already element types and need to include their own element type. The `CustomType` is specified along side the element type, rather than explicitly having an `ElementType` delineation.

Currently:

```json
          {
            "name": "map_list_string_attribute",
            "map": {
              "computed_optional_required": "computed",
              "element_type": {
                "list": {
                  "custom_type": {
                    "import": "github.com/hashicorp/terraform-plugin-framework/types/basetypes",
                    "type": "basetypes.ListType",
                    "value_type": "basetypes.ListValue"
                  },
                  "string": {}
                }
              }
            }
          },
```

It may make sense to reintroduce what was originally designed in the specification with the verbose `ElementType` property for clarity.

```json
          {
            "name": "map_list_string_attribute",
            "map": {
              "computed_optional_required": "computed",
              "element_type": {
                "list": {
                  "custom_type": {
                    "import": "github.com/hashicorp/terraform-plugin-framework/types/basetypes",
                    "type": "basetypes.ListType",
                    "value_type": "basetypes.ListValue"
                  },
                  "element_type": {
                    "string": {}
                  }
                }
              }
            }
          },
```
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

Makes sense to me 🚀 - I opened hashicorp/terraform-plugin-codegen-openapi#17 to update the OpenAPI generator

@bflad bflad merged commit 3f47c20 into main Jun 21, 2023
@bflad bflad deleted the bflad/object-custom-type branch June 21, 2023 14:23
bflad added a commit that referenced this pull request Jun 22, 2023
…ect property

Reference: #26

For consistency with collection attribute types which use an explicit `element_type` object property and object types which use an explicit `attribute_types` property. An additional benefit is that it further distinguishes where a `custom_type` may apply.

Previous implementations:

```json
{
            "name": "list_map_attribute",
            "list": {
              "computed_optional_required": "computed",
              "element_type": {
                "map": {
                  "string": {}
                }
              }
            }
          },
```

Are now defined as:

```json
          {
            "name": "list_map_attribute",
            "list": {
              "computed_optional_required": "computed",
              "element_type": {
                "map": {
                  "element_type": {
                    "string": {}
                  }
                }
              }
            }
          },
```

The Go bindings and any consuming code do not require changes since Go implicitly required the `ElementType` field definition, even when it was using type embedding.
bflad added a commit that referenced this pull request Jun 22, 2023
…ect property (#29)

Reference: #26

For consistency with collection attribute types which use an explicit `element_type` object property and object types which use an explicit `attribute_types` property. An additional benefit is that it further distinguishes where a `custom_type` may apply.

Previous implementations:

```json
{
            "name": "list_map_attribute",
            "list": {
              "computed_optional_required": "computed",
              "element_type": {
                "map": {
                  "string": {}
                }
              }
            }
          },
```

Are now defined as:

```json
          {
            "name": "list_map_attribute",
            "list": {
              "computed_optional_required": "computed",
              "element_type": {
                "map": {
                  "element_type": {
                    "string": {}
                  }
                }
              }
            }
          },
```

The Go bindings and any consuming code do not require changes since Go implicitly required the `ElementType` field definition, even when it was using type embedding.
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CustomType to the Specification Go Bindings

2 participants