Skip to content

feat: generate json schema #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ build: $(BINARIES)

$(BINARIES): init
@go build -o $@ main.go

.PHONY: gen
gen:
@go generate ./...
@go run scripts/main.go
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.12.0
github.com/spf13/pflag v1.0.5 // indirect
)
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
142 changes: 142 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/shiron-dev/arcanum-hue/internal/converter/model/config",
"$ref": "#/$defs/Config",
"$defs": {
"ColorTheme": {
"properties": {
"name": {
"type": "string"
},
"vscodeUiTheme": {
"type": "string"
},
"type": {
"type": "string"
},
"colors": {
"$ref": "#/$defs/ColorsModel"
}
},
"additionalProperties": false,
"type": "object"
},
"ColorsModel": {
"properties": {
"foreground": {
"type": "string"
},
"hiForeground": {
"type": "string"
},
"secondaryForeground": {
"type": "string"
},
"foregroundAccent": {
"type": "string"
},
"warningForeground": {
"type": "string"
},
"background": {
"type": "string"
},
"editorBackground": {
"type": "string"
},
"secondaryBackground": {
"type": "string"
},
"backgroundAccent": {
"type": "string"
},
"hiBackgroundAccent": {
"type": "string"
},
"matchBackground": {
"type": "string"
},
"border": {
"type": "string"
},
"terminalAnsi": {
"$ref": "#/$defs/TerminalAnsiModel"
}
},
"additionalProperties": false,
"type": "object"
},
"Config": {
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"colorThemes": {
"items": {
"$ref": "#/$defs/ColorTheme"
},
"type": "array"
}
},
"additionalProperties": false,
"type": "object"
},
"TerminalAnsiModel": {
"properties": {
"black": {
"type": "string"
},
"brightBlack": {
"type": "string"
},
"blue": {
"type": "string"
},
"cyan": {
"type": "string"
},
"green": {
"type": "string"
},
"brightBlue": {
"type": "string"
},
"brightCyan": {
"type": "string"
},
"brightGreen": {
"type": "string"
},
"white": {
"type": "string"
},
"brightWhite": {
"type": "string"
},
"magenta": {
"type": "string"
},
"yellow": {
"type": "string"
},
"red": {
"type": "string"
},
"brightYellow": {
"type": "string"
},
"brightMagenta": {
"type": "string"
},
"brightRed": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
}
}
}
35 changes: 35 additions & 0 deletions scripts/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"encoding/json"
"os"

"github.com/invopop/jsonschema"
"github.com/shiron-dev/arcanum-hue/internal/converter/model"
)

func main() {
file, err := os.Create("./schema.json")
if err != nil {
panic(err)
}

//nolint:exhaustruct
ref := &jsonschema.Reflector{
FieldNameTag: "yaml",
RequiredFromJSONSchemaTags: true,
}

//nolint:exhaustruct
schema := ref.Reflect(&model.Config{})

schemaStr, err := json.MarshalIndent(schema, "", " ")
if err != nil {
panic(err)
}

_, err = file.Write(schemaStr)
if err != nil {
panic(err)
}
}
Loading