Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema: Implement DeprecationMessage for resources, data sources, and provider #140

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/ENHANCEMENTS-20240515-100422.yaml
Original file line number Diff line number Diff line change
@@ -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"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/cmd/testdata/custom_and_external/ir.json
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@
}
}
],
"deprecation_message": "This data source is deprecated!",
"description": "\"Example\" datasource",
"markdown_description": "\"Example\" _datasource_"
}
Expand Down Expand Up @@ -1055,6 +1056,7 @@
}
}
],
"deprecation_message": "This provider is deprecated!",
"description": "\"Example\" provider",
"markdown_description": "\"Example\" _provider_"
}
Expand Down Expand Up @@ -1435,6 +1437,7 @@
}
}
],
"deprecation_message": "This resource is deprecated!",
"description": "\"Example\" resource",
"markdown_description": "\"Example\" _resource_"
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/datasource/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions internal/provider/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions internal/resource/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type GeneratorSchema struct {
Blocks GeneratorBlocks
Description *string
MarkdownDescription *string
DeprecationMessage *string
}

func (g GeneratorSchema) Imports() (string, error) {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/schema/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/schema/templates/schema.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ return schema.Schema{
{{- if .MarkdownDescription }}
MarkdownDescription: {{printf "%q" .MarkdownDescription}},
{{- end}}
{{- if .DeprecationMessage }}
DeprecationMessage: {{printf "%q" .DeprecationMessage}},
{{- end}}
}
}