Package jsonschema provides JSON Schema Draft 4 encoding support for schema.Schema. Note that the current implementation is incomplete, and not all FieldValidator types are yet supported. Custom validators are also not supported at the moment.




    This section is empty.


    View Source
    var (
    	//ErrKeysValidatorNotSupported is returned when Dict.KeysValidator is not a
    	//*schema.String instance or nil.
    	ErrKeysValidatorNotSupported = errors.New("KeysValidator type not supported")
    View Source
    var (
    	//ErrNoSchema is returned when trying to JSON Encode a schema.Object with
    	//the Schema property set to nil.
    	ErrNoSchema = errors.New("no schema defined for object")
    View Source
    var (
    	//ErrNoSchemaList is returned when trying to JSON Encode an empty
    	//schema.AnyOf or schema.AllOf slice.
    	ErrNoSchemaList = errors.New("at least one schema must be specified")
    View Source
    var (
    	// ErrNotImplemented is returned when the JSON schema encoding logic for a
    	// schema.FieldValidator has not (yet) been implemented.
    	ErrNotImplemented = errors.New("not implemented")


    This section is empty.


    type Builder

    type Builder interface {
    	// BuildJSONSchema should return a map containing JSON Schema Draft 4
    	// properties that can be set based on FieldValidator data. Application
    	// specific properties can be added as well, but should not conflict with
    	// any legal JSON Schema keys.
    	BuildJSONSchema() (map[string]interface{}, error)

      The Builder interface should be implemented by custom schema.FieldValidator implementations to allow JSON Schema serialization.

      func ValidatorBuilder

      func ValidatorBuilder(v schema.FieldValidator) (Builder, error)

        ValidatorBuilder type-casts v to a valid Builder implementation or returns an error.

        type Encoder

        type Encoder struct {
        	// contains filtered or unexported fields

          Encoder writes the JSON Schema representation of a schema.Schema to an output stream. Note that only a sub-set of the FieldValidator types in the schema package is supported at the moment. Custom validators are also not yet handled. Attempting to encode a schema containing such fields will result in a ErrNotImplemented error.

          | "additionalProperties": false,
          | "properties": {
          | | "bar": {
          | | | "type": "integer"
          | | },
          | | "baz": {
          | | | "description": "baz can not be set by the user",
          | | | "maxLength": 42,
          | | | "readOnly": true,
          | | | "type": "string"
          | | },
          | | "foo": {
          | | | "minimum": 0,
          | | | "type": "number"
          | | },
          | | "foobar": {
          | | | "description": "foobar can hold any valid JSON value"
          | | }
          | },
          | "required": [
          | | "foo"
          | ],
          | "type": "object"

          func NewEncoder

          func NewEncoder(w io.Writer) *Encoder

            NewEncoder returns a new JSONSchema Encoder that writes to w.

            func (*Encoder) Encode

            func (e *Encoder) Encode(s *schema.Schema) error

              Encode writes the JSON Schema representation of s to the stream, followed by a newline character.