diff --git a/console/src/components/SchemaFields.tsx b/console/src/components/SchemaFields.tsx index 8256b7eb..313c3e29 100644 --- a/console/src/components/SchemaFields.tsx +++ b/console/src/components/SchemaFields.tsx @@ -20,6 +20,7 @@ import { VariableAutocompleteInput } from "@/components/ui/variable-autocomplete export interface SchemaProperty { name: string schema: Schema + hidden?: boolean } export interface Schema { @@ -44,7 +45,9 @@ function normalizeProperties( ): [string, Schema][] { if (!properties) return [] if (Array.isArray(properties)) { - return properties.map((p, i) => [p.name, { ...p.schema, order: p.schema.order ?? i }]) + return properties + .filter((p) => !p.hidden) + .map((p, i) => [p.name, { ...p.schema, order: p.schema.order ?? i }]) } return Object.entries(properties) } diff --git a/internal/wasm/test/action.wasm b/internal/wasm/test/action.wasm index db4cf0a0..8e4b5072 100644 Binary files a/internal/wasm/test/action.wasm and b/internal/wasm/test/action.wasm differ diff --git a/internal/wasm/test/provider.wasm b/internal/wasm/test/provider.wasm index c2a14319..4f80f88b 100644 Binary files a/internal/wasm/test/provider.wasm and b/internal/wasm/test/provider.wasm differ diff --git a/pkg/modules/manifest.go b/pkg/modules/manifest.go index dd2deafc..f92f8b4d 100644 --- a/pkg/modules/manifest.go +++ b/pkg/modules/manifest.go @@ -25,6 +25,7 @@ type Author struct { type JSONSchemaProperty struct { Name string `json:"name"` Schema *JSONSchema `json:"schema"` + Hidden bool `json:"hidden,omitempty"` } // JSONSchema represents a JSON Schema object compatible with the frontend. diff --git a/pkg/modules/manifest_test.go b/pkg/modules/manifest_test.go new file mode 100644 index 00000000..8ba37930 --- /dev/null +++ b/pkg/modules/manifest_test.go @@ -0,0 +1,95 @@ +package modules + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestJSONSchemaPropertyHidden(t *testing.T) { + t.Parallel() + + type test struct { + property JSONSchemaProperty + wantKey bool + } + + tests := map[string]test{ + "hidden true is serialized": { + property: JSONSchemaProperty{ + Name: "secret_key", + Schema: &JSONSchema{Type: "string"}, + Hidden: true, + }, + wantKey: true, + }, + "hidden false is omitted": { + property: JSONSchemaProperty{ + Name: "api_key", + Schema: &JSONSchema{Type: "string"}, + Hidden: false, + }, + wantKey: false, + }, + "hidden zero-value is omitted": { + property: JSONSchemaProperty{ + Name: "api_key", + Schema: &JSONSchema{Type: "string"}, + }, + wantKey: false, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + data, err := json.Marshal(test.property) + require.NoError(t, err) + + var raw map[string]any + err = json.Unmarshal(data, &raw) + require.NoError(t, err) + + _, hasHidden := raw["hidden"] + assert.Equal(t, test.wantKey, hasHidden) + + if test.wantKey { + assert.Equal(t, true, raw["hidden"]) + } + }) + } +} + +func TestJSONSchemaPropertyHiddenDeserialization(t *testing.T) { + t.Parallel() + + type test struct { + input string + wantHidden bool + } + + tests := map[string]test{ + "with hidden true": { + input: `{"name":"secret","schema":{"type":"string"},"hidden":true}`, + wantHidden: true, + }, + "with hidden false": { + input: `{"name":"api_key","schema":{"type":"string"},"hidden":false}`, + wantHidden: false, + }, + "without hidden field": { + input: `{"name":"api_key","schema":{"type":"string"}}`, + wantHidden: false, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + var prop JSONSchemaProperty + err := json.Unmarshal([]byte(test.input), &prop) + require.NoError(t, err) + assert.Equal(t, test.wantHidden, prop.Hidden) + }) + } +}