wf-generate
is a Node.js-based generator that uses Swagger definitions and mapping files to automatically generate
mock data. This data can be used for testing APIs or as placeholders in development environments.
To install wf-generate
, make sure you have Node.js installed, then run the following command:
npm install @wesflo/generator
After installation, you can invoke the tool via the command line. The script will be available by default with the
command wf-generate
.
Run the command:
` npx wf-generate `
The configuration is done through the package.json
file. Here you can specify the paths to your Swagger file, mapping
files, and the target folder for the generated mock data.
Example for package.json
:
{
"wfGenerator": {
"swagger": "mock/swagger.yaml",
"mappings": [
"mock/mapping.yaml",
"mock/overwrite.yaml"
],
"target": "tmp/mocks"
}
When the generator starts, you will be prompted for several inputs:
mock/swagger.yaml
).mock/mapping.yaml
)../mocks
).In the mapping.yaml
, different types can be used to define the structure and constraints of the generated mock data.
Below is a description of the supported types and their properties:
type: number
length
: Specifies the length of the number (e.g., how many digits it should have).min
: The minimum value for the number.max
: The maximum value for the number.step
: The step value when iterating (e.g., 10, 20, 30, etc.).Example:
someNumber.value:
type: number
length: 10
min: 1000
max: 9995
step: 5
type: string
minLength
: The minimum length of the string.maxLength
: The maximum length of the string.Example:
someString.value:
type: string
minLength: 5
maxLength: 50
type: date
format
: The format of the date, such as YYYY-MM-DD
, MM-DD-YYYY
, etc.Example:
someDate.value:
type: date
format: YYYY-MM-DD
type: paragraph
minLength
: The minimum number of characters in the paragraph.maxLength
: The maximum number of characters in the paragraph.Example:
someParagraph.value:
type: paragraph
minLength: 20
maxLength: 200
type: image
width
: The width of the image.height
: The height of the image.Example:
productImage.value:
type: image
width: 200
height: 400
type: currency
min
: The minimum value for the currency.max
: The maximum value for the currency.Example:
someCurrency.value:
type: currency
min: 5.00
max: 1000.00
In mapping.yaml
, you can define different data types such
as number
, string
, date
, paragraph
, image
, currency
, and link
. Each type has specific properties that you
can adjust to generate the mock data that fits your needs. For example, for a number
type, you can define its length,
range, and step, while for a string
type, you can set its minimum and maximum length.
These types provide flexibility in generating mock data that precisely matches your requirements.
mapping.yaml
)someKey.value:
type: number
length: 10
anotherKey.value:
type: string
minLength: 5
maxLength: 50
yetAnotherKey.value:
type: date
format: YYYY-MM-DD
overwrite.yaml
)someKey.value:
type: number
length: 100