Skip to content

Commit cfb63d8

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

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
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

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ require (
4040
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af
4141
github.com/spf13/cobra v1.8.1
4242
github.com/spf13/pflag v1.0.5
43+
github.com/wk8/go-ordered-map/v2 v2.1.8
4344
golang.org/x/net v0.30.0
4445
golang.org/x/sync v0.8.0
4546
golang.org/x/sys v0.26.0
@@ -111,7 +112,6 @@ require (
111112
github.com/russross/blackfriday/v2 v2.1.0 // indirect
112113
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
113114
github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701 // indirect
114-
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
115115
github.com/x448/float16 v0.8.4 // indirect
116116
github.com/yuin/gopher-lua v1.1.1 // indirect
117117
go.uber.org/atomic v1.7.0 // indirect

pkg/limayaml/limayaml.go

+7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ const (
7676
WSL2 VMType = "wsl2"
7777
)
7878

79+
var (
80+
OSTypes = []OS{LINUX}
81+
ArchTypes = []Arch{X8664, AARCH64, ARMV7L, RISCV64}
82+
MountTypes = []MountType{REVSSHFS, NINEP, VIRTIOFS, WSLMount}
83+
VMTypes = []VMType{QEMU, VZ, WSL2}
84+
)
85+
7986
type VMOpts struct {
8087
QEMU QEMUOpts `yaml:"qemu,omitempty" json:"qemu,omitempty"`
8188
}

0 commit comments

Comments
 (0)