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

# 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

# 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

# Functions

Contains checks a slice to see if it contains the matching string.
No description provided by the author
Filter removes from a slice any true conditions from the delegate.
MetaSchemaVersions returns a list of all supported schema versions.
NewID returns a new ID.
NewReference returns a Reference.
ResolveIDs looks over the raw json and traverses over the schema looking for $id fields,.

# Constants

Array are used for ordered elements.
Boolean type matches only two special values: true and false.
Draft07 is not really supported.
Draft08 old name not really supported.
IETF_2019_19 formerly known as Draft 8.
Integer type is used for integral numbers.
Null type is generally used to represent a missing value.
Number type is used for any numeric type, either integers or floating point numbers.
Object are the mapping type in JSON.
String type is used for strings of text.

# Structs

Schema the base JSON Schema.

# Type aliases

DataType specifies the data type for a schema.
ID ($id) property is a URI-reference that serves two purposes: It declares a unique identifier for the schema.
No description provided by the author
Reference ($ref) is used to reference other schemas, used with allOf, anyOf and oneOf.
SchemaVersion declares which version of the JSON Schema standard that the schema was written against.