swagger-mock-api icon indicating copy to clipboard operation
swagger-mock-api copied to clipboard

ability to use latest chance's helpers

Open Nilegfx opened this issue 8 years ago • 0 comments

not sure how (if it is exist) to use chance helpers like pickone

I tried

name:
        type: string
        x-chance-type: pickone
        x-type-value:
          - first
          - second

I think we it might need to upgrade chance version in this repo.

update I used pick with x-type-options and it worked.

I think for simplification, we can be consistent with how to pass options and value to chance method. even for fixed custom type we can ignore x-type-options and use the x-type-value

something like this here:

if (node['x-chance-type'] && !node['x-type-value'] ) {
    return chance[node['x-chance-type']](node['x-type-options']);
}

if (node['x-chance-type'] && node['x-type-value'] ) {
    return chance[node['x-chance-type']](node['x-type-value'], node['x-type-options']);
}

so I can do:

name:
        type: string
        x-chance-type: pick
        x-type-options: 2
        x-type-value:
          - first
          - second
          - third

then it should return two randomly picked items on the value array

Nilegfx avatar Jun 15 '17 10:06 Nilegfx