Skip to content

Releases: discovery-digital/jsonschema

v1.10.6

10 Sep 22:22
Compare
Choose a tag to compare
  • Fixes exclusiveMin and exclusiveMax types for draft-07.

This is a breaking change but it is due to implementation error.

v1.10.5

25 Jun 03:00
Compare
Choose a tag to compare
  • Actually provide the behavior described in v1.10.2

v1.10.4

07 Jun 03:13
333ed5c
Compare
Choose a tag to compare
  • Allow allowNull keyword for arrays

v1.10.3

03 Jun 23:00
91708fb
Compare
Choose a tag to compare

Field name collisions from an embed are now allowed when they have a different json name declared

v1.10.2

22 May 04:37
Compare
Choose a tag to compare
  • SchemaSwitch now has fieldOrder to allow deterministic output of the fields due to map usage. If the field names are not provided by the implementer, they will be seeded internally.

There generally aren't many cases where you want it to provide the values here, but the option is open.

v1.10.1 - $schema should only be declared once in the root

29 Apr 03:09
Compare
Choose a tag to compare

#24 from @mrfosip keeps $schema declared only in the root, as described by the specification, which may cause certain json validators to blow up

v1.10.0

23 Mar 23:55
Compare
Choose a tag to compare
  • Implement allOf, anyOf constructs
  • Refactoring out the subschema implementations to improve clarity
  • Comments for the subschema implementations to give more context
  • Files have been moved and renamed to address the growing codebase
  • Update README to document all features this fork has introduced
  • Address pointer issue reported in #21

v1.9.1

23 Feb 17:59
Compare
Choose a tag to compare

Currently, a field with a encoding/json.RawMessage will output in JSON schema as an array of integer:

{
    "items": {
        "type": "integer"
    },
    "type": "array"
}

basically because it's an alias to a slice of bytes.

However it should output to an object:

{
    "type": "object"
}

the same way it is done for map[string]interface{} :

v1.9.0 - `optional` flag

07 Dec 08:06
a24f638
Compare
Choose a tag to compare
  • jsonschema:"optional" will make the field optional

    The use case for this is when you are taking json input where validation on a field should be optional
    but you do not want to declare omitempty because you serialize the struct to json to a third party
    and the fields must exist (such as a field that's an int)

v1.8.0 - Support minItems, maxItems validation for slices

07 Dec 03:47
Compare
Choose a tag to compare

If jsonschema.Reflector is provided a typed slice collection that implements MinItems and/or MaxItems as depicted below, jsonschema will be generated to validate the slice and its contents.

package main

import (
	"encoding/json"
	"fmt"
	"github.com/discovery-digital/jsonschema"
)

type Goo struct {
	Bar string `json:"bar" jsonschema:"required"`
}

type GooCollection []Goo
func (fc GooCollection) MinItems() int {
	return 2
}

func (fc GooCollection) MaxItems() int {
	return 7
}

func main() {
	goo := GooCollection{}

	s := jsonschema.Reflect(goo)
	schema, _ := json.MarshalIndent(s, "", "\t")
	fmt.Println(string(schema))
}

Generated jsonschema

{
  "definitions": {
    "main.Goo": {
      "additionalProperties": false,
      "properties": {
        "bar": {
          "type": "string"
        }
      },
      "required": [
        "bar"
      ],
      "type": "object"
    }
  },
  "items": {
    "$ref": "#/definitions/main.Goo",
    "$schema": "http://json-schema.org/draft-07/schema#"
  },
  "maxItems": 7,
  "minItems": 2,
  "type": "array"
}