-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathnested_attribute_object.go
More file actions
72 lines (53 loc) · 1.69 KB
/
nested_attribute_object.go
File metadata and controls
72 lines (53 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0
package convert
import (
"bytes"
specschema "github.com/hashicorp/terraform-plugin-codegen-spec/schema"
"github.com/hashicorp/terraform-plugin-codegen-framework/internal/schema"
)
type NestedAttributeObject struct {
attributes schema.GeneratorAttributes
customType CustomTypeNestedObject
validators Validators
}
// NewNestedAttributeObject constructs a NestedAttributeObject which is used to generate a
// nested attribute object in the schema.
func NewNestedAttributeObject(a schema.GeneratorAttributes, c *specschema.CustomType, v Validators, name string) NestedAttributeObject {
return NestedAttributeObject{
attributes: a,
customType: NewCustomTypeNestedObject(c, name),
validators: v,
}
}
func (n NestedAttributeObject) Equal(other NestedAttributeObject) bool {
if !n.attributes.Equal(other.attributes) {
return false
}
if !n.customType.Equal(other.customType) {
return false
}
return n.validators.Equal(other.validators)
}
func (n NestedAttributeObject) Imports() *schema.Imports {
imports := schema.NewImports()
imports.Append(n.customType.Imports())
imports.Append(n.validators.Imports())
imports.Append(n.attributes.Imports())
return imports
}
func (n NestedAttributeObject) Schema() ([]byte, error) {
var b bytes.Buffer
attributesSchema, err := n.attributes.Schema()
if err != nil {
return nil, err
}
b.WriteString("NestedObject: schema.NestedAttributeObject{\n")
b.WriteString("Attributes: map[string]schema.Attribute{")
b.WriteString(attributesSchema)
b.WriteString("\n},\n")
b.Write(n.customType.Schema())
b.Write(n.validators.Schema())
b.WriteString("},\n")
return b.Bytes(), nil
}