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
1213func 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+
2340func 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
0 commit comments