string
Synth's string
generator type regroups many different useful functionalities, from the ability to generate sentences
from a regular expression to dates and times, through leveraging Faker providers to generate valid addresses,
telephone numbers, etc.
#
patternString values generated by a specified regular expression in the pattern
key.
#
Example#
fakerSynth integrates with the Python Faker library. To generate a string using Faker
, use the "faker": {...}
key/value pair. The value of the faker
key must be an object with at least a generator
key.
#
ExampleFaker offers a variety of different fake data, in different locales and can be leveraged easily from Synth schemas using
the generator
key. Any of the Faker standard providers
generating a string can be used in a Synth schema. The example given below generates fake credit card numbers using
the credit_card_number
provider.
Some Faker providers allow for parameters to customize the generated data. These parameters can be specified alongside
the generator
field as arbitrary key/value pairs. In the example below, we used "card_type" : "amex"
.
Locales can be specified using the optional locales
key. Allowed values are the same as locales specified
in Faker's locales documentation. In the example below, we
use "locales": ["en_GB"]
. Multiple locales can be specified and Synth will sample at random among them.
#
Example#
date_timeA date_time
is a variant of the string
generator type that generates values from a specified range of date_time
values. This lets you, for example, generate valid days of the year for an updated_at
column or a
valid RFC 2822 timestamp for an email header field, among others.
You can specify a string as a date_time
by using the "date_time": {...}
key/value pair.
#
ExampleAccepted values for the "date_time"
key are objects with the following keys:
"format"
: a strftime-style parameter specifying the string formatting of the underlyingdate_time
value."subtype"
: one of the following"naive_date"
: when the underlyingdate_time
value should be a simpledate
without timezone specification,"naive_time"
: when the underlyingdate_time
value should be a simpletime
without timezone specification,"naive_date_time"
: when the underlyingdate_time
value should be a combineddate
andtime
without timezone specification,"date_time"
: when the underlyingdate_time
value should be a combineddate
andtime
with timezone specification.
"begin"
and"end"
: the lower and upper bounds of thedate_time
value to generate. The formatting of these values must adhere to thestrftime
-string specified in the"format"
field.
#
Example#
serializedserialized
is a variant of the string
generator type which serializes the output of a child generator into a string.
serialized
has 2 fields,
serializer
: The serializer to be used (currently onlyjson
)content
: The content to be serialized. This can be any valid Synth generator
#
Example#
categoricalA categorical
is a variant of the string
generator type that generates values from a finite set of user-defined
values. You can specify a string as a categorical by using the "categorical": {...}
key/value pair.
#
ExampleThe value of the "categorical"
key must be an object whose:
- keys are the allowed values of the categorical (e.g.
"pawn"
,"rook"
, etc.), - values are non-negative integers defining the relative weight of the corresponding variant (e.g.
8
,2
, etc.).