Skip to content

Commit 68284aa

Browse files
committed
initial commit
0 parents  commit 68284aa

File tree

10 files changed

+1658
-0
lines changed

10 files changed

+1658
-0
lines changed

.gitignore

Whitespace-only changes.

.golangci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: '2'
2+
linters:
3+
enable:
4+
- asasalint
5+
- asciicheck
6+
- bidichk
7+
- bodyclose
8+
- containedctx
9+
- contextcheck
10+
- copyloopvar
11+
- decorder
12+
- dogsled
13+
- err113
14+
- exhaustive
15+
- fatcontext
16+
- gocheckcompilerdirectives
17+
- goconst
18+
- gomoddirectives
19+
- govet
20+
- iface
21+
- ineffassign
22+
- interfacebloat
23+
- intrange
24+
- makezero
25+
- mirror
26+
- misspell
27+
- nestif
28+
- nilerr
29+
- nilnesserr
30+
- noctx
31+
- nonamedreturns
32+
- nosprintfhostport
33+
- protogetter
34+
- staticcheck
35+
- tagalign
36+
- testifylint
37+
- unconvert
38+
- unparam
39+
- unused
40+
- wastedassign
41+
- wsl_v5
42+
43+
settings:
44+
gomoddirectives:
45+
go-version-pattern: '1\.\d+(\.0)?$'
46+
replace-local: true
47+
replace-allow-list:
48+
- google.golang.org/genproto

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# jsonforms-parser
2+
3+
A dependency-free Go parser for [JSON Forms](https://jsonforms.io) schemas. Produces a type-safe AST for building custom renderers.
4+
5+
## Features
6+
7+
- **All Standard Elements** - Control, Layout, Group, Categorization, Category, Label
8+
- **Custom Elements** - Unknown types preserved with parsed children
9+
- **Rules & Conditions** - HIDE/SHOW/ENABLE/DISABLE with schema-based, leaf, AND, OR conditions
10+
- **Visitor Pattern** - Traverse and transform the AST
11+
- **Type-Safe** - Strongly-typed nodes, no generic maps
12+
- **Zero Dependencies** - Pure Go stdlib
13+
14+
## Installation
15+
16+
```bash
17+
go get github.com/tinybluerobots/jsonforms-parser
18+
```
19+
20+
## Usage
21+
22+
```go
23+
import "github.com/tinybluerobots/jsonforms-parser"
24+
25+
ast, err := jsonforms.Parse(uiSchemaJSON, schemaJSON)
26+
if err != nil {
27+
log.Fatal(err)
28+
}
29+
30+
layout := ast.UISchema.(*jsonforms.VerticalLayout)
31+
control := layout.Elements[0].(*jsonforms.Control)
32+
fmt.Println(control.Scope) // "#/properties/name"
33+
```
34+
35+
## Elements
36+
37+
All elements implement `UISchemaElement`:
38+
- `Control` - Binds UI to data property
39+
- `VerticalLayout`, `HorizontalLayout` - Layout containers
40+
- `Group` - Labeled container
41+
- `Categorization`, `Category` - Tab navigation
42+
- `Label` - Static text
43+
- `CustomElement` - Unknown/custom types
44+
45+
## Visitor Pattern
46+
47+
```go
48+
type MyVisitor struct {
49+
jsonforms.BaseVisitor
50+
}
51+
52+
func (v *MyVisitor) VisitControl(c *jsonforms.Control) error {
53+
fmt.Println("Found:", c.Scope)
54+
return nil
55+
}
56+
57+
jsonforms.Walk(ast.UISchema, &MyVisitor{})
58+
```
59+
60+
## Use Cases
61+
62+
Build custom renderers, transform schemas, validate structures, generate docs, or convert between form systems.
63+
64+
## License
65+
66+
MIT

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/tinybluerobots/jsonforms-parser
2+
3+
go 1.25
4+
5+
require github.com/stretchr/testify v1.11.1
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
6+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

mise.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tools]
2+
golangci-lint = "latest"
3+
gotestsum = "latest"
4+
5+
[tasks.lint]
6+
run = "golangci-lint run --fix ./..."
7+
8+
[tasks.test]
9+
run = "gotestsum"

0 commit comments

Comments
 (0)