Skip to main content

Configuration

Mockend is configured using a .mockend.json file that you commit on your repository.

.mockend.json
{
"ModelName": {
"fieldName": {
"<type>": {} | [],
"hasMany": "Model",
"belongsTo": "Model"
}
}
}

Model

Model names are singular and start with a capital letter.

{
"User": {},
"Post": {},
"Comment": {},
"Person": {},
"City": {}
}

Field

Field names can be any valid JSON field name.

Types

string

Generates a random string.

{ "title": { "string": {} }

int

Generates a random integer between min and max.

{ "likes": { "int": { "min": 0, "max": 1000000 } } }

boolean

Generates a random boolean.

{ "isPublished": { "boolean": {} } }

dateTime

Generates a random RFC3339 DateTime between min and max.

{
"createdAt: {
"dateTime": {
"min": "2010-01-01T00:00:00Z",
"max": "2020-12-31T23:59:59Z"
}
}
}

regexp

Generates a random string based on regular expression.

{ "name": { "regexp": "[A-Z][a-z]{5,10}" } }
[ { "name": "Mxokole" }, { "name": "Tuilo" }, ... ]

loremWord

Generates a random word.

{
"tag": {
"loremWord": {}
}
}
[ { "tag": "ipsum" }, { "tag": "velit" }, ... ]

loremWords

Generates random words between minLength and maxLength.

{
"title": {
"loremWords": { "minLength": 5, "maxLength": 20 }
}
}
[ { "title": "lorem ipsum dolor" }, ... ]

loremSentences

Generates random sentences between minLength and maxLength.

{
"longDescription": {
"loremSentences": { "minLength": 100, "maxLength": 200 }
}
}
[ { "description": "Lorem ipsum ... sit. Ut enim ... duis." }, ... ]

loremParagraphs

Generates random paragraphs between minLength and maxLength.

{
"text": {
"loremParagraphs": { "minLength": 200, "maxLength": 500 }
}
}

Custom data

To have an API closer to your domain, you can provide a set of strings or integers which will be randomly picked.

tip

There are many libs that lets you generate common values like names, countries, ... (e.g. Faker for Python, Faker for Ruby, ...)

tip

Editing JSON files by hand can become cumbersome. If your .mockend.json gets big, you can consider having a script to generate it instead.

string[]

{
"name": {
"string": [
"Thor",
"Loki"
]
}
}
[ { "name": "Loki" }, { "name": "Loki" }, { "name": "Thor" }, ... ]

int[]

{
"code": {
"int": [
100,
200,
300
]
}
}
[ { "code": 200 }, { "code": 300 }, { "code": 300 }, ... ]

Relations

You can describe relations between models.

hasMany

{
"Post": {
"userComments": {
"hasMany": "Comment"
}
}
}

userComments field will have an array of generated Comment.

belongsTo

{
"Comment": {
"authorPost": {
"belongsTo": "Post"
}
}
}

authorPost field will have a generated Post.

note

Relations are only supported with GraphQL.

Other examples

regexp generator is a powerful way to create any string. Here are some examples to get you started. Feel free to adapt them to suit your needs.

Pictures

{
"avatar": {
"regexp": "https://i\\.pravatar\\.cc/150\\?u=[0-9]{5}"
},
"photo": {
"regexp": "https://picsum\\.photos/seed/[0-9]{5}/1920/1080"
}
}

Generates URLs to online services with a random seed ([0-9]{5} = 5 random numbers).

Names

{ "firstName": { "regexp": "[A-Z][a-z]{5,10}" } }

Generates a random string starting with an uppercase letter and between 5 to 10 lowercase letters.

Emails

{ "email": { "regexp": "[a-z]{5,10}@[a-z]{5}\\.[a-z]{2,3}" } }

Generates an email containing @ and a 2 to 3 letters domain.

Hex colors

{ "color": { "regexp": "#[0-9A-F]{6}" } }

Generates an hex color.