diff --git a/internal/config/parse.go b/internal/config/parse.go index a628e8aa..1f4cd9b2 100644 --- a/internal/config/parse.go +++ b/internal/config/parse.go @@ -82,6 +82,10 @@ type AttributeOptions struct { type Override struct { // Description overrides the description that was mapped/merged from the OpenAPI specification. Description string `yaml:"description"` + // Schema overrides the schema that was mapped/merged from the OpenAPI specification. + Schema SchemaOptions `yaml:"schema"` + // A power tool to perform any arbitrary override of or insertion - not validated against OpenAPI spec. + CustomOverrides map[string]string `yaml:"custom_overrides"` } // ParseConfig takes in a byte array (of YAML), unmarshals into a Config struct, and validates the result diff --git a/internal/explorer/config_explorer.go b/internal/explorer/config_explorer.go index cc5fa13d..79d99617 100644 --- a/internal/explorer/config_explorer.go +++ b/internal/explorer/config_explorer.go @@ -198,20 +198,22 @@ func extractSchemaProxy(document high.Document, componentRef string) (*highbase. return highbase.CreateSchemaProxy(highSchema), nil } -func extractSchemaOptions(cfgSchemaOpts config.SchemaOptions) SchemaOptions { - return SchemaOptions{ +func extractSchemaOptions(cfgSchemaOpts config.SchemaOptions) config.SchemaOptions { + return config.SchemaOptions{ Ignores: cfgSchemaOpts.Ignores, - AttributeOptions: AttributeOptions{ + AttributeOptions: config.AttributeOptions{ Aliases: cfgSchemaOpts.AttributeOptions.Aliases, Overrides: extractOverrides(cfgSchemaOpts.AttributeOptions.Overrides), }, } } -func extractOverrides(cfgOverrides map[string]config.Override) map[string]Override { - overrides := make(map[string]Override, len(cfgOverrides)) +func extractOverrides(cfgOverrides map[string]config.Override) map[string]config.Override { + overrides := make(map[string]config.Override, len(cfgOverrides)) for key, cfgOverride := range cfgOverrides { - overrides[key] = Override{Description: cfgOverride.Description} + overrides[key] = config.Override{Description: cfgOverride.Description} + overrides[key] = config.Override{CustomOverrides: cfgOverride.CustomOverrides} + overrides[key] = config.Override{Schema: cfgOverride.Schema} } return overrides diff --git a/internal/explorer/config_explorer_test.go b/internal/explorer/config_explorer_test.go index 36fa2cf1..ac3e5238 100644 --- a/internal/explorer/config_explorer_test.go +++ b/internal/explorer/config_explorer_test.go @@ -92,9 +92,9 @@ func Test_ConfigExplorer_FindResources(t *testing.T) { Description: "delete op here", OperationId: "delete_resource", }, - SchemaOptions: explorer.SchemaOptions{ - AttributeOptions: explorer.AttributeOptions{ - Overrides: map[string]explorer.Override{}, + SchemaOptions: config.SchemaOptions{ + AttributeOptions: config.AttributeOptions{ + Overrides: map[string]config.Override{}, }, }, }, @@ -165,9 +165,9 @@ func Test_ConfigExplorer_FindResources(t *testing.T) { Description: "delete op here", OperationId: "delete_resource", }, - SchemaOptions: explorer.SchemaOptions{ - AttributeOptions: explorer.AttributeOptions{ - Overrides: map[string]explorer.Override{}, + SchemaOptions: config.SchemaOptions{ + AttributeOptions: config.AttributeOptions{ + Overrides: map[string]config.Override{}, }, }, }, @@ -302,13 +302,13 @@ func Test_ConfigExplorer_FindResources(t *testing.T) { Description: "read op here", OperationId: "read_resource", }, - SchemaOptions: explorer.SchemaOptions{ + SchemaOptions: config.SchemaOptions{ Ignores: []string{"ignore1.abc", "ignore2.def"}, - AttributeOptions: explorer.AttributeOptions{ + AttributeOptions: config.AttributeOptions{ Aliases: map[string]string{ "otherId": "id", }, - Overrides: map[string]explorer.Override{ + Overrides: map[string]config.Override{ "test": { Description: "test description for override", }, @@ -382,9 +382,9 @@ func Test_ConfigExplorer_FindDataSources(t *testing.T) { Description: "read op here", OperationId: "read_resource", }, - SchemaOptions: explorer.SchemaOptions{ - AttributeOptions: explorer.AttributeOptions{ - Overrides: map[string]explorer.Override{}, + SchemaOptions: config.SchemaOptions{ + AttributeOptions: config.AttributeOptions{ + Overrides: map[string]config.Override{}, }, }, }, @@ -415,9 +415,9 @@ func Test_ConfigExplorer_FindDataSources(t *testing.T) { Description: "read op here", OperationId: "read_resource", }, - SchemaOptions: explorer.SchemaOptions{ - AttributeOptions: explorer.AttributeOptions{ - Overrides: map[string]explorer.Override{}, + SchemaOptions: config.SchemaOptions{ + AttributeOptions: config.AttributeOptions{ + Overrides: map[string]config.Override{}, }, }, }, @@ -496,13 +496,13 @@ func Test_ConfigExplorer_FindDataSources(t *testing.T) { Description: "read op here", OperationId: "read_resource", }, - SchemaOptions: explorer.SchemaOptions{ + SchemaOptions: config.SchemaOptions{ Ignores: []string{"ignore1.abc", "ignore2.def"}, - AttributeOptions: explorer.AttributeOptions{ + AttributeOptions: config.AttributeOptions{ Aliases: map[string]string{ "otherId": "id", }, - Overrides: map[string]explorer.Override{ + Overrides: map[string]config.Override{ "test": { Description: "test description for override", }, diff --git a/internal/explorer/explorer.go b/internal/explorer/explorer.go index 908b62c9..e8f55458 100644 --- a/internal/explorer/explorer.go +++ b/internal/explorer/explorer.go @@ -4,7 +4,9 @@ package explorer import ( + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/pb33f/libopenapi/datamodel/high/base" + high "github.com/pb33f/libopenapi/datamodel/high/v3" ) @@ -22,14 +24,14 @@ type Resource struct { UpdateOp *high.Operation DeleteOp *high.Operation CommonParameters []*high.Parameter - SchemaOptions SchemaOptions + SchemaOptions config.SchemaOptions } // DataSource contains a Read operation and schema options for configuration. type DataSource struct { ReadOp *high.Operation CommonParameters []*high.Parameter - SchemaOptions SchemaOptions + SchemaOptions config.SchemaOptions } // Provider contains a name and a schema. @@ -38,17 +40,3 @@ type Provider struct { SchemaProxy *base.SchemaProxy Ignores []string } - -type SchemaOptions struct { - Ignores []string - AttributeOptions AttributeOptions -} - -type AttributeOptions struct { - Aliases map[string]string - Overrides map[string]Override -} - -type Override struct { - Description string -} diff --git a/internal/mapper/attrmapper/bool.go b/internal/mapper/attrmapper/bool.go index 7b6fb922..9e6fcbb7 100644 --- a/internal/mapper/attrmapper/bool.go +++ b/internal/mapper/attrmapper/bool.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -31,7 +31,7 @@ func (a *ResourceBoolAttribute) Merge(mergeAttribute ResourceAttribute) (Resourc return a, nil } -func (a *ResourceBoolAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceBoolAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil @@ -64,7 +64,7 @@ func (a *DataSourceBoolAttribute) Merge(mergeAttribute DataSourceAttribute) (Dat return a, nil } -func (a *DataSourceBoolAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceBoolAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil diff --git a/internal/mapper/attrmapper/bool_test.go b/internal/mapper/attrmapper/bool_test.go index 5078eba9..df710018 100644 --- a/internal/mapper/attrmapper/bool_test.go +++ b/internal/mapper/attrmapper/bool_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -131,7 +131,7 @@ func TestResourceBoolAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceBoolAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -142,7 +142,7 @@ func TestResourceBoolAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceBoolAttribute{ @@ -285,7 +285,7 @@ func TestDataSourceBoolAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceBoolAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -296,7 +296,7 @@ func TestDataSourceBoolAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceBoolAttribute{ diff --git a/internal/mapper/attrmapper/data_source_attributes.go b/internal/mapper/attrmapper/data_source_attributes.go index e1dc435e..80142dc7 100644 --- a/internal/mapper/attrmapper/data_source_attributes.go +++ b/internal/mapper/attrmapper/data_source_attributes.go @@ -7,19 +7,19 @@ import ( "errors" "strings" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" ) type DataSourceAttribute interface { GetName() string Merge(DataSourceAttribute) (DataSourceAttribute, error) - ApplyOverride(explorer.Override) (DataSourceAttribute, error) + ApplyOverride(config.Override) (DataSourceAttribute, error) ToSpec() datasource.Attribute } type DataSourceNestedAttribute interface { - ApplyNestedOverride([]string, explorer.Override) (DataSourceAttribute, error) + ApplyNestedOverride([]string, config.Override) (DataSourceAttribute, error) } type DataSourceAttributes []DataSourceAttribute @@ -67,7 +67,7 @@ func (attributes DataSourceAttributes) ToSpec() []datasource.Attribute { return specAttributes } -func (attributes DataSourceAttributes) ApplyOverrides(overrideMap map[string]explorer.Override) (DataSourceAttributes, error) { +func (attributes DataSourceAttributes) ApplyOverrides(overrideMap map[string]config.Override) (DataSourceAttributes, error) { var errResult error for key, override := range overrideMap { var err error @@ -78,7 +78,7 @@ func (attributes DataSourceAttributes) ApplyOverrides(overrideMap map[string]exp return attributes, errResult } -func (attributes DataSourceAttributes) ApplyOverride(path []string, override explorer.Override) (DataSourceAttributes, error) { +func (attributes DataSourceAttributes) ApplyOverride(path []string, override config.Override) (DataSourceAttributes, error) { var errResult error if len(path) == 0 { return attributes, errResult diff --git a/internal/mapper/attrmapper/data_source_attributes_test.go b/internal/mapper/attrmapper/data_source_attributes_test.go index 86942209..d1746954 100644 --- a/internal/mapper/attrmapper/data_source_attributes_test.go +++ b/internal/mapper/attrmapper/data_source_attributes_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/schema" @@ -204,13 +204,13 @@ func TestDataSourceAttributes_ApplyOverrides(t *testing.T) { t.Parallel() testCases := map[string]struct { - overrides map[string]explorer.Override + overrides map[string]config.Override attributes attrmapper.DataSourceAttributes expectedAttributes attrmapper.DataSourceAttributes }{ // TODO: this may eventually return an error, but for now just returns without modification "no matching overrides": { - overrides: map[string]explorer.Override{ + overrides: map[string]config.Override{ "": { Description: "new description", }, @@ -241,7 +241,7 @@ func TestDataSourceAttributes_ApplyOverrides(t *testing.T) { }, }, "matching overrides": { - overrides: map[string]explorer.Override{ + overrides: map[string]config.Override{ "string_attribute": { Description: "new string description", }, @@ -283,7 +283,7 @@ func TestDataSourceAttributes_ApplyOverrides(t *testing.T) { }, }, "matching nested overrides": { - overrides: map[string]explorer.Override{ + overrides: map[string]config.Override{ "single_nested": { Description: "new description", }, diff --git a/internal/mapper/attrmapper/float64.go b/internal/mapper/attrmapper/float64.go index 7a6680cd..d66ace8b 100644 --- a/internal/mapper/attrmapper/float64.go +++ b/internal/mapper/attrmapper/float64.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -31,7 +31,7 @@ func (a *ResourceFloat64Attribute) Merge(mergeAttribute ResourceAttribute) (Reso return a, nil } -func (a *ResourceFloat64Attribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceFloat64Attribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil @@ -64,7 +64,7 @@ func (a *DataSourceFloat64Attribute) Merge(mergeAttribute DataSourceAttribute) ( return a, nil } -func (a *DataSourceFloat64Attribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceFloat64Attribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil diff --git a/internal/mapper/attrmapper/float64_test.go b/internal/mapper/attrmapper/float64_test.go index 958dff4a..a3ea11e6 100644 --- a/internal/mapper/attrmapper/float64_test.go +++ b/internal/mapper/attrmapper/float64_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -131,7 +131,7 @@ func TestResourceFloat64Attribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceFloat64Attribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -142,7 +142,7 @@ func TestResourceFloat64Attribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceFloat64Attribute{ @@ -285,7 +285,7 @@ func TestDataSourceFloat64Attribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceFloat64Attribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -296,7 +296,7 @@ func TestDataSourceFloat64Attribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceFloat64Attribute{ diff --git a/internal/mapper/attrmapper/int64.go b/internal/mapper/attrmapper/int64.go index 0c0fe758..975d0eb2 100644 --- a/internal/mapper/attrmapper/int64.go +++ b/internal/mapper/attrmapper/int64.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -31,7 +31,7 @@ func (a *ResourceInt64Attribute) Merge(mergeAttribute ResourceAttribute) (Resour return a, nil } -func (a *ResourceInt64Attribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceInt64Attribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil @@ -64,7 +64,7 @@ func (a *DataSourceInt64Attribute) Merge(mergeAttribute DataSourceAttribute) (Da return a, nil } -func (a *DataSourceInt64Attribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceInt64Attribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil diff --git a/internal/mapper/attrmapper/int64_test.go b/internal/mapper/attrmapper/int64_test.go index 28c67322..215b2b8f 100644 --- a/internal/mapper/attrmapper/int64_test.go +++ b/internal/mapper/attrmapper/int64_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -131,7 +131,7 @@ func TestResourceInt64Attribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceInt64Attribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -142,7 +142,7 @@ func TestResourceInt64Attribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceInt64Attribute{ @@ -285,7 +285,7 @@ func TestDataSourceInt64Attribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceInt64Attribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -296,7 +296,7 @@ func TestDataSourceInt64Attribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceInt64Attribute{ diff --git a/internal/mapper/attrmapper/list.go b/internal/mapper/attrmapper/list.go index 2a1c0eb8..397e362d 100644 --- a/internal/mapper/attrmapper/list.go +++ b/internal/mapper/attrmapper/list.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -36,7 +36,7 @@ func (a *ResourceListAttribute) Merge(mergeAttribute ResourceAttribute) (Resourc return a, nil } -func (a *ResourceListAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceListAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil @@ -74,7 +74,7 @@ func (a *DataSourceListAttribute) Merge(mergeAttribute DataSourceAttribute) (Dat return a, nil } -func (a *DataSourceListAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceListAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil diff --git a/internal/mapper/attrmapper/list_nested.go b/internal/mapper/attrmapper/list_nested.go index 68e07375..26626cbd 100644 --- a/internal/mapper/attrmapper/list_nested.go +++ b/internal/mapper/attrmapper/list_nested.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -37,13 +37,13 @@ func (a *ResourceListNestedAttribute) Merge(mergeAttribute ResourceAttribute) (R return a, nil } -func (a *ResourceListNestedAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceListNestedAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil } -func (a *ResourceListNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceListNestedAttribute) ApplyNestedOverride(path []string, override config.Override) (ResourceAttribute, error) { var err error a.NestedObject.Attributes, err = a.NestedObject.Attributes.ApplyOverride(path, override) @@ -87,13 +87,13 @@ func (a *DataSourceListNestedAttribute) Merge(mergeAttribute DataSourceAttribute return a, nil } -func (a *DataSourceListNestedAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceListNestedAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil } -func (a *DataSourceListNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceListNestedAttribute) ApplyNestedOverride(path []string, override config.Override) (DataSourceAttribute, error) { var err error a.NestedObject.Attributes, err = a.NestedObject.Attributes.ApplyOverride(path, override) diff --git a/internal/mapper/attrmapper/list_nested_test.go b/internal/mapper/attrmapper/list_nested_test.go index f457fee5..5c40425b 100644 --- a/internal/mapper/attrmapper/list_nested_test.go +++ b/internal/mapper/attrmapper/list_nested_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -366,7 +366,7 @@ func TestResourceListNestedAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceListNestedAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -387,7 +387,7 @@ func TestResourceListNestedAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceListNestedAttribute{ @@ -429,7 +429,7 @@ func TestResourceListNestedAttribute_ApplyNestedOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceListNestedAttribute overridePath []string - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override nested attribute": { @@ -463,7 +463,7 @@ func TestResourceListNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceListNestedAttribute{ @@ -525,7 +525,7 @@ func TestResourceListNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute", "double_nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceListNestedAttribute{ @@ -924,7 +924,7 @@ func TestDataSourceListNestedAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceListNestedAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -945,7 +945,7 @@ func TestDataSourceListNestedAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceListNestedAttribute{ @@ -987,7 +987,7 @@ func TestDataSourceListNestedAttribute_ApplyNestedOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceListNestedAttribute overridePath []string - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override nested attribute": { @@ -1021,7 +1021,7 @@ func TestDataSourceListNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceListNestedAttribute{ @@ -1083,7 +1083,7 @@ func TestDataSourceListNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute", "double_nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceListNestedAttribute{ diff --git a/internal/mapper/attrmapper/list_test.go b/internal/mapper/attrmapper/list_test.go index 63508261..e944e1ad 100644 --- a/internal/mapper/attrmapper/list_test.go +++ b/internal/mapper/attrmapper/list_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -485,7 +485,7 @@ func TestResourceListAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceListAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -499,7 +499,7 @@ func TestResourceListAttribute_ApplyOverride(t *testing.T) { }, }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceListAttribute{ @@ -999,7 +999,7 @@ func TestDataSourceListAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceListAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -1013,7 +1013,7 @@ func TestDataSourceListAttribute_ApplyOverride(t *testing.T) { }, }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceListAttribute{ diff --git a/internal/mapper/attrmapper/map.go b/internal/mapper/attrmapper/map.go index f25c8a59..5ed84763 100644 --- a/internal/mapper/attrmapper/map.go +++ b/internal/mapper/attrmapper/map.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -36,7 +36,7 @@ func (a *ResourceMapAttribute) Merge(mergeAttribute ResourceAttribute) (Resource return a, nil } -func (a *ResourceMapAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceMapAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil @@ -74,7 +74,7 @@ func (a *DataSourceMapAttribute) Merge(mergeAttribute DataSourceAttribute) (Data return a, nil } -func (a *DataSourceMapAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceMapAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil diff --git a/internal/mapper/attrmapper/map_nested.go b/internal/mapper/attrmapper/map_nested.go index 4ba7f40a..d3da125e 100644 --- a/internal/mapper/attrmapper/map_nested.go +++ b/internal/mapper/attrmapper/map_nested.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -37,13 +37,13 @@ func (a *ResourceMapNestedAttribute) Merge(mergeAttribute ResourceAttribute) (Re return a, nil } -func (a *ResourceMapNestedAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceMapNestedAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil } -func (a *ResourceMapNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceMapNestedAttribute) ApplyNestedOverride(path []string, override config.Override) (ResourceAttribute, error) { var err error a.NestedObject.Attributes, err = a.NestedObject.Attributes.ApplyOverride(path, override) @@ -87,13 +87,13 @@ func (a *DataSourceMapNestedAttribute) Merge(mergeAttribute DataSourceAttribute) return a, nil } -func (a *DataSourceMapNestedAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceMapNestedAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil } -func (a *DataSourceMapNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceMapNestedAttribute) ApplyNestedOverride(path []string, override config.Override) (DataSourceAttribute, error) { var err error a.NestedObject.Attributes, err = a.NestedObject.Attributes.ApplyOverride(path, override) diff --git a/internal/mapper/attrmapper/map_nested_test.go b/internal/mapper/attrmapper/map_nested_test.go index e25e4df0..67a98fb0 100644 --- a/internal/mapper/attrmapper/map_nested_test.go +++ b/internal/mapper/attrmapper/map_nested_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -366,7 +366,7 @@ func TestResourceMapNestedAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceMapNestedAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -387,7 +387,7 @@ func TestResourceMapNestedAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceMapNestedAttribute{ @@ -429,7 +429,7 @@ func TestResourceMapNestedAttribute_ApplyNestedOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceMapNestedAttribute overridePath []string - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override nested attribute": { @@ -463,7 +463,7 @@ func TestResourceMapNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceMapNestedAttribute{ @@ -525,7 +525,7 @@ func TestResourceMapNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute", "double_nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceMapNestedAttribute{ @@ -924,7 +924,7 @@ func TestDataSourceMapNestedAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceMapNestedAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -945,7 +945,7 @@ func TestDataSourceMapNestedAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceMapNestedAttribute{ @@ -987,7 +987,7 @@ func TestDataSourceMapNestedAttribute_ApplyNestedOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceMapNestedAttribute overridePath []string - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override nested attribute": { @@ -1021,7 +1021,7 @@ func TestDataSourceMapNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceMapNestedAttribute{ @@ -1083,7 +1083,7 @@ func TestDataSourceMapNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute", "double_nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceMapNestedAttribute{ diff --git a/internal/mapper/attrmapper/map_test.go b/internal/mapper/attrmapper/map_test.go index e02f30db..6da9dc17 100644 --- a/internal/mapper/attrmapper/map_test.go +++ b/internal/mapper/attrmapper/map_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -485,7 +485,7 @@ func TestResourceMapAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceMapAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -499,7 +499,7 @@ func TestResourceMapAttribute_ApplyOverride(t *testing.T) { }, }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceMapAttribute{ @@ -999,7 +999,7 @@ func TestDataSourceMapAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceMapAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -1013,7 +1013,7 @@ func TestDataSourceMapAttribute_ApplyOverride(t *testing.T) { }, }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceMapAttribute{ diff --git a/internal/mapper/attrmapper/number.go b/internal/mapper/attrmapper/number.go index f47b8da9..8fb66520 100644 --- a/internal/mapper/attrmapper/number.go +++ b/internal/mapper/attrmapper/number.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -31,7 +31,7 @@ func (a *ResourceNumberAttribute) Merge(mergeAttribute ResourceAttribute) (Resou return a, nil } -func (a *ResourceNumberAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceNumberAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil @@ -64,7 +64,7 @@ func (a *DataSourceNumberAttribute) Merge(mergeAttribute DataSourceAttribute) (D return a, nil } -func (a *DataSourceNumberAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceNumberAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil diff --git a/internal/mapper/attrmapper/number_test.go b/internal/mapper/attrmapper/number_test.go index 633a2352..2e096824 100644 --- a/internal/mapper/attrmapper/number_test.go +++ b/internal/mapper/attrmapper/number_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -131,7 +131,7 @@ func TestResourceNumberAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceNumberAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -142,7 +142,7 @@ func TestResourceNumberAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceNumberAttribute{ @@ -285,7 +285,7 @@ func TestDataSourceNumberAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceNumberAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -296,7 +296,7 @@ func TestDataSourceNumberAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceNumberAttribute{ diff --git a/internal/mapper/attrmapper/resource_attributes.go b/internal/mapper/attrmapper/resource_attributes.go index 6c772c26..8cf2a045 100644 --- a/internal/mapper/attrmapper/resource_attributes.go +++ b/internal/mapper/attrmapper/resource_attributes.go @@ -7,19 +7,19 @@ import ( "errors" "strings" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" ) type ResourceAttribute interface { GetName() string Merge(ResourceAttribute) (ResourceAttribute, error) - ApplyOverride(explorer.Override) (ResourceAttribute, error) + ApplyOverride(config.Override) (ResourceAttribute, error) ToSpec() resource.Attribute } type ResourceNestedAttribute interface { - ApplyNestedOverride([]string, explorer.Override) (ResourceAttribute, error) + ApplyNestedOverride([]string, config.Override) (ResourceAttribute, error) } type ResourceAttributes []ResourceAttribute @@ -67,7 +67,7 @@ func (attributes ResourceAttributes) ToSpec() []resource.Attribute { return specAttributes } -func (attributes ResourceAttributes) ApplyOverrides(overrideMap map[string]explorer.Override) (ResourceAttributes, error) { +func (attributes ResourceAttributes) ApplyOverrides(overrideMap map[string]config.Override) (ResourceAttributes, error) { var errResult error for key, override := range overrideMap { var err error @@ -78,7 +78,7 @@ func (attributes ResourceAttributes) ApplyOverrides(overrideMap map[string]explo return attributes, errResult } -func (attributes ResourceAttributes) ApplyOverride(path []string, override explorer.Override) (ResourceAttributes, error) { +func (attributes ResourceAttributes) ApplyOverride(path []string, override config.Override) (ResourceAttributes, error) { var errResult error if len(path) == 0 { return attributes, errResult diff --git a/internal/mapper/attrmapper/resource_attributes_test.go b/internal/mapper/attrmapper/resource_attributes_test.go index 51aa3311..bd7d4bda 100644 --- a/internal/mapper/attrmapper/resource_attributes_test.go +++ b/internal/mapper/attrmapper/resource_attributes_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" "github.com/hashicorp/terraform-plugin-codegen-spec/schema" @@ -204,13 +204,13 @@ func TestResourceAttributes_ApplyOverrides(t *testing.T) { t.Parallel() testCases := map[string]struct { - overrides map[string]explorer.Override + overrides map[string]config.Override attributes attrmapper.ResourceAttributes expectedAttributes attrmapper.ResourceAttributes }{ // TODO: this may eventually return an error, but for now just returns without modification "no matching overrides": { - overrides: map[string]explorer.Override{ + overrides: map[string]config.Override{ "": { Description: "new description", }, @@ -241,7 +241,7 @@ func TestResourceAttributes_ApplyOverrides(t *testing.T) { }, }, "matching overrides": { - overrides: map[string]explorer.Override{ + overrides: map[string]config.Override{ "string_attribute": { Description: "new string description", }, @@ -283,7 +283,7 @@ func TestResourceAttributes_ApplyOverrides(t *testing.T) { }, }, "matching nested overrides": { - overrides: map[string]explorer.Override{ + overrides: map[string]config.Override{ "single_nested": { Description: "new description", }, diff --git a/internal/mapper/attrmapper/set.go b/internal/mapper/attrmapper/set.go index a1c031b7..eaa5d610 100644 --- a/internal/mapper/attrmapper/set.go +++ b/internal/mapper/attrmapper/set.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -36,7 +36,7 @@ func (a *ResourceSetAttribute) Merge(mergeAttribute ResourceAttribute) (Resource return a, nil } -func (a *ResourceSetAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceSetAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil @@ -74,7 +74,7 @@ func (a *DataSourceSetAttribute) Merge(mergeAttribute DataSourceAttribute) (Data return a, nil } -func (a *DataSourceSetAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceSetAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil diff --git a/internal/mapper/attrmapper/set_nested.go b/internal/mapper/attrmapper/set_nested.go index 082a61ef..1707c591 100644 --- a/internal/mapper/attrmapper/set_nested.go +++ b/internal/mapper/attrmapper/set_nested.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -37,13 +37,13 @@ func (a *ResourceSetNestedAttribute) Merge(mergeAttribute ResourceAttribute) (Re return a, nil } -func (a *ResourceSetNestedAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceSetNestedAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil } -func (a *ResourceSetNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceSetNestedAttribute) ApplyNestedOverride(path []string, override config.Override) (ResourceAttribute, error) { var err error a.NestedObject.Attributes, err = a.NestedObject.Attributes.ApplyOverride(path, override) @@ -87,13 +87,13 @@ func (a *DataSourceSetNestedAttribute) Merge(mergeAttribute DataSourceAttribute) return a, nil } -func (a *DataSourceSetNestedAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceSetNestedAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil } -func (a *DataSourceSetNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceSetNestedAttribute) ApplyNestedOverride(path []string, override config.Override) (DataSourceAttribute, error) { var err error a.NestedObject.Attributes, err = a.NestedObject.Attributes.ApplyOverride(path, override) diff --git a/internal/mapper/attrmapper/set_nested_test.go b/internal/mapper/attrmapper/set_nested_test.go index cd67f6a6..4bc36ef5 100644 --- a/internal/mapper/attrmapper/set_nested_test.go +++ b/internal/mapper/attrmapper/set_nested_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -366,7 +366,7 @@ func TestResourceSetNestedAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceSetNestedAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -387,7 +387,7 @@ func TestResourceSetNestedAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceSetNestedAttribute{ @@ -429,7 +429,7 @@ func TestResourceSetNestedAttribute_ApplyNestedOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceSetNestedAttribute overridePath []string - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override nested attribute": { @@ -463,7 +463,7 @@ func TestResourceSetNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceSetNestedAttribute{ @@ -525,7 +525,7 @@ func TestResourceSetNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute", "double_nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceSetNestedAttribute{ @@ -924,7 +924,7 @@ func TestDataSourceSetNestedAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceSetNestedAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -945,7 +945,7 @@ func TestDataSourceSetNestedAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceSetNestedAttribute{ @@ -987,7 +987,7 @@ func TestDataSourceSetNestedAttribute_ApplyNestedOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceSetNestedAttribute overridePath []string - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override nested attribute": { @@ -1021,7 +1021,7 @@ func TestDataSourceSetNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceSetNestedAttribute{ @@ -1083,7 +1083,7 @@ func TestDataSourceSetNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute", "double_nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceSetNestedAttribute{ diff --git a/internal/mapper/attrmapper/set_test.go b/internal/mapper/attrmapper/set_test.go index 06f5b962..48bddc7c 100644 --- a/internal/mapper/attrmapper/set_test.go +++ b/internal/mapper/attrmapper/set_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -485,7 +485,7 @@ func TestResourceSetAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceSetAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -499,7 +499,7 @@ func TestResourceSetAttribute_ApplyOverride(t *testing.T) { }, }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceSetAttribute{ @@ -999,7 +999,7 @@ func TestDataSourceSetAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceSetAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -1013,7 +1013,7 @@ func TestDataSourceSetAttribute_ApplyOverride(t *testing.T) { }, }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceSetAttribute{ diff --git a/internal/mapper/attrmapper/single_nested.go b/internal/mapper/attrmapper/single_nested.go index e83f1055..b52f86d1 100644 --- a/internal/mapper/attrmapper/single_nested.go +++ b/internal/mapper/attrmapper/single_nested.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -37,13 +37,13 @@ func (a *ResourceSingleNestedAttribute) Merge(mergeAttribute ResourceAttribute) return a, nil } -func (a *ResourceSingleNestedAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceSingleNestedAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil } -func (a *ResourceSingleNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceSingleNestedAttribute) ApplyNestedOverride(path []string, override config.Override) (ResourceAttribute, error) { var err error a.Attributes, err = a.Attributes.ApplyOverride(path, override) @@ -85,13 +85,13 @@ func (a *DataSourceSingleNestedAttribute) Merge(mergeAttribute DataSourceAttribu return a, nil } -func (a *DataSourceSingleNestedAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceSingleNestedAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil } -func (a *DataSourceSingleNestedAttribute) ApplyNestedOverride(path []string, override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceSingleNestedAttribute) ApplyNestedOverride(path []string, override config.Override) (DataSourceAttribute, error) { var err error a.Attributes, err = a.Attributes.ApplyOverride(path, override) diff --git a/internal/mapper/attrmapper/single_nested_test.go b/internal/mapper/attrmapper/single_nested_test.go index e94fd0ff..be03dfd4 100644 --- a/internal/mapper/attrmapper/single_nested_test.go +++ b/internal/mapper/attrmapper/single_nested_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -332,7 +332,7 @@ func TestResourceSingleNestedAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceSingleNestedAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -351,7 +351,7 @@ func TestResourceSingleNestedAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceSingleNestedAttribute{ @@ -391,7 +391,7 @@ func TestResourceSingleNestedAttribute_ApplyNestedOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceSingleNestedAttribute overridePath []string - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override nested attribute": { @@ -420,7 +420,7 @@ func TestResourceSingleNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceSingleNestedAttribute{ @@ -474,7 +474,7 @@ func TestResourceSingleNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute", "double_nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceSingleNestedAttribute{ @@ -835,7 +835,7 @@ func TestDataSourceSingleNestedAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceSingleNestedAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -854,7 +854,7 @@ func TestDataSourceSingleNestedAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceSingleNestedAttribute{ @@ -894,7 +894,7 @@ func TestDataSourceSingleNestedAttribute_ApplyNestedOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceSingleNestedAttribute overridePath []string - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override nested attribute": { @@ -923,7 +923,7 @@ func TestDataSourceSingleNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceSingleNestedAttribute{ @@ -977,7 +977,7 @@ func TestDataSourceSingleNestedAttribute_ApplyNestedOverride(t *testing.T) { }, }, overridePath: []string{"nested_attribute", "double_nested_attribute"}, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceSingleNestedAttribute{ diff --git a/internal/mapper/attrmapper/string.go b/internal/mapper/attrmapper/string.go index fc54a6ab..0d54b52b 100644 --- a/internal/mapper/attrmapper/string.go +++ b/internal/mapper/attrmapper/string.go @@ -4,7 +4,7 @@ package attrmapper import ( - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/provider" @@ -31,7 +31,7 @@ func (a *ResourceStringAttribute) Merge(mergeAttribute ResourceAttribute) (Resou return a, nil } -func (a *ResourceStringAttribute) ApplyOverride(override explorer.Override) (ResourceAttribute, error) { +func (a *ResourceStringAttribute) ApplyOverride(override config.Override) (ResourceAttribute, error) { a.Description = &override.Description return a, nil @@ -64,7 +64,7 @@ func (a *DataSourceStringAttribute) Merge(mergeAttribute DataSourceAttribute) (D return a, nil } -func (a *DataSourceStringAttribute) ApplyOverride(override explorer.Override) (DataSourceAttribute, error) { +func (a *DataSourceStringAttribute) ApplyOverride(override config.Override) (DataSourceAttribute, error) { a.Description = &override.Description return a, nil diff --git a/internal/mapper/attrmapper/string_test.go b/internal/mapper/attrmapper/string_test.go index 09d254af..440f9c8e 100644 --- a/internal/mapper/attrmapper/string_test.go +++ b/internal/mapper/attrmapper/string_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer" + "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper" "github.com/hashicorp/terraform-plugin-codegen-spec/datasource" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" @@ -131,7 +131,7 @@ func TestResourceStringAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.ResourceStringAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.ResourceAttribute }{ "override description": { @@ -142,7 +142,7 @@ func TestResourceStringAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.ResourceStringAttribute{ @@ -285,7 +285,7 @@ func TestDataSourceStringAttribute_ApplyOverride(t *testing.T) { testCases := map[string]struct { attribute attrmapper.DataSourceStringAttribute - override explorer.Override + override config.Override expectedAttribute attrmapper.DataSourceAttribute }{ "override description": { @@ -296,7 +296,7 @@ func TestDataSourceStringAttribute_ApplyOverride(t *testing.T) { Description: pointer("old description"), }, }, - override: explorer.Override{ + override: config.Override{ Description: "new description", }, expectedAttribute: &attrmapper.DataSourceStringAttribute{ diff --git a/internal/mapper/datasource_mapper_test.go b/internal/mapper/datasource_mapper_test.go index 55c9a2df..b0fd0120 100644 --- a/internal/mapper/datasource_mapper_test.go +++ b/internal/mapper/datasource_mapper_test.go @@ -26,7 +26,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) { testCases := map[string]struct { readResponseSchema *base.SchemaProxy readParams []*high.Parameter - schemaOptions explorer.SchemaOptions + schemaOptions config.SchemaOptions want datasource.Attributes }{ "merge primitives across all ops": { @@ -622,8 +622,8 @@ func TestDataSourceMapper_basic_merges(t *testing.T) { }), }), }), - schemaOptions: explorer.SchemaOptions{ - AttributeOptions: explorer.AttributeOptions{ + schemaOptions: config.SchemaOptions{ + AttributeOptions: config.AttributeOptions{ Aliases: map[string]string{ "read_path_parameter": "attribute_required", "read_query_parameter": "attribute_computed_optional", @@ -646,7 +646,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) { }, }, "ignore bool prop across all ops": { - schemaOptions: explorer.SchemaOptions{ + schemaOptions: config.SchemaOptions{ Ignores: []string{ "bool_prop", "nested_obj.bool_prop", diff --git a/internal/mapper/oas/build.go b/internal/mapper/oas/build.go index bd763dfd..d5c60823 100644 --- a/internal/mapper/oas/build.go +++ b/internal/mapper/oas/build.go @@ -7,6 +7,8 @@ import ( "context" "errors" "fmt" + "log/slog" + "os" "strconv" "github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util" @@ -226,6 +228,10 @@ func getMultiTypeSchema(proxyOne *base.SchemaProxy, proxyTwo *base.SchemaProxy) // retrieveType will return the JSON schema type. Support for multi-types is restricted to combinations of "null" and another type, i.e. ["null", "string"] func retrieveType(schema *base.Schema) (string, *SchemaError) { + logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ + Level: slog.LevelWarn, + })) + switch len(schema.Type) { case 0: // Properties are only valid applying to objects, it's possible tools might omit the type @@ -234,7 +240,12 @@ func retrieveType(schema *base.Schema) (string, *SchemaError) { return util.OAS_type_object, nil } - return "", SchemaErrorFromProxy(errors.New("no 'type' array or supported allOf, oneOf, anyOf constraint - attribute cannot be created"), schema.ParentProxy) + var err *SchemaError = SchemaErrorFromProxy(errors.New("no 'type' array or supported allOf, oneOf, anyOf constraint - attribute will default to type string"), schema.ParentProxy) + + logger.Warn("schema type is empty - assigning default type of string", "err", SchemaErrorFromProxy(errors.New("no 'type' array or supported allOf, oneOf, anyOf constraint"), schema.ParentProxy)) + return util.OAS_type_string, err + + // return util.OAS_type_string, SchemaErrorFromProxy(errors.New("no 'type' array or supported allOf, oneOf, anyOf constraint - attribute cannot be created"), schema.ParentProxy) case 1: return schema.Type[0], nil case 2: diff --git a/internal/mapper/oas/build_test.go b/internal/mapper/oas/build_test.go index 7736170e..97ddba09 100644 --- a/internal/mapper/oas/build_test.go +++ b/internal/mapper/oas/build_test.go @@ -1103,7 +1103,7 @@ func TestBuildSchema_Errors(t *testing.T) { schemaProxy: base.CreateSchemaProxy(&base.Schema{ Type: []string{}, }), - expectedErrRegex: `no 'type' array or supported allOf, oneOf, anyOf constraint - attribute cannot be created`, + expectedErrRegex: `no 'type' array or supported allOf, oneOf, anyOf constraint - attribute will default to type string`, }, "unsupported multi-type array": { schemaProxy: base.CreateSchemaProxy(&base.Schema{ diff --git a/internal/mapper/resource_mapper_test.go b/internal/mapper/resource_mapper_test.go index 09cc42b2..e729e635 100644 --- a/internal/mapper/resource_mapper_test.go +++ b/internal/mapper/resource_mapper_test.go @@ -28,7 +28,7 @@ func TestResourceMapper_basic_merges(t *testing.T) { createResponseSchema *base.SchemaProxy readResponseSchema *base.SchemaProxy readParams []*high.Parameter - schemaOptions explorer.SchemaOptions + schemaOptions config.SchemaOptions want resource.Attributes }{ "merge primitives across all ops": { @@ -820,8 +820,8 @@ func TestResourceMapper_basic_merges(t *testing.T) { }), }), }), - schemaOptions: explorer.SchemaOptions{ - AttributeOptions: explorer.AttributeOptions{ + schemaOptions: config.SchemaOptions{ + AttributeOptions: config.AttributeOptions{ Aliases: map[string]string{ "read_path_parameter": "attribute_required", "read_query_parameter": "attribute_computed", @@ -844,7 +844,7 @@ func TestResourceMapper_basic_merges(t *testing.T) { }, }, "ignore bool prop across all ops": { - schemaOptions: explorer.SchemaOptions{ + schemaOptions: config.SchemaOptions{ Ignores: []string{ "bool_prop", "nested_obj.bool_prop",