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
e72b826d
Commit
e72b826d
authored
10 years ago
by
Alvaro Cabrera
Browse files
Options
Downloads
Patches
Plain Diff
Update info
parent
ee89a8f3
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
+32
-4
32 additions, 4 deletions
README.md
with
32 additions
and
4 deletions
README.md
+
32
−
4
View file @
e72b826d
...
@@ -3,6 +3,8 @@ Fake your schemas!
...
@@ -3,6 +3,8 @@ 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)
[

](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)
`json-schema-faker`
supports (currently) the JSON-Schema specification
**draft-04**
only (?)
```
javascript
```
javascript
var
jsf
=
require
(
'
json-schema-faker
'
);
var
jsf
=
require
(
'
json-schema-faker
'
);
...
@@ -98,11 +100,12 @@ console.log(sample.someValue);
...
@@ -98,11 +100,12 @@ console.log(sample.someValue);
// output: voluptatem
// output: voluptatem
```
```
Faking values
Faking values
-------------
-------------
Generate human-friendly samples by using
**faker**
property on each subschema:
`json-schema-faker`
supports
[
Faker.js
](
http://marak.com/faker.js/
)
and
[
Chance.js
](
http://chancejs.com/
)
sample generators.
Use the
**faker**
or
**chance**
property on each subschema for this:
```
json
```
json
{
{
...
@@ -117,7 +120,31 @@ The above schema will invoke:
...
@@ -117,7 +120,31 @@ The above schema will invoke:
require
(
'
faker
'
).
internet
.
email
();
require
(
'
faker
'
).
internet
.
email
();
```
```
Not that
**faker**
property has higher precedence than
**format**
.
Another example is passing arguments to the generator:
```
json
{
"type"
:
"string"
,
"chance"
:
{
"email"
:
{
"domain"
:
"fake.com"
}
}
}
```
And will invoke:
```
javascript
var
Chance
=
require
(
'
chance
'
),
chance
=
new
Chance
();
chance
.
email
({
"
domain
"
:
"
fake.com
"
});
```
If you pass an array, they will be used as raw arguments.
Note that both generators has higher precedence than
**format**
.
Great, Why?
Great, Why?
-----------
-----------
...
@@ -125,13 +152,14 @@ Great, Why?
...
@@ -125,13 +152,14 @@ Great, Why?
Actually, I've found some projects or services:
Actually, I've found some projects or services:
-
http://www.json-generator.com/
-
http://www.json-generator.com/
-
https://github.com/unindented/fake-json
-
https://github.com/jonahkagan/schematic-ipsum
-
https://github.com/jonahkagan/schematic-ipsum
-
https://www.npmjs.org/package/json-schema-mock
-
https://www.npmjs.org/package/json-schema-mock
-
https://github.com/thaume/json-schema-processor
-
https://github.com/thaume/json-schema-processor
-
https://github.com/andreineculau/json-schema-random
-
https://github.com/andreineculau/json-schema-random
-
https://github.com/murgatroid99/json-schema-random-instance
-
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.
Many of they
are incomplete
(?)
, so I decided to code this library.
Issues
Issues
------
------
...
...
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