Commit graph

5 commits

Author SHA1 Message Date
Brian Flad
3b4964270f
internal/command/jsonprovider: Remove root jsonfunction object from function output (#34536)
Previously, the `providers schema -json` output would include the root object from `metadata functions -json`. This object had its own `format_version` property, which would be confusing with the root `format_version` property already present.

This change still uses the `jsonfunction` package for consistency between cty and provider function JSON handling, but removes that extra object, instead making `functions` directly a mapping of names to signatures/definitions. This also adds a code comment to hint maintainers that jsonprovider format versioning is tied to jsonfunction format versioning.

Example output prior to change:

```jsonc
{
  "format_version": "1.0",
  "provider_schemas": {
    "registry.terraform.io/bflad/framework": {
      // ...
      "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"
              }
            ]
          }
        }
      }
    }
  }
}
```

Example output after change:

```jsonc
{
  "format_version": "1.0",
  "provider_schemas": {
    "registry.terraform.io/bflad/framework": {
      // ...
      "functions": {
        "example": {
          "description": "Echoes given argument as result",
          "summary": "Example function",
          "return_type": "string",
          "parameters": [
            {
              "name": "input",
              "description": "String to echo",
              "type": "string"
            }
          ]
        }
      }
    }
  }
}
```
2024-01-18 15:48:07 -05:00
James Bardin
a74c847656 test MarshalProviderFunctions
Provider functions should marshal identically to an equivalent cty
functions.
2023-12-22 09:56:15 -05:00
hashicorp-copywrite[bot]
53c34ff49c
Update copyright file headers to BUSL-1.1 2023-08-10 23:43:27 +01:00
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
Daniel Banck
4fa77727b5
Introduce metadata functions command (#32487)
* Add metadata functions command skeleton

* Export functions as JSON via cli command

* Add metadata command

* Add tests to jsonfunction package

* WIP: Add metadata functions test

* Change return_type & type in JSON to json.RawMessage

This enables easier deserialisation of types when parsing the JSON.

* Skip is_nullable when false

* Update cli docs with metadata command

* Use tfdiags to report function marshal errors

* Ignore map, list and type functions

* Test Marshal function with diags

* Test metadata functions command output

* Simplify type marshaling by using cty.Type

* Add static function signatures for can and try

* Update internal/command/jsonfunction/function_test.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

---------

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2023-02-14 14:08:47 +00:00