Skip to content

Commit 541eb2d

Browse files
committed
Add command to generate jsonschema for limayaml
Signed-off-by: Anders F Björklund <[email protected]>
1 parent e53aea8 commit 541eb2d

File tree

6 files changed

+52
-0
lines changed

6 files changed

+52
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
_output/
22
_artifacts/
33
lima.REJECTED.yaml
4+
schema-limayaml.json
45
.config

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ docsy: _output/bin/limactl$(exe)
200200
$< generate-doc --type docsy website/_output/docsy \
201201
--output _output --prefix $(PREFIX)
202202

203+
schema-limayaml.json: _output/bin/limactl$(exe)
204+
$< generate-schema >$@
205+
206+
.PHONY: check-jsonschema
207+
check-jsonschema: schema-limayaml.json
208+
check-jsonschema --schemafile $< examples/default.yaml
209+
203210
.PHONY: diagrams
204211
diagrams: docs/lima-sequence-diagram.png
205212
docs/lima-sequence-diagram.png: docs/images/lima-sequence-diagram.puml

cmd/limactl/genschema.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/invopop/jsonschema"
8+
"github.com/lima-vm/lima/pkg/limayaml"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func newGenSchemaCommand() *cobra.Command {
13+
genschemaCommand := &cobra.Command{
14+
Use: "generate-schema",
15+
Short: "Generate json-schema document",
16+
Args: WrapArgsError(cobra.NoArgs),
17+
RunE: genschemaAction,
18+
Hidden: true,
19+
}
20+
return genschemaCommand
21+
}
22+
23+
func genschemaAction(cmd *cobra.Command, _ []string) error {
24+
schema := jsonschema.Reflect(&limayaml.LimaYAML{})
25+
j, err := json.MarshalIndent(schema, "", " ")
26+
if err != nil {
27+
return err
28+
}
29+
_, err = fmt.Fprintln(cmd.OutOrStdout(), string(j))
30+
return err
31+
}

cmd/limactl/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func newApp() *cobra.Command {
119119
newDiskCommand(),
120120
newUsernetCommand(),
121121
newGenDocCommand(),
122+
newGenSchemaCommand(),
122123
newSnapshotCommand(),
123124
newProtectCommand(),
124125
newUnprotectCommand(),

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
github.com/foxcpp/go-mockdns v1.1.0
2424
github.com/goccy/go-yaml v1.11.3
2525
github.com/google/go-cmp v0.6.0
26+
github.com/invopop/jsonschema v0.12.0
2627
github.com/lima-vm/go-qcow2reader v0.1.1
2728
github.com/lima-vm/sshocker v0.3.4
2829
github.com/mattn/go-isatty v0.0.20
@@ -59,6 +60,8 @@ require (
5960
github.com/VividCortex/ewma v1.2.0 // indirect
6061
github.com/a8m/envsubst v1.4.2 // indirect
6162
github.com/alecthomas/participle/v2 v2.1.1 // indirect
63+
github.com/bahlo/generic-list-go v0.2.0 // indirect
64+
github.com/buger/jsonparser v1.1.1 // indirect
6265
github.com/davecgh/go-spew v1.1.1 // indirect
6366
github.com/digitalocean/go-libvirt v0.0.0-20220804181439-8648fbde413e // indirect
6467
github.com/dimchansky/utfbom v1.1.1 // indirect
@@ -103,6 +106,7 @@ require (
103106
github.com/rivo/uniseg v0.2.0 // indirect
104107
github.com/russross/blackfriday/v2 v2.1.0 // indirect
105108
github.com/u-root/uio v0.0.0-20210528114334-82958018845c // indirect
109+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
106110
github.com/yuin/gopher-lua v1.1.1 // indirect
107111
go.uber.org/atomic v1.7.0 // indirect
108112
go.uber.org/multierr v1.7.0 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPp
2323
github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU=
2424
github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
2525
github.com/armon/go-proxyproto v0.0.0-20210323213023-7e956b284f0a/go.mod h1:QmP9hvJ91BbJmGVGSbutW19IC0Q9phDCLGaomwTJbgU=
26+
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
27+
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
2628
github.com/balajiv113/fd v0.0.0-20230330094840-143eec500f3e h1:IdMhFPEfTZQU971tIHx3UhY4l+yCeynprnINrDTSrOc=
2729
github.com/balajiv113/fd v0.0.0-20230330094840-143eec500f3e/go.mod h1:aXGMJsd3XrnUFTuyf/pTGg5jG6CY8JMZ5juywvShjgQ=
30+
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
31+
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
2832
github.com/cheggaaa/pb/v3 v3.1.5 h1:QuuUzeM2WsAqG2gMqtzaWithDJv0i+i6UlnwSCI4QLk=
2933
github.com/cheggaaa/pb/v3 v3.1.5/go.mod h1:CrxkeghYTXi1lQBEI7jSn+3svI3cuc19haAj6jM60XI=
3034
github.com/containerd/containerd v1.7.16 h1:7Zsfe8Fkj4Wi2My6DXGQ87hiqIrmOXolm72ZEkFU5Mg=
@@ -135,6 +139,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
135139
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
136140
github.com/insomniacslk/dhcp v0.0.0-20220504074936-1ca156eafb9f h1:l1QCwn715k8nYkj4Ql50rzEog3WnMdrd4YYMMwemxEo=
137141
github.com/insomniacslk/dhcp v0.0.0-20220504074936-1ca156eafb9f/go.mod h1:h+MxyHxRg9NH3terB1nfRIUaQEcI0XOVkdR9LNBlp8E=
142+
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
143+
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
138144
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
139145
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
140146
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@@ -264,6 +270,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
264270
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
265271
github.com/u-root/uio v0.0.0-20210528114334-82958018845c h1:BFvcl34IGnw8yvJi8hlqLFo9EshRInwWBs2M5fGWzQA=
266272
github.com/u-root/uio v0.0.0-20210528114334-82958018845c/go.mod h1:LpEX5FO/cB+WF4TYGY1V5qktpaZLkKkSegbr0V4eYXA=
273+
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
274+
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
267275
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
268276
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
269277
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=

0 commit comments

Comments
 (0)