
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
openapi-mock-generator
Advanced tools
Create realistic mocked data from an OpenAPI specification, using [faker.js](https://github.com/marak/Faker.js/) and [Chance](https://chancejs.com/) random data generators.
Create realistic mocked data from an OpenAPI specification, using faker.js and Chance random data generators.
format
. minimum
, maximum
, etc...), faker.js or Chance data generators.Once you have loaded an OpenApi specification, you can navigate the tree with paths and schemas, and load a definition in the editor. You can modify the selected definition and see the generated mocked data in the editor on the right. The modified definition will be taken also by other elements that have a reference to that definition.
In the tree, there is also a special Playground
item that can be used to generate data "on the fly" without modifying an existing definition.
Data can be generated from the format
property:
{
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date-time"
},
"uuid": {
"type": "string",
"format": "uuid"
}
}
}
{
"date": "1986-09-22T16:44:15.119Z",
"uuid": "daf0229f-cc3b-2b50-bbe4-6dea4837b0bf"
}
Number ranges can be controlled with minimum
and maximum
:
{
"type": "integer",
"minimum": 10,
"maximum": 42
}
21
Array items length can be controlled with minItems
and maxItems
:
{
"type": "array",
"minItems": 5,
"maxItems": 10,
"items": {
"type": "number"
}
}
[
71856238.93752578,
-9957501.746244192,
-7145041.207682312,
-53358509.39871331,
-83770088.68054512,
-25448017.578881666,
45764879.26211512,
-5112859.453620076,
-74878171.17192386,
46948099.995764345
]
You can use the name of a faker.js
or Chance
method using the x-faker
or x-chance
properties:
{
"type": "object",
"properties": {
"name": {
"type": "string",
"x-chance": "company"
},
"description": {
"type": "string",
"x-faker": "company.catchPhrase"
}
}
}
{
"name": "Citigroup, Inc",
"description": "Vision-oriented foreground middleware"
}
You can pass parameters to the method using an object with the method name as a key and an array of values as parameters:
{
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date",
"x-faker": {
"date.between": ["2000", "2050"]
}
}
}
}
{
"date": "2040-05-06"
}
You can pass also object as a single parameter:
{
"type": "object",
"properties": {
"email": {
"type": "string",
"format": "email",
"x-chance": {
"email": {
"domain": "acme.com"
}
}
}
}
}
{
"email": "aci@acme.com"
}
For Faker.js, you can interpolate multiple results with the fake
method:
{
"type": "object",
"properties": {
"name": {
"type": "string",
"x-faker": {
"fake": ["{{name.lastName}}, {{name.firstName}} {{name.suffix}}"]
}
}
}
}
{
"name": "Schmeler, Odie Jr."
}
The code generation is based on json-schema-faker, you can also check the project documentation for other examples.
MIT
FAQs
Create realistic mocked data from an OpenAPI specification, using [faker.js](https://github.com/marak/Faker.js/) and [Chance](https://chancejs.com/) random data generators.
We found that openapi-mock-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.