|
2 | 2 |
|
3 | 3 | This tool generates Go data types and structs that corresponds to definitions in the schema, along with unmarshaling code that validates the input JSON according to the schema's validation rules. |
4 | 4 |
|
| 5 | +## Installing |
| 6 | + |
| 7 | +* **Binary install**: Get a release [here](https://github.com/atombender/go-jsonschema/releases). |
| 8 | + |
| 9 | +* **From source**: Go 1.11 or later, with Go modules enabled, is advisable in order to get the right dependencies. To install: |
| 10 | + |
| 11 | +```shell |
| 12 | +$ go get github.com/atombender/go-jsonschema/... |
| 13 | +$ go install github.com/atombender/go-jsonschema/cmd/gojsonschema |
| 14 | +``` |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +At its most basic: |
| 19 | + |
| 20 | +```shell |
| 21 | +$ gojsonschema -p main schema.json |
| 22 | +``` |
| 23 | + |
| 24 | +This will write a Go source file to standard output, declared under the package `main`. |
| 25 | + |
| 26 | +You can generate code for multiple schemas in the same invocation, optionally writing to different files inside different packages: |
| 27 | + |
| 28 | +```shell |
| 29 | +$ gojsonschema \ |
| 30 | + --schema-package=https://example.com/schema1=github.com/myuser/myproject \ |
| 31 | + --schema-output=https://example.com/schema1=schema1.go \ |
| 32 | + --schema-package=https://example.com/schema2=github.com/myuser/myproject/stuff \ |
| 33 | + --schema-output=https://example.com/schema2=stuff/schema2.go \ |
| 34 | + schema1.json schema2.json |
| 35 | +``` |
| 36 | + |
| 37 | +This will create `schema1.go` (declared as `package myproject`) and `stuff/schema2.go` (declared as `package stuff`). If `schema1.json` refers to `schema2.json` or vice versa, the two Go files will import the other package that it depends on. Note the flag format: |
| 38 | + |
| 39 | +``` |
| 40 | +--schema-package=https://example.com/schema1=github.com/myuser/myproject \ |
| 41 | + ^ ^ |
| 42 | + | | |
| 43 | + schema $id full import URL |
| 44 | +``` |
| 45 | + |
5 | 46 | ## Status |
6 | 47 |
|
7 | 48 | While not finished, go-jsonschema can be used today. Aside from some minor features, only specific validations remain to be fully implemented. |
@@ -80,45 +121,6 @@ While not finished, go-jsonschema can be used today. Aside from some minor featu |
80 | 121 | - [ ] JSON pointers |
81 | 122 | - [ ] Regex |
82 | 123 |
|
83 | | -## Usage |
84 | | - |
85 | | -At its most basic: |
86 | | - |
87 | | -```shell |
88 | | -$ gojsonschema -p main schema.json |
89 | | -``` |
90 | | - |
91 | | -This will write a Go source file to standard output, declared under the package `main`. |
92 | | - |
93 | | -You can generate code for multiple schemas in the same invocation, optionally writing to different files inside different packages: |
94 | | - |
95 | | -```shell |
96 | | -$ gojsonschema \ |
97 | | - --schema-package=https://example.com/schema1=github.com/myuser/myproject \ |
98 | | - --schema-output=https://example.com/schema1=schema1.go \ |
99 | | - --schema-package=https://example.com/schema2=github.com/myuser/myproject/stuff \ |
100 | | - --schema-output=https://example.com/schema2=stuff/schema2.go \ |
101 | | - schema1.json schema2.json |
102 | | -``` |
103 | | - |
104 | | -This will create `schema1.go` (declared as `package myproject`) and `stuff/schema2.go` (declared as `package stuff`). If `schema1.json` refers to `schema2.json` or vice versa, the two Go files will import the other package that it depends on. Note the flag format: |
105 | | - |
106 | | -``` |
107 | | ---schema-package=https://example.com/schema1=github.com/myuser/myproject \ |
108 | | - ^ ^ |
109 | | - | | |
110 | | - schema $id full import URL |
111 | | -``` |
112 | | - |
113 | | -## Installing |
114 | | - |
115 | | -Requires Go 1.11 or later, with Go modules enabled. To install: |
116 | | - |
117 | | -```shell |
118 | | -$ go get github.com/atombender/go-jsonschema/... |
119 | | -$ go install github.com/atombender/go-jsonschema/cmd/gojsonschema |
120 | | -``` |
121 | | - |
122 | 124 | ## License |
123 | 125 |
|
124 | | -BSD license. See `LICENSE` file. |
| 126 | +MIT license. See `LICENSE` file. |
0 commit comments