2

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?

Haukinger
  • 10,420
  • 2
  • 15
  • 28
S.Yavari
  • 876
  • 8
  • 25

2 Answers2

1

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.

Alison W
  • 41
  • 1
0

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.

Urthor
  • 95
  • 1
  • 8