Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use random value from examples instead of generating fake data #2

Open
sspat opened this issue Jul 19, 2018 · 2 comments
Open

Use random value from examples instead of generating fake data #2

sspat opened this issue Jul 19, 2018 · 2 comments

Comments

@sspat
Copy link

sspat commented Jul 19, 2018

Hi! Awesome plugin, appreciate your work!

It would be great to have the next feature:
If there are any examples specified, the plugin could randomly take a value from the examples, instead of generating fake data.
That would give more control of the generated data and create more relevant examples.

Right now, using the following schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "city": {
      "type": "string",
      "examples": [
        "Moscow"
      ]
    }
  },
  "required": [
    "city"
  ]
}

The plugin generates a success example like this:

{
    "city": "eiusmod dolor"
}

It would be great, if it could generate instead this:

{
    "city": "Moscow"
}

So i can provide examples where they are relevant and leave other fields for random fake data generation.

@Arxcis
Copy link

Arxcis commented Mar 21, 2019

Have you considered using the 'pattern'-property to achieve your goal?

Example:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "city": {
      "type": "string",
      "pattern": "Moscow|Brussels|Oslo|Stockholm|Copenhagen|London"
    }
  },
  "required": [
    "city"
  ]
}

Check that it works here -> https://json-schema-faker.js.org

@Arxcis
Copy link

Arxcis commented Mar 21, 2019

@sspat Maybe the chance or faker-property already supports this?

{
  "type": "object",
  "properties": {
    "food": {
      "type": "string",
      "chance": {
        "pickone": [
          [
            "banana",
            "apple",
            "orange"
          ]
        ]
      }
    }
  },
  "required": [
    "food"
  ]
}

I haven't tried it but it is described here: https://github.com/json-schema-faker/json-schema-faker/blob/master/docs/USAGE.md#user-content-advanced-usage-of-fakerjs-and-chancejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants