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

Initial support for provider-defined functions from providers schema -json #119

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ type FunctionSignature struct {
// of the function
Description string `json:"description,omitempty"`

// Summary is an optional shortened description of the function
Summary string `json:"summary,omitempty"`

// DeprecationMessage is an optional message that indicates that the
// function should be considered deprecated and what actions should be
// performed by the practitioner to handle the deprecation.
DeprecationMessage string `json:"deprecation_message,omitempty"`

// ReturnType is the ctyjson representation of the function's
// return types based on supplying all parameters using
// dynamic types. Functions can have dynamic return types.
Expand Down
3 changes: 3 additions & 0 deletions schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ type ProviderSchema struct {

// The schemas for any data sources in this provider.
DataSourceSchemas map[string]*Schema `json:"data_source_schemas,omitempty"`

// The definitions for any functions in this provider.
Functions *MetadataFunctions `json:"functions,omitempty"`
}

// Schema is the JSON representation of a particular schema
Expand Down
17 changes: 17 additions & 0 deletions schemas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ func TestProviderSchemasValidate(t *testing.T) {
}
}

func TestProviderSchemasValidate_functions(t *testing.T) {
f, err := os.Open("testdata/functions/schemas.json")
if err != nil {
t.Fatal(err)
}
defer f.Close()

var schemas *ProviderSchemas
if err := json.NewDecoder(f).Decode(&schemas); err != nil {
t.Fatal(err)
}

if err := schemas.Validate(); err != nil {
t.Fatal(err)
}
}

func TestProviderSchemasValidate_nestedAttributes(t *testing.T) {
f, err := os.Open("testdata/nested_attributes/schemas.json")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions testdata/functions/schemas.json
Original file line number Diff line number Diff line change
@@ -0,0 +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":{"format_version":"1.0","function_signatures":{"example":{"description":"Echoes given argument as result","summary":"Example function","return_type":"string","parameters":[{"name":"input","description":"String to echo","type":"string"}]}}}}}}