7
7
"github.com/invopop/jsonschema"
8
8
"github.com/lima-vm/lima/pkg/limayaml"
9
9
"github.com/spf13/cobra"
10
+ orderedmap "github.com/wk8/go-ordered-map/v2"
10
11
)
11
12
12
13
func newGenSchemaCommand () * cobra.Command {
@@ -20,6 +21,22 @@ func newGenSchemaCommand() *cobra.Command {
20
21
return genschemaCommand
21
22
}
22
23
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
+
23
40
func genschemaAction (cmd * cobra.Command , _ []string ) error {
24
41
schema := jsonschema .Reflect (& limayaml.LimaYAML {})
25
42
// allow Disk to be either string (name) or object (struct)
@@ -28,6 +45,11 @@ func genschemaAction(cmd *cobra.Command, _ []string) error {
28
45
{Type : "string" },
29
46
{Type : "object" },
30
47
}
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 )
31
53
j , err := json .MarshalIndent (schema , "" , " " )
32
54
if err != nil {
33
55
return err
0 commit comments