Skip to content

Commit

Permalink
feat(integrations): show default values (#1696)
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
  • Loading branch information
migmartri authored Jan 3, 2025
1 parent f83a212 commit 033f21a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/cli/cmd/available_integration_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ func renderSchemaTable(tableTitle string, properties sdk.SchemaPropertiesMap) er
color = text.Colors{text.FgHiYellow}
}

required := "no"
if v.Required {
required = "yes"
var requiredInfo = color.Sprint(hBool(v.Required))
if v.Default != "" && !v.Required {
requiredInfo = fmt.Sprintf("%s (default: %s)", requiredInfo, v.Default)
}

t.AppendRow(table.Row{color.Sprint(v.Name), color.Sprint(propertyType), color.Sprint(required), v.Description})
t.AppendRow(table.Row{color.Sprint(v.Name), color.Sprint(propertyType), requiredInfo, v.Description})
}

t.Render()
Expand Down
10 changes: 9 additions & 1 deletion app/controlplane/plugins/sdk/v1/fanout.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ type SchemaProperty struct {
// If the property is required
Required bool
// Optional format (email, host)
Format string
Format string
Default string
}

func CompileJSONSchema(in []byte) (*schema_validator.Schema, error) {
Expand Down Expand Up @@ -493,12 +494,19 @@ func CalculatePropertiesMap(s *schema_validator.Schema, m *SchemaPropertiesMap)
}

var required = requiredMap[k]

var defaultVal string
if v.Default != nil && !required {
defaultVal = fmt.Sprintf("%v", v.Default)
}

(*m)[k] = &SchemaProperty{
Name: k,
Type: v.Types[0],
Required: required,
Description: v.Description,
Format: v.Format,
Default: defaultVal,
}
}
}
Expand Down

0 comments on commit 033f21a

Please sign in to comment.