1602 / json-schema / Json.Schema.Definitions

This module contains low-level structures JSON Schema build from. Normally you wouldn't need to use any of those definitions.

If you really need this low-level API you might need JSON Schema spec as guidance.

Feel free to open issue to describe your use-case, it will affect development roadmap of this library.

Definitions


type Schema
    = BooleanSchema Basics.Bool
    | ObjectSchema SubSchema

Schema can be either boolean or actual object containing validation and meta properties


type alias SubSchema =
{ type_ : Type
, id : Maybe String
, ref : Maybe String
, title : Maybe String
, description : Maybe String
, default : Maybe Json.Decode.Value
, examples : Maybe (List Json.Decode.Value)
, definitions : Maybe Schemata
, multipleOf : Maybe Basics.Float
, maximum : Maybe Basics.Float
, exclusiveMaximum : Maybe ExclusiveBoundary
, minimum : Maybe Basics.Float
, exclusiveMinimum : Maybe ExclusiveBoundary
, maxLength : Maybe Basics.Int
, minLength : Maybe Basics.Int
, pattern : Maybe String
, format : Maybe String
, items : Items
, additionalItems : Maybe Schema
, maxItems : Maybe Basics.Int
, minItems : Maybe Basics.Int
, uniqueItems : Maybe Basics.Bool
, contains : Maybe Schema
, maxProperties : Maybe Basics.Int
, minProperties : Maybe Basics.Int
, required : Maybe (List String)
, properties : Maybe Schemata
, patternProperties : Maybe Schemata
, additionalProperties : Maybe Schema
, dependencies : List ( String
, Dependency )
, propertyNames : Maybe Schema
, enum : Maybe (List Json.Decode.Value)
, const : Maybe Json.Decode.Value
, allOf : Maybe (List Schema)
, anyOf : Maybe (List Schema)
, oneOf : Maybe (List Schema)
, not : Maybe Schema
, source : Json.Decode.Value 
}

This object holds all draft-6 schema properties


type Schemata
    = Schemata (List ( String, Schema ))

List of schema-properties used in properties, definitions and patternProperties


type Items
    = NoItems
    | ItemDefinition Schema
    | ArrayOfItems (List Schema)

Items definition.


type Dependency
    = ArrayPropNames (List String)
    | PropSchema Schema

Dependency definition.


type Type
    = AnyType
    | SingleType SingleType
    | NullableType SingleType
    | UnionType (List SingleType)

Type property in json schema can be a single type or array of them, this type definition wraps up this complexity, also it introduces concept of nullable type, which is array of "null" type and a single type speaking JSON schema language, but also a useful concept to treat it separately from list of types.


type SingleType
    = IntegerType
    | NumberType
    | StringType
    | BooleanType
    | ArrayType
    | ObjectType
    | NullType

blankSchema : Schema

Create blank JSON Schema {}.

blankSubSchema : SubSchema


type ExclusiveBoundary
    = BoolBoundary Basics.Bool
    | NumberBoundary Basics.Float

Exclusive boundaries. Compatibility layer between draft-04 and draft-06 (keywords exclusiveMinimum and exclusiveMaximum has been changed from a boolean to a number to be consistent with the principle of keyword independence). Since we currently keep both draft-4 and draft-6 as same type definition, we have a union of Bool and Float here. It might be not a bad idea to separate type definitions for different drafts of JSON Schema, current API decision will be reconsidered when future versions of JSON Schema will arrive.

Decoding / encoding

decoder : Json.Decode.Decoder Schema

encode : Schema -> Json.Decode.Value

Misc

stringToType : String -> Result String SingleType

Attempt to parse string into a single type, it recognises the following list of types:

getCustomKeywordValue : String -> Schema -> Maybe Json.Decode.Value

Return custom keyword value by its name, useful when dealing with additional meta information added along with standard JSON Schema keywords.