From 815ea6143e816b9d34fdc7e97427c70527fab57a Mon Sep 17 00:00:00 2001 From: Austin Valle Date: Wed, 15 May 2024 10:24:34 -0400 Subject: [PATCH] implement deprecation message --- .changes/unreleased/ENHANCEMENTS-20240515-100422.yaml | 6 ++++++ .../datasource_example/example_data_source_gen.go | 1 + .../provider_example/example_provider_gen.go | 1 + .../resource_example/example_resource_gen.go | 1 + .../specified_pkg_name/example_data_source_gen.go | 1 + .../all_output/specified_pkg_name/example_provider_gen.go | 1 + .../all_output/specified_pkg_name/example_resource_gen.go | 1 + .../data_sources_output/example_data_source_gen.go | 1 + internal/cmd/testdata/custom_and_external/ir.json | 3 +++ .../provider_output/example_provider_gen.go | 1 + .../resources_output/example_resource_gen.go | 1 + internal/datasource/convert.go | 2 ++ internal/provider/convert.go | 2 ++ internal/resource/convert.go | 2 ++ internal/schema/schema.go | 8 ++++++++ internal/schema/schemas.go | 1 + internal/schema/templates/schema.gotmpl | 3 +++ 17 files changed, 36 insertions(+) create mode 100644 .changes/unreleased/ENHANCEMENTS-20240515-100422.yaml diff --git a/.changes/unreleased/ENHANCEMENTS-20240515-100422.yaml b/.changes/unreleased/ENHANCEMENTS-20240515-100422.yaml new file mode 100644 index 00000000..c932fe86 --- /dev/null +++ b/.changes/unreleased/ENHANCEMENTS-20240515-100422.yaml @@ -0,0 +1,6 @@ +kind: ENHANCEMENTS +body: 'schema: Added `Description`, `MarkdownDescription` and `DeprecationMessage` + fields to resource, data source and provider schemas' +time: 2024-05-15T10:04:22.078016-04:00 +custom: + Issue: "112" diff --git a/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/datasource_example/example_data_source_gen.go b/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/datasource_example/example_data_source_gen.go index b8d83127..36630a20 100644 --- a/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/datasource_example/example_data_source_gen.go +++ b/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/datasource_example/example_data_source_gen.go @@ -563,6 +563,7 @@ func ExampleDataSourceSchema(ctx context.Context) schema.Schema { }, Description: "\"Example\" datasource", MarkdownDescription: "\"Example\" _datasource_", + DeprecationMessage: "This data source is deprecated!", } } diff --git a/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/provider_example/example_provider_gen.go b/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/provider_example/example_provider_gen.go index 1ed8a057..142710e3 100644 --- a/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/provider_example/example_provider_gen.go +++ b/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/provider_example/example_provider_gen.go @@ -206,6 +206,7 @@ func ExampleProviderSchema(ctx context.Context) schema.Schema { }, Description: "\"Example\" provider", MarkdownDescription: "\"Example\" _provider_", + DeprecationMessage: "This provider is deprecated!", } } diff --git a/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/resource_example/example_resource_gen.go b/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/resource_example/example_resource_gen.go index 4a23e1e5..9e64fbcf 100644 --- a/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/resource_example/example_resource_gen.go +++ b/internal/cmd/testdata/custom_and_external/all_output/default_pkg_name/resource_example/example_resource_gen.go @@ -225,6 +225,7 @@ func ExampleResourceSchema(ctx context.Context) schema.Schema { }, Description: "\"Example\" resource", MarkdownDescription: "\"Example\" _resource_", + DeprecationMessage: "This resource is deprecated!", } } diff --git a/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_data_source_gen.go b/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_data_source_gen.go index fef96fda..79bcc3f1 100644 --- a/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_data_source_gen.go +++ b/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_data_source_gen.go @@ -563,6 +563,7 @@ func ExampleDataSourceSchema(ctx context.Context) schema.Schema { }, Description: "\"Example\" datasource", MarkdownDescription: "\"Example\" _datasource_", + DeprecationMessage: "This data source is deprecated!", } } diff --git a/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_provider_gen.go b/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_provider_gen.go index a8318e94..49fdc2bc 100644 --- a/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_provider_gen.go +++ b/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_provider_gen.go @@ -206,6 +206,7 @@ func ExampleProviderSchema(ctx context.Context) schema.Schema { }, Description: "\"Example\" provider", MarkdownDescription: "\"Example\" _provider_", + DeprecationMessage: "This provider is deprecated!", } } diff --git a/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_resource_gen.go b/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_resource_gen.go index 1c92e679..064b1f2a 100644 --- a/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_resource_gen.go +++ b/internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name/example_resource_gen.go @@ -225,6 +225,7 @@ func ExampleResourceSchema(ctx context.Context) schema.Schema { }, Description: "\"Example\" resource", MarkdownDescription: "\"Example\" _resource_", + DeprecationMessage: "This resource is deprecated!", } } diff --git a/internal/cmd/testdata/custom_and_external/data_sources_output/example_data_source_gen.go b/internal/cmd/testdata/custom_and_external/data_sources_output/example_data_source_gen.go index 717b62a8..1a275cd7 100644 --- a/internal/cmd/testdata/custom_and_external/data_sources_output/example_data_source_gen.go +++ b/internal/cmd/testdata/custom_and_external/data_sources_output/example_data_source_gen.go @@ -563,6 +563,7 @@ func ExampleDataSourceSchema(ctx context.Context) schema.Schema { }, Description: "\"Example\" datasource", MarkdownDescription: "\"Example\" _datasource_", + DeprecationMessage: "This data source is deprecated!", } } diff --git a/internal/cmd/testdata/custom_and_external/ir.json b/internal/cmd/testdata/custom_and_external/ir.json index 35568d9e..bcd16e54 100644 --- a/internal/cmd/testdata/custom_and_external/ir.json +++ b/internal/cmd/testdata/custom_and_external/ir.json @@ -728,6 +728,7 @@ } } ], + "deprecation_message": "This data source is deprecated!", "description": "\"Example\" datasource", "markdown_description": "\"Example\" _datasource_" } @@ -1055,6 +1056,7 @@ } } ], + "deprecation_message": "This provider is deprecated!", "description": "\"Example\" provider", "markdown_description": "\"Example\" _provider_" } @@ -1435,6 +1437,7 @@ } } ], + "deprecation_message": "This resource is deprecated!", "description": "\"Example\" resource", "markdown_description": "\"Example\" _resource_" } diff --git a/internal/cmd/testdata/custom_and_external/provider_output/example_provider_gen.go b/internal/cmd/testdata/custom_and_external/provider_output/example_provider_gen.go index b85b90d3..96488f86 100644 --- a/internal/cmd/testdata/custom_and_external/provider_output/example_provider_gen.go +++ b/internal/cmd/testdata/custom_and_external/provider_output/example_provider_gen.go @@ -206,6 +206,7 @@ func ExampleProviderSchema(ctx context.Context) schema.Schema { }, Description: "\"Example\" provider", MarkdownDescription: "\"Example\" _provider_", + DeprecationMessage: "This provider is deprecated!", } } diff --git a/internal/cmd/testdata/custom_and_external/resources_output/example_resource_gen.go b/internal/cmd/testdata/custom_and_external/resources_output/example_resource_gen.go index 333d2089..4d8783e6 100644 --- a/internal/cmd/testdata/custom_and_external/resources_output/example_resource_gen.go +++ b/internal/cmd/testdata/custom_and_external/resources_output/example_resource_gen.go @@ -225,6 +225,7 @@ func ExampleResourceSchema(ctx context.Context) schema.Schema { }, Description: "\"Example\" resource", MarkdownDescription: "\"Example\" _resource_", + DeprecationMessage: "This resource is deprecated!", } } diff --git a/internal/datasource/convert.go b/internal/datasource/convert.go index 1a2fef72..f06663c2 100644 --- a/internal/datasource/convert.go +++ b/internal/datasource/convert.go @@ -61,6 +61,8 @@ func NewSchema(d datasource.DataSource) (generatorschema.GeneratorSchema, error) s.MarkdownDescription = d.Schema.MarkdownDescription + s.DeprecationMessage = d.Schema.DeprecationMessage + return s, nil } diff --git a/internal/provider/convert.go b/internal/provider/convert.go index aa733a14..8cf368da 100644 --- a/internal/provider/convert.go +++ b/internal/provider/convert.go @@ -64,6 +64,8 @@ func NewSchema(p *provider.Provider) (generatorschema.GeneratorSchema, error) { s.MarkdownDescription = p.Schema.MarkdownDescription + s.DeprecationMessage = p.Schema.DeprecationMessage + return s, nil } diff --git a/internal/resource/convert.go b/internal/resource/convert.go index a485b25a..f93b45ab 100644 --- a/internal/resource/convert.go +++ b/internal/resource/convert.go @@ -61,6 +61,8 @@ func NewSchema(d resource.Resource) (generatorschema.GeneratorSchema, error) { s.MarkdownDescription = d.Schema.MarkdownDescription + s.DeprecationMessage = d.Schema.DeprecationMessage + return s, nil } diff --git a/internal/schema/schema.go b/internal/schema/schema.go index baeaeeda..f9b287da 100644 --- a/internal/schema/schema.go +++ b/internal/schema/schema.go @@ -24,6 +24,7 @@ type GeneratorSchema struct { Blocks GeneratorBlocks Description *string MarkdownDescription *string + DeprecationMessage *string } func (g GeneratorSchema) Imports() (string, error) { @@ -151,6 +152,11 @@ func (g GeneratorSchema) Schema(name, packageName, generatorType string) ([]byte markdownDescription = *g.MarkdownDescription } + deprecationMessage := "" + if g.DeprecationMessage != nil { + deprecationMessage = *g.DeprecationMessage + } + templateData := struct { Name string PackageName string @@ -160,6 +166,7 @@ func (g GeneratorSchema) Schema(name, packageName, generatorType string) ([]byte Description string Imports string MarkdownDescription string + DeprecationMessage string }{ Name: FrameworkIdentifier(name).ToPascalCase(), PackageName: packageName, @@ -169,6 +176,7 @@ func (g GeneratorSchema) Schema(name, packageName, generatorType string) ([]byte Description: description, Imports: imports, MarkdownDescription: markdownDescription, + DeprecationMessage: deprecationMessage, } t, err := template.New("schema").Parse(SchemaGoTemplate) diff --git a/internal/schema/schemas.go b/internal/schema/schemas.go index cda1ee41..b7a6d876 100644 --- a/internal/schema/schemas.go +++ b/internal/schema/schemas.go @@ -57,6 +57,7 @@ func (g GeneratorSchemas) Models() (map[string][]byte, error) { Blocks: schema.Blocks, Description: schema.Description, MarkdownDescription: schema.MarkdownDescription, + DeprecationMessage: schema.DeprecationMessage, } models, err := generatorSchema.Models(name) diff --git a/internal/schema/templates/schema.gotmpl b/internal/schema/templates/schema.gotmpl index 18fc1b07..8e391386 100644 --- a/internal/schema/templates/schema.gotmpl +++ b/internal/schema/templates/schema.gotmpl @@ -31,5 +31,8 @@ return schema.Schema{ {{- if .MarkdownDescription }} MarkdownDescription: {{printf "%q" .MarkdownDescription}}, {{- end}} + {{- if .DeprecationMessage }} + DeprecationMessage: {{printf "%q" .DeprecationMessage}}, + {{- end}} } }