Need help with schematyper?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

idubinskiy
218 Stars 25 Forks MIT License 30 Commits 7 Opened issues

Description

Generates Go types based on JSON Schemas

Services available

!
?

Need anything else?

Contributors list

# 206,367
elastic...
Perl
tdd-uti...
Terrafo...
25 commits
# 677,742
Go
1 commit

schematyper

Generates Go struct types based on a JSON Schema.

Installation

$ go get github.com/idubinskiy/schematyper

Usage

$ schematyper schema.json

Creates a

schema_schematype.go
file with package
main
.

Command line options: ``` usage: schematyper []

Flags: --help Show context-sensitive help (also try --help-long and --help-man). -c, --console output to console instead of file -o, --out-file=OUT-FILE filename for output; default is _schematype.go --package="main" package name for generated file; default is "main" --root-type=ROOT-TYPE name of root type; default is generated from the filename --prefix=PREFIX prefix for non-root types --ptr-for-omit use a pointer to a struct for an object property that is represented as a struct if the property is not required (i.e., has omitempty tag)

Args: file containing a valid JSON schema ```

package main
(the default) will generate unexported types. Any other package name defaults to exported types.
--root-type
and
--prefix
can be used to override this behavior.

Can be used with

go generate
:

go
//go:generate schematyper -o schema_type.go -package mypackage schemas/schema.json

Schema Features Support

Supports the following JSON Schema keywords: *

title
- sets type name *
description
- sets type comment *
required
- sets which fields in type don't have
omitempty
. If --ptr-for-omit is specified and the field is not required, a field that is an object represented as a struct is generated as a pointer to the struct. *
properties
- determines struct fields *
additionalProperties
- determines struct type of map values *
type
- sets field type (
string
,
bool
, etc.). Examples: *
["string", "null"]
sets
*string
*
"object"
sets
map[string]interface{}
,
map[string]
, or a new struct type depending on schema *
"array"
sets
[]interface{}
or
[]
depending on schema *
["string", "integer"]
sets
interface{}
*
items
- sets array items type, similar to
type
*
format
- if
date-time
, sets type to
time.Time
and imports
time
*
definitions
- creates additional types which can be referenced using
$ref
*
$ref
- Reference a local schema (same file).

Support for more features is pending, but many will require adding run-time checks by implementing the

json.Marshaler
and
json.Unmarshaler
interfaces.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.