Skip to content

aacebo/jsonschema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonschema

License Go Reference Go Report Card Build Status codecov

a zero dependency jsonschema implementation

Usage

CLI

$: jsonschema **/*

Files

schema, err := jsonschema.Read("./schema.json")

if err != nil {
    panic(err)
}

errs := jsonschema.Compile(schema)

if len(errs) > 0 {
    panic(errs)
}

Builder

schema := jsonschema.Builder().
    Object().
    Properties(map[string]jsonschema.Schema{
        "test": jsonschema.Builder().String().Build(),
    }).
    AdditionalProperties(jsonschema.Builder().Integer().Build()).
    Required("test").
    Build()

errs := jsonschema.Compile(schema)

if len(errs) > 0 {
    panic(errs)
}

errs = jsonschema.Validate(schema, struct {
    Test  string `json:"test"`
    Other int    `json:"other"`
}{"test", 1})

if len(errs) > 0 {
    panic(errs)
}

Non-Global Namespace

namespace := jsonschema.New()

Custom Keywords

jsonschema.AddKeyword("alphaNum", jsonschema.Keyword{ ... })

Custom Formats

jsonschema.AddFormat("lowercase", func(input string) error {
    if strings.ToLower(input) != input {
        return errors.New("must be lowercase")
    }

    return nil
})

Formats

  • date-time
  • email
  • ipv4
  • ipv6
  • uri
  • uuid

Supported Drafts

Draft Status
4
6
7
2019-09
2020-12

Features

Name Status
Custom Keywords
Custom Error Messages
Custom Formats

To Do

  • schema builder pattern
  • cli
  • struct tags
  • add message keyword for custom error messages
  • keywords:
    • object
      • unevaluatedProperties
    • array
      • prefixItems
      • unevaluatedItems
      • minContains
      • maxContains
    • deprecated
    • readOnly
    • writeOnly
    • examples
    • contentMediaType
    • contentEncoding
    • if/then/else

About

a zero dependency jsonschema implementation

Resources

License

Stars

Watchers

Forks

Packages

No packages published