From 4e58201c6cdb60ddb379d3ff295804f02b2e04cf Mon Sep 17 00:00:00 2001 From: Venelin Date: Thu, 2 Jan 2025 17:33:43 +0200 Subject: [PATCH] repro for 2803 --- ...eAttributeVsBlockSchemaNameOverride.golden | 97 +++++ ...estedCsharpOverrideAttributesSchema.golden | 123 ++++++ ...cksNestedCsharpOverrideBlocksSchema.golden | 110 ++++++ ...eAttributeVsBlockSchemaNameOverride.golden | 66 ++++ pkg/pf/tfgen/tfgen_test.go | 362 +++++++++++++++++- 5 files changed, 756 insertions(+), 2 deletions(-) create mode 100644 pkg/pf/tfgen/testdata/TestDataSourceAttributeVsBlockSchemaNameOverride.golden create mode 100644 pkg/pf/tfgen/testdata/TestRegressDatabricksNestedCsharpOverrideAttributesSchema.golden create mode 100644 pkg/pf/tfgen/testdata/TestRegressDatabricksNestedCsharpOverrideBlocksSchema.golden create mode 100644 pkg/pf/tfgen/testdata/TestResourceAttributeVsBlockSchemaNameOverride.golden diff --git a/pkg/pf/tfgen/testdata/TestDataSourceAttributeVsBlockSchemaNameOverride.golden b/pkg/pf/tfgen/testdata/TestDataSourceAttributeVsBlockSchemaNameOverride.golden new file mode 100644 index 000000000..19c9c068d --- /dev/null +++ b/pkg/pf/tfgen/testdata/TestDataSourceAttributeVsBlockSchemaNameOverride.golden @@ -0,0 +1,97 @@ +{ + "name": "testprovider", + "version": "0.0.1", + "attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).", + "meta": { + "moduleFormat": "(.*)(?:/[^/]*)" + }, + "language": { + "nodejs": { + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", + "compatibility": "tfbridge20", + "disableUnionOutputTypes": true + }, + "python": { + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", + "compatibility": "tfbridge20", + "pyproject": {} + } + }, + "config": {}, + "types": { + "testprovider:index/getAttrResCollection1:getAttrResCollection1": { + "properties": { + "prop": { + "type": "string" + } + }, + "type": "object" + }, + "testprovider:index/getBlockResCollection1:getBlockResCollection1": { + "properties": { + "prop1": { + "type": "string" + } + }, + "type": "object" + } + }, + "provider": { + "description": "The provider type for the testprovider package. By default, resources use package-wide configuration\nsettings, however an explicit `Provider` instance may be created and passed during resource\nconstruction to achieve fine-grained programmatic control over provider settings. See the\n[documentation](https://www.pulumi.com/docs/reference/programming-model/#providers) for more information.\n" + }, + "functions": { + "testprovider:index/getAttrRes:getAttrRes": { + "outputs": { + "description": "A collection of values returned by getAttrRes.\n", + "properties": { + "collection1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getAttrResCollection1:getAttrResCollection1" + } + }, + "id": { + "type": "string" + } + }, + "type": "object", + "required": [ + "collection1", + "id" + ] + } + }, + "testprovider:index/getBlockRes:getBlockRes": { + "inputs": { + "description": "A collection of arguments for invoking getBlockRes.\n", + "properties": { + "collection1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getBlockResCollection1:getBlockResCollection1" + } + } + }, + "type": "object" + }, + "outputs": { + "description": "A collection of values returned by getBlockRes.\n", + "properties": { + "collection1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getBlockResCollection1:getBlockResCollection1" + } + }, + "id": { + "type": "string" + } + }, + "type": "object", + "required": [ + "id" + ] + } + } + } +} \ No newline at end of file diff --git a/pkg/pf/tfgen/testdata/TestRegressDatabricksNestedCsharpOverrideAttributesSchema.golden b/pkg/pf/tfgen/testdata/TestRegressDatabricksNestedCsharpOverrideAttributesSchema.golden new file mode 100644 index 000000000..0ab108842 --- /dev/null +++ b/pkg/pf/tfgen/testdata/TestRegressDatabricksNestedCsharpOverrideAttributesSchema.golden @@ -0,0 +1,123 @@ +{ + "name": "testprovider", + "version": "0.0.1", + "attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).", + "meta": { + "moduleFormat": "(.*)(?:/[^/]*)" + }, + "language": { + "nodejs": { + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", + "compatibility": "tfbridge20", + "disableUnionOutputTypes": true + }, + "python": { + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", + "compatibility": "tfbridge20", + "pyproject": {} + } + }, + "config": {}, + "types": { + "testprovider:index/getServingEndpointsEndpoints1:getServingEndpointsEndpoints1": { + "properties": { + "aiGateways": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getServingEndpointsEndpoints1AiGateway:getServingEndpointsEndpoints1AiGateway" + } + } + }, + "type": "object", + "required": [ + "aiGateways" + ], + "language": { + "nodejs": { + "requiredInputs": [] + } + } + }, + "testprovider:index/getServingEndpointsEndpoints1AiGateway:getServingEndpointsEndpoints1AiGateway": { + "properties": { + "guardrails": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getServingEndpointsEndpoints1AiGatewayGuardrail:getServingEndpointsEndpoints1AiGatewayGuardrail" + } + } + }, + "type": "object", + "required": [ + "guardrails" + ], + "language": { + "nodejs": { + "requiredInputs": [] + } + } + }, + "testprovider:index/getServingEndpointsEndpoints1AiGatewayGuardrail:getServingEndpointsEndpoints1AiGatewayGuardrail": { + "properties": { + "inputs": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getServingEndpointsEndpoints1AiGatewayGuardrailInput:getServingEndpointsEndpoints1AiGatewayGuardrailInput" + } + } + }, + "type": "object", + "required": [ + "inputs" + ], + "language": { + "nodejs": { + "requiredInputs": [] + } + } + }, + "testprovider:index/getServingEndpointsEndpoints1AiGatewayGuardrailInput:getServingEndpointsEndpoints1AiGatewayGuardrailInput": { + "properties": { + "maxBatchSize": { + "type": "integer" + } + }, + "type": "object", + "required": [ + "maxBatchSize" + ], + "language": { + "nodejs": { + "requiredInputs": [] + } + } + } + }, + "provider": { + "description": "The provider type for the testprovider package. By default, resources use package-wide configuration\nsettings, however an explicit `Provider` instance may be created and passed during resource\nconstruction to achieve fine-grained programmatic control over provider settings. See the\n[documentation](https://www.pulumi.com/docs/reference/programming-model/#providers) for more information.\n" + }, + "functions": { + "testprovider:index/getServingEndpoints:getServingEndpoints": { + "outputs": { + "description": "A collection of values returned by getServingEndpoints.\n", + "properties": { + "endpoints1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getServingEndpointsEndpoints1:getServingEndpointsEndpoints1" + } + }, + "id": { + "type": "string", + "description": "The provider-assigned unique ID for this managed resource.\n" + } + }, + "type": "object", + "required": [ + "endpoints1", + "id" + ] + } + } + } +} \ No newline at end of file diff --git a/pkg/pf/tfgen/testdata/TestRegressDatabricksNestedCsharpOverrideBlocksSchema.golden b/pkg/pf/tfgen/testdata/TestRegressDatabricksNestedCsharpOverrideBlocksSchema.golden new file mode 100644 index 000000000..648b9e4a2 --- /dev/null +++ b/pkg/pf/tfgen/testdata/TestRegressDatabricksNestedCsharpOverrideBlocksSchema.golden @@ -0,0 +1,110 @@ +{ + "name": "testprovider", + "version": "0.0.1", + "attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).", + "meta": { + "moduleFormat": "(.*)(?:/[^/]*)" + }, + "language": { + "nodejs": { + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", + "compatibility": "tfbridge20", + "disableUnionOutputTypes": true + }, + "python": { + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", + "compatibility": "tfbridge20", + "pyproject": {} + } + }, + "config": {}, + "types": { + "testprovider:index/getServingEndpointsEndpoints1:getServingEndpointsEndpoints1": { + "properties": { + "aiGateway1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getServingEndpointsEndpoints1AiGateway1:getServingEndpointsEndpoints1AiGateway1" + } + } + }, + "type": "object" + }, + "testprovider:index/getServingEndpointsEndpoints1AiGateway1:getServingEndpointsEndpoints1AiGateway1": { + "properties": { + "guardrails1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getServingEndpointsEndpoints1AiGateway1Guardrails1:getServingEndpointsEndpoints1AiGateway1Guardrails1" + } + } + }, + "type": "object" + }, + "testprovider:index/getServingEndpointsEndpoints1AiGateway1Guardrails1:getServingEndpointsEndpoints1AiGateway1Guardrails1": { + "properties": { + "input1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getServingEndpointsEndpoints1AiGateway1Guardrails1Input1:getServingEndpointsEndpoints1AiGateway1Guardrails1Input1" + } + } + }, + "type": "object" + }, + "testprovider:index/getServingEndpointsEndpoints1AiGateway1Guardrails1Input1:getServingEndpointsEndpoints1AiGateway1Guardrails1Input1": { + "properties": { + "maxBatchSize": { + "type": "integer", + "language": { + "csharp": { + "name": "MaxBatchSize1" + } + } + } + }, + "type": "object", + "required": [ + "maxBatchSize" + ] + } + }, + "provider": { + "description": "The provider type for the testprovider package. By default, resources use package-wide configuration\nsettings, however an explicit `Provider` instance may be created and passed during resource\nconstruction to achieve fine-grained programmatic control over provider settings. See the\n[documentation](https://www.pulumi.com/docs/reference/programming-model/#providers) for more information.\n" + }, + "functions": { + "testprovider:index/getServingEndpoints:getServingEndpoints": { + "inputs": { + "description": "A collection of arguments for invoking getServingEndpoints.\n", + "properties": { + "endpoints1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getServingEndpointsEndpoints1:getServingEndpointsEndpoints1" + } + } + }, + "type": "object" + }, + "outputs": { + "description": "A collection of values returned by getServingEndpoints.\n", + "properties": { + "endpoints1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/getServingEndpointsEndpoints1:getServingEndpointsEndpoints1" + } + }, + "id": { + "type": "string", + "description": "The provider-assigned unique ID for this managed resource.\n" + } + }, + "type": "object", + "required": [ + "id" + ] + } + } + } +} \ No newline at end of file diff --git a/pkg/pf/tfgen/testdata/TestResourceAttributeVsBlockSchemaNameOverride.golden b/pkg/pf/tfgen/testdata/TestResourceAttributeVsBlockSchemaNameOverride.golden new file mode 100644 index 000000000..e05772e06 --- /dev/null +++ b/pkg/pf/tfgen/testdata/TestResourceAttributeVsBlockSchemaNameOverride.golden @@ -0,0 +1,66 @@ +{ + "name": "testprovider", + "version": "0.0.1", + "attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).", + "meta": { + "moduleFormat": "(.*)(?:/[^/]*)" + }, + "language": { + "nodejs": { + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", + "compatibility": "tfbridge20", + "disableUnionOutputTypes": true + }, + "python": { + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", + "compatibility": "tfbridge20", + "pyproject": {} + } + }, + "config": {}, + "types": { + "testprovider:index/BlockResCollection1:BlockResCollection1": { + "properties": { + "prop1": { + "type": "string" + } + }, + "type": "object" + } + }, + "provider": { + "description": "The provider type for the testprovider package. By default, resources use package-wide configuration\nsettings, however an explicit `Provider` instance may be created and passed during resource\nconstruction to achieve fine-grained programmatic control over provider settings. See the\n[documentation](https://www.pulumi.com/docs/reference/programming-model/#providers) for more information.\n" + }, + "resources": { + "testprovider:index/blockRes:BlockRes": { + "properties": { + "collection1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/BlockResCollection1:BlockResCollection1" + } + } + }, + "inputProperties": { + "collection1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/BlockResCollection1:BlockResCollection1" + } + } + }, + "stateInputs": { + "description": "Input properties used for looking up and filtering BlockRes resources.\n", + "properties": { + "collection1": { + "type": "array", + "items": { + "$ref": "#/types/testprovider:index/BlockResCollection1:BlockResCollection1" + } + } + }, + "type": "object" + } + } + } +} \ No newline at end of file diff --git a/pkg/pf/tfgen/tfgen_test.go b/pkg/pf/tfgen/tfgen_test.go index 413ebd7fb..588bf4b6f 100644 --- a/pkg/pf/tfgen/tfgen_test.go +++ b/pkg/pf/tfgen/tfgen_test.go @@ -23,6 +23,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" + dschema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/provider" pschema "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -31,11 +32,12 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hexops/autogold/v2" pulumiSchema "github.com/pulumi/pulumi/pkg/v3/codegen/schema" - pulumischema "github.com/pulumi/pulumi/pkg/v3/codegen/schema" "github.com/stretchr/testify/require" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/providerbuilder" pftfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge" "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info" ) // Regressing an issue with AWS provider not recognizing that assume_role config setting is singular via @@ -453,7 +455,7 @@ func TestTypeOverride(t *testing.T) { "test_res": tt.info, }, // Trim the schema for easier comparison - SchemaPostProcessor: func(p *pulumischema.PackageSpec) { + SchemaPostProcessor: func(p *pulumiSchema.PackageSpec) { p.Language = nil p.Provider.Description = "" }, @@ -471,3 +473,359 @@ func TestTypeOverride(t *testing.T) { }) } } + +func TestDataSourceAttributeVsBlockSchemaNameOverride(t *testing.T) { + t.Parallel() + + attrRes := dschema.Schema{ + Attributes: map[string]dschema.Attribute{ + "id": dschema.StringAttribute{Computed: true}, + "collection": dschema.ListNestedAttribute{ + NestedObject: dschema.NestedAttributeObject{ + Attributes: map[string]dschema.Attribute{ + "prop": dschema.StringAttribute{ + Optional: true, + }, + }, + }, + }, + }, + } + + blockRes := dschema.Schema{ + Attributes: map[string]dschema.Attribute{ + "id": dschema.StringAttribute{Computed: true}, + }, + Blocks: map[string]dschema.Block{ + "collection": dschema.ListNestedBlock{ + NestedObject: dschema.NestedBlockObject{ + Attributes: map[string]dschema.Attribute{ + "prop": dschema.StringAttribute{ + Optional: true, + }, + }, + }, + }, + }, + } + + prov := providerbuilder.NewProvider( + providerbuilder.NewProviderArgs{ + AllDataSources: []providerbuilder.DataSource{ + { + Name: "attr_res", + DataSourceSchema: attrRes, + }, + { + Name: "block_res", + DataSourceSchema: blockRes, + }, + }, + }, + ) + + providerInfo := prov.ToProviderInfo() + + providerInfo.DataSources["testprovider_attr_res"].Fields = map[string]*tfbridge.SchemaInfo{ + "collection": { + Name: "collection1", + Elem: &tfbridge.SchemaInfo{ + Fields: map[string]*tfbridge.SchemaInfo{ + "prop": {Name: "prop1"}, + }, + }, + }, + } + + providerInfo.DataSources["testprovider_block_res"].Fields = map[string]*tfbridge.SchemaInfo{ + "collection": { + Name: "collection1", + Elem: &tfbridge.SchemaInfo{ + Fields: map[string]*tfbridge.SchemaInfo{ + "prop": {Name: "prop1"}, + }, + }, + }, + } + + res, err := GenerateSchema(context.Background(), GenerateSchemaOptions{ + ProviderInfo: providerInfo, + }) + require.NoError(t, err) + var prettyJSON bytes.Buffer + if err := json.Indent(&prettyJSON, res.ProviderMetadata.PackageSchema, "", " "); err != nil { + t.Fatal(err) + } + + autogold.ExpectFile(t, autogold.Raw(prettyJSON.String())) +} + +func TestResourceAttributeVsBlockSchemaNameOverride(t *testing.T) { + t.Parallel() + + attrRes := rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "id": rschema.StringAttribute{Computed: true}, + "collection": rschema.ListNestedAttribute{ + NestedObject: rschema.NestedAttributeObject{ + Attributes: map[string]rschema.Attribute{ + "prop": rschema.StringAttribute{ + Optional: true, + }, + }, + }, + }, + }, + } + + blockRes := rschema.Schema{ + Attributes: map[string]rschema.Attribute{ + "id": rschema.StringAttribute{Computed: true}, + }, + Blocks: map[string]rschema.Block{ + "collection": rschema.ListNestedBlock{ + NestedObject: rschema.NestedBlockObject{ + Attributes: map[string]rschema.Attribute{ + "prop": rschema.StringAttribute{ + Optional: true, + }, + }, + }, + }, + }, + } + + prov := providerbuilder.NewProvider( + providerbuilder.NewProviderArgs{ + AllResources: []providerbuilder.Resource{ + { + Name: "attr_res", + ResourceSchema: attrRes, + }, + { + Name: "block_res", + ResourceSchema: blockRes, + }, + }, + }, + ) + + providerInfo := prov.ToProviderInfo() + + providerInfo.Resources["testprovider_attr_res"].Fields = map[string]*tfbridge.SchemaInfo{ + "collection": { + Name: "collection1", + Elem: &tfbridge.SchemaInfo{ + Fields: map[string]*tfbridge.SchemaInfo{ + "prop": {Name: "prop1"}, + }, + }, + }, + } + + providerInfo.Resources["testprovider_block_res"].Fields = map[string]*tfbridge.SchemaInfo{ + "collection": { + Name: "collection1", + Elem: &tfbridge.SchemaInfo{ + Fields: map[string]*tfbridge.SchemaInfo{ + "prop": {Name: "prop1"}, + }, + }, + }, + } + + res, err := GenerateSchema(context.Background(), GenerateSchemaOptions{ + ProviderInfo: providerInfo, + }) + require.NoError(t, err) + var prettyJSON bytes.Buffer + if err := json.Indent(&prettyJSON, res.ProviderMetadata.PackageSchema, "", " "); err != nil { + t.Fatal(err) + } + + autogold.ExpectFile(t, autogold.Raw(prettyJSON.String())) +} + +func TestRegressDatabricksNestedCsharpOverrideBlocksSchema(t *testing.T) { + t.Parallel() + dsSchemaBlocks := dschema.Schema{ + Blocks: map[string]dschema.Block{ + "endpoints": dschema.ListNestedBlock{ + NestedObject: dschema.NestedBlockObject{ + Blocks: map[string]dschema.Block{ + "ai_gateway": dschema.ListNestedBlock{ + NestedObject: dschema.NestedBlockObject{ + Blocks: map[string]dschema.Block{ + "guardrails": dschema.ListNestedBlock{ + NestedObject: dschema.NestedBlockObject{ + Blocks: map[string]dschema.Block{ + "input": dschema.ListNestedBlock{ + NestedObject: dschema.NestedBlockObject{ + Attributes: map[string]dschema.Attribute{ + "max_batch_size": dschema.Int64Attribute{}, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + + schemaProvider := providerbuilder.NewProvider( + providerbuilder.NewProviderArgs{ + AllDataSources: []providerbuilder.DataSource{ + { + Name: "serving_endpoints", + DataSourceSchema: dsSchemaBlocks, + ReadFunc: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + }, + }, + }, + }, + ) + providerInfo := schemaProvider.ToProviderInfo() + + providerInfo.DataSources["testprovider_serving_endpoints"].Fields = map[string]*info.Schema{ + "endpoints": { + Name: "endpoints1", + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ + "ai_gateway": { + Name: "aiGateway1", + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ + "guardrails": { + Name: "guardrails1", + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ + "input": { + Name: "input1", + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ + "max_batch_size": { + CSharpName: "MaxBatchSize1", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + + res, err := GenerateSchema(context.Background(), GenerateSchemaOptions{ + ProviderInfo: providerInfo, + }) + require.NoError(t, err) + var prettyJSON bytes.Buffer + if err := json.Indent(&prettyJSON, res.ProviderMetadata.PackageSchema, "", " "); err != nil { + t.Fatal(err) + } + + autogold.ExpectFile(t, autogold.Raw(prettyJSON.String())) +} + +func TestRegressDatabricksNestedCsharpOverrideAttributesSchema(t *testing.T) { + t.Parallel() + dsSchemaAttributes := dschema.Schema{ + Attributes: map[string]dschema.Attribute{ + "endpoints": dschema.ListNestedAttribute{ + NestedObject: dschema.NestedAttributeObject{ + Attributes: map[string]dschema.Attribute{ + "ai_gateway": dschema.ListNestedAttribute{ + NestedObject: dschema.NestedAttributeObject{ + Attributes: map[string]dschema.Attribute{ + "guardrails": dschema.ListNestedAttribute{ + NestedObject: dschema.NestedAttributeObject{ + Attributes: map[string]dschema.Attribute{ + "input": dschema.ListNestedAttribute{ + NestedObject: dschema.NestedAttributeObject{ + Attributes: map[string]dschema.Attribute{ + "max_batch_size": dschema.Int64Attribute{}, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + + schemaProvider := providerbuilder.NewProvider( + providerbuilder.NewProviderArgs{ + AllDataSources: []providerbuilder.DataSource{ + { + Name: "serving_endpoints", + DataSourceSchema: dsSchemaAttributes, + ReadFunc: func(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + }, + }, + }, + }, + ) + providerInfo := schemaProvider.ToProviderInfo() + + providerInfo.DataSources["testprovider_serving_endpoints"].Fields = map[string]*info.Schema{ + "endpoints": { + Name: "endpoints1", + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ + "ai_gateway": { + Name: "aiGateway1", + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ + "guardrails": { + Name: "guardrails1", + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ + "input": { + Name: "input1", + Elem: &info.Schema{ + Fields: map[string]*info.Schema{ + "max_batch_size": { + CSharpName: "MaxBatchSize1", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + + res, err := GenerateSchema(context.Background(), GenerateSchemaOptions{ + ProviderInfo: providerInfo, + }) + require.NoError(t, err) + var prettyJSON bytes.Buffer + if err := json.Indent(&prettyJSON, res.ProviderMetadata.PackageSchema, "", " "); err != nil { + t.Fatal(err) + } + + autogold.ExpectFile(t, autogold.Raw(prettyJSON.String())) +}