Skip to content

Commit 0a19046

Browse files
committed
Add jsonschema enum for the property types
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 906f34b commit 0a19046

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

cmd/limactl/genschema.go

+22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/invopop/jsonschema"
88
"github.com/lima-vm/lima/pkg/limayaml"
99
"github.com/spf13/cobra"
10+
orderedmap "github.com/wk8/go-ordered-map/v2"
1011
)
1112

1213
func newGenSchemaCommand() *cobra.Command {
@@ -20,6 +21,22 @@ func newGenSchemaCommand() *cobra.Command {
2021
return genschemaCommand
2122
}
2223

24+
func toAny(args []string) []any {
25+
result := []any{nil}
26+
for _, arg := range args {
27+
result = append(result, arg)
28+
}
29+
return result
30+
}
31+
32+
func getProp(props *orderedmap.OrderedMap[string, *jsonschema.Schema], key string) *jsonschema.Schema {
33+
value, ok := props.Get(key)
34+
if !ok {
35+
return nil
36+
}
37+
return value
38+
}
39+
2340
func genschemaAction(cmd *cobra.Command, _ []string) error {
2441
schema := jsonschema.Reflect(&limayaml.LimaYAML{})
2542
// allow Disk to be either string (name) or object (struct)
@@ -28,6 +45,11 @@ func genschemaAction(cmd *cobra.Command, _ []string) error {
2845
{Type: "string"},
2946
{Type: "object"},
3047
}
48+
properties := schema.Definitions["LimaYAML"].Properties
49+
getProp(properties, "os").Enum = toAny(limayaml.OSTypes)
50+
getProp(properties, "arch").Enum = toAny(limayaml.ArchTypes)
51+
getProp(properties, "mountType").Enum = toAny(limayaml.MountTypes)
52+
getProp(properties, "vmType").Enum = toAny(limayaml.VMTypes)
3153
j, err := json.MarshalIndent(schema, "", " ")
3254
if err != nil {
3355
return err

pkg/limayaml/limayaml.go

+9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ type LimaYAML struct {
4646

4747
type (
4848
OS = string
49+
OSType = OS
4950
Arch = string
51+
ArchType = Arch
5052
MountType = string
5153
VMType = string
5254
)
@@ -71,6 +73,13 @@ const (
7173
WSL2 VMType = "wsl2"
7274
)
7375

76+
var (
77+
OSTypes = []OSType{LINUX}
78+
ArchTypes = []ArchType{X8664, AARCH64, ARMV7L, RISCV64}
79+
MountTypes = []MountType{REVSSHFS, NINEP, VIRTIOFS, WSLMount}
80+
VMTypes = []VMType{QEMU, VZ, WSL2}
81+
)
82+
7483
type Rosetta struct {
7584
Enabled *bool `yaml:"enabled" json:"enabled" jsonschema:"nullable"`
7685
BinFmt *bool `yaml:"binfmt" json:"binfmt" jsonschema:"nullable"`

0 commit comments

Comments
 (0)