Releases: discovery-digital/jsonschema
v1.10.6
v1.10.5
v1.10.4
v1.10.3
v1.10.2
SchemaSwitch
now has fieldOrder
to allow deterministic output of the fields due tomap
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
#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
- 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
- Fix from @debovema
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
-
jsonschema:"optional"
will make the field optionalThe 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 declareomitempty
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
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"
}