Categorygithub.com/RossMerr/jsonschema
repositorypackage
0.0.0-20230224195607-8a850223f1fb
Repository: https://github.com/rossmerr/jsonschema.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Go

jsonschema

Code generation from json schemas with basic support for 2019-09:

Installation

  • go install github.com/RossMerr/jsonschema/cmd/jsonschema

Notes for usage

$id
  • Top level $id must follow the absolute-URI convention of being a canonical URL. The old 'id' field is not supported.
$ref
  • Can resolve to any point in the document or another local file using a JSON Pointer.

"#/definitions/address"

"http://www.sample.com/definitions.json#/address"

$def
  • The old 'definitions' field is still supported but merged into the new $def field.
allOf
  • Will generate a struct with all of the subschemas embedded.
anyOf
  • Will generate an array of a interface with all subschemas implementing its method.
oneOf
  • Will generate a interface with all subschemas implementing its method.

Validation

All generated go types will be a value or reference type depending on the 'required' field. All fields and struct's also get generated validation tags mostly conforming to the Well-known struct tags for validate. Additional values for the validate tag include:

  • allof
  • anyof
  • oneof
  • regex

Which you can then use for any custom validators.

Not or partial support

String
Regular Expressions

You can add support with a custom validate field tag. But a regex validator won't be added because commas and = signs can be part of a regex which conflict with the validation definitions.

Numeric
Object
Array
Generic
Media: string-encoding non-JSON data
Combining schemas
Applying subschemas conditionally
External JSON Pointer

All schemas must be local