Skip to content
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
5 changes: 4 additions & 1 deletion console/src/components/SchemaFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
export interface SchemaProperty {
name: string
schema: Schema
hidden?: boolean
}

export interface Schema {
Expand All @@ -44,7 +45,9 @@
): [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)
}
Expand All @@ -54,7 +57,7 @@
description?: string
parent: string
schema: Schema
form: UseFormReturn<any>

Check warning on line 60 in console/src/components/SchemaFields.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
variableNames?: string[]
}

Expand Down Expand Up @@ -85,7 +88,7 @@
}
}
}
}, [schema, parent])

Check warning on line 91 in console/src/components/SchemaFields.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'entries'. Either include it or remove the dependency array

if (!entries.length) {
return null
Expand Down
Binary file modified internal/wasm/test/action.wasm
Binary file not shown.
Binary file modified internal/wasm/test/provider.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions pkg/modules/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
95 changes: 95 additions & 0 deletions pkg/modules/manifest_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
Loading