Reputation: 876
I have a yaml file like this:
type: object
properties:
transactionId:
x-faker: random.uuid
description: Transaction internal id
type: string
description:
x-faker: lorem.sentence
description: Transaction description
type: string
categoryId:
x-faker: random.number
description: Unique id of the category
type: integer
required:
- transactionId
- categoryId
I'm using the prism to mock the API response dynamically and it works fine. The only problem is, the categoryId
is a random number which I don't have any control over it. I want it to be a number between 1 and 10. According to the faker.js documentation, it is possible to use the min
and max
attributes to control the random generator but the x-faker
property doesn't support using those parameters. I need to use something like this:
x-faker: random.number({min:1, max:10})
Is there any way to do this?
Upvotes: 2
Views: 1959
Reputation: 673
I use prism (stoplight/prism-cli v5.12.0) to serve OpenApi v3.0 yaml file.
Here is structure for range from 10 to 20:
type: object
properties:
total:
type: 'integer'
example: 100
x-faker:
datatype.number: // random.number is depricated
min: 10
max: 20
Upvotes: 0
Reputation: 95
As Alison W said, it's best not to use faker for generating generic values like this. Faker produces specific values of a certain shape.
Use a generic library for generating random numbers instead.
Upvotes: 0
Reputation: 41
I've just come across the same issue, looks like doing something like random.number((1) + 9)
will solve the problem. This would give you a random number between 1 and 10.
Upvotes: 1