Skip to content

Commit f2686e9

Browse files
authored
Initial support for provider-defined functions from providers schema -json (#119)
* Initial support for provider-defined functions from providers schema -json Reference: #118 Reference: hashicorp/terraform#34450 The Terraform `providers schema -json` output implementation currently uses the entire `metadata functions -json` implementation, so has the additional nesting layer containing `format_version` and `function_signatures`. * Remove extraneous function metadata object
1 parent 884568c commit f2686e9

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

metadata.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ type FunctionSignature struct {
7777
// of the function
7878
Description string `json:"description,omitempty"`
7979

80+
// Summary is an optional shortened description of the function
81+
Summary string `json:"summary,omitempty"`
82+
83+
// DeprecationMessage is an optional message that indicates that the
84+
// function should be considered deprecated and what actions should be
85+
// performed by the practitioner to handle the deprecation.
86+
DeprecationMessage string `json:"deprecation_message,omitempty"`
87+
8088
// ReturnType is the ctyjson representation of the function's
8189
// return types based on supplying all parameters using
8290
// dynamic types. Functions can have dynamic return types.

schemas.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ type ProviderSchema struct {
8686

8787
// The schemas for any data sources in this provider.
8888
DataSourceSchemas map[string]*Schema `json:"data_source_schemas,omitempty"`
89+
90+
// The definitions for any functions in this provider.
91+
Functions map[string]*FunctionSignature `json:"functions,omitempty"`
8992
}
9093

9194
// Schema is the JSON representation of a particular schema

schemas_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ func TestProviderSchemasValidate(t *testing.T) {
2626
}
2727
}
2828

29+
func TestProviderSchemasValidate_functions(t *testing.T) {
30+
f, err := os.Open("testdata/functions/schemas.json")
31+
if err != nil {
32+
t.Fatal(err)
33+
}
34+
defer f.Close()
35+
36+
var schemas *ProviderSchemas
37+
if err := json.NewDecoder(f).Decode(&schemas); err != nil {
38+
t.Fatal(err)
39+
}
40+
41+
if err := schemas.Validate(); err != nil {
42+
t.Fatal(err)
43+
}
44+
}
45+
2946
func TestProviderSchemasValidate_nestedAttributes(t *testing.T) {
3047
f, err := os.Open("testdata/nested_attributes/schemas.json")
3148
if err != nil {

testdata/functions/schemas.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"format_version":"1.0","provider_schemas":{"example":{"provider":{"version":0,"block":{"attributes":{"example":{"type":"string","description_kind":"plain","optional":true}},"description_kind":"plain"}},"resource_schemas":{"framework_example":{"version":0,"block":{"attributes":{"id":{"type":"string","description":"Example identifier","description_kind":"markdown","computed":true}},"description":"Example resource","description_kind":"markdown"}}},"data_source_schemas":{"framework_example":{"version":0,"block":{"attributes":{"id":{"type":"string","description":"Example identifier","description_kind":"markdown","computed":true}},"description":"Example data source","description_kind":"markdown"}}},"functions":{"example":{"description":"Echoes given argument as result","summary":"Example function","return_type":"string","parameters":[{"name":"input","description":"String to echo","type":"string"}]}}}}}

0 commit comments

Comments
 (0)