Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
json-schema-faker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fork
json-schema-faker
Commits
b8767093
Commit
b8767093
authored
10 years ago
by
Alvaro Cabrera
Browse files
Options
Downloads
Patches
Plain Diff
Update info
parent
0c1c6cb4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+102
-1
102 additions, 1 deletion
README.md
with
102 additions
and
1 deletion
README.md
+
102
−
1
View file @
b8767093
[

](https://travis-ci.org/pateketrueke/json-schema-faker)
[

](https://coveralls.io/r/pateketrueke/json-schema-faker?branch=master)
Fake your schemas!
==================
[

](https://travis-ci.org/pateketrueke/json-schema-faker)
[

](http://badge.fury.io/js/json-schema-faker)
[

](https://coveralls.io/r/pateketrueke/json-schema-faker?branch=master)
```
javascript
var
jsf
=
require
(
'
json-schema-faker
'
);
var
schema
=
{
type
:
'
object
'
,
properties
:
{
user
:
{
type
:
'
object
'
,
properties
:
{
id
:
{
$ref
:
'
#/definitions/positiveInt
'
},
name
:
{
type
:
'
string
'
,
faker
:
'
name.findName
'
},
email
:
{
type
:
'
string
'
,
format
:
'
email
'
,
faker
:
'
internet.email
'
}
},
required
:
[
'
id
'
,
'
name
'
,
'
email
'
]
}
},
required
:
[
'
user
'
],
definitions
:
{
positiveInt
:
{
type
:
'
integer
'
,
minimum
:
0
,
minimumExclusive
:
true
}
}
};
var
sample
=
jsf
(
schema
);
console
.
log
(
sample
.
user
.
name
);
// output: John Doe
```
Supported keywords
------------------
-
**$ref**
—
Resolve internal references only, and/or external if provided.
-
**required**
—
All required properties are guaranteed, if not can be omitted.
-
**pattern**
-
**format**
—
Core formats only: date-time, email, hostname, ipv4, ipv6 and uri.
-
**enum**
—
Returns any of these enumerated values.
-
**minLength/maxLength**
—
Applies length constraints to string values.
-
**minimum/maximum**
—
Applies constraints to numeric values.
-
**exclusiveMinimum/exclusiveMaximum**
—
Adds exclusivity for numeric values.
-
**multipleOf**
—
Multiply constraints for numeric values.
-
**items**
—
Support for subschema and fixed item values.
-
**minItems/maxItems**
—
Adds length constraints for array items.
-
**uniqueItems**
—
Applies uniqueness constraints for array items.
-
**additionalItems**
—
Partially supported (?)
-
**allOf/oneOf/anyOf**
—
Subschema combinators.
-
**properties**
—
Object properties to be generated.
-
**minProperties/maxProperties**
—
Adds length constraints for object properties.
-
**patternProperties**
—
RegExp-based object properties.
-
**additionalProperties**
—
Partially supported (?)
-
**dependencies**
—
Not supported yet (?)
Faking values
-------------
In order to get human-friendly samples you can use the
**faker**
property on each subschema:
```
json
{
"type"
:
"string"
,
"faker"
:
"internet.email"
}
```
The above schema will invoke:
```
javascript
require
(
'
faker
'
).
internet
.
email
();
```
Not that
**faker**
property has higher precedence than
**format**
.
Great, Why?
-----------
Actually, I've found some projects or services:
-
http://www.json-generator.com/
-
https://github.com/jonahkagan/schematic-ipsum
-
https://www.npmjs.org/package/json-schema-mock
-
https://github.com/thaume/json-schema-processor
-
https://github.com/andreineculau/json-schema-random
-
https://github.com/murgatroid99/json-schema-random-instance
But are incomplete or has limited support for some keywords, so I decided to code this library.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment