1602/json-schema/2.0.0

NOTE: this package is not compatible with Elm 0.19.1

Json.Schema.Random

Generate random values based on JSON Schema.

Experimental module.

Generator

value : GeneratorSettings -> Schema -> Generator Value

Default value generator.

buildSchema
    |> withProperties
        [ ( "foo", buildSchema |> withType "integer" ) ]
    |> toSchema
    |> Result.withDefault (blankSchema)
    |> value defaultSettings
    |> flip Random.step (Random.initialSeed 2)
    |> \( v, _ ) ->
        Expect.equal v (Encode.object [ ( "foo", Encode.int 688281600 ) ])

See tests for more examples.

Settings

type alias GeneratorSettings =
{ optionalPropertyProbability : Float
, degradationMultiplier : Float
, defaultListLengthLimit : Int
, defaultStringLengthLimit : Int
}

Customize generator behaviour using following parameters:

  • optionalPropertyProbability : float from 0 to 1, which affects used while generating object with optional property, default 0.5
  • degradationMultiplier : used in nested objects to affect probability of optional property appearance (must have for recursive objects), default 0.2
  • defaultListLengthLimit : how many items in array to generate when limit is not set by a schema, default 100
  • defaultStringLengthLimit : how many characters in random string to generate when limit is not set by a schema, default 100
defaultSettings : GeneratorSettings

Defaults for GeneratorSettings