Forum Discussion

Stoplight's avatar
Stoplight
Community Manager
11 months ago
Solved

Is it possible to limit array lengths in Studio?

Originally posted by user timvanderlinden to the Stoplight Community on 10/28/2022 at 08:32 ET.

Hi all!

I'm getting my feet wet in mocking with importing OpenAPI docs from our services into Studio. So far so good, but I noticed that the dynamic mocks generates a high amount of elements in array types. I have tried various faker options to limit those amounts, but to no avail.

How should I limit the amount of items an array generates?

For example:

 HotspotImage:
      type: object
      properties:
        url:
          type: string
          format: uri
          x-faker: image.imageUrl
        title:
          type: string
        hotspots:
          type: array
          items:
            $ref: '#/components/schemas/Hotspot'
          x-faker:
            datatype.array:
              min: 1
              max: 3
      required:
        - hotspots
        - title
        - url

As you can se above I have attempted to limit the hotspots array to be random between 1 and 3, but without luck, they simply become empty instead of limited. It still generates about 15 items.