danibram / mocker-data-generator

A simplified way to generate masive mock data based on a schema, you can use the awesome fake/random data generators like (FakerJs, ChanceJs, CasualJs and RandExpJs)
https://danibram.github.io/mocker-data-generator/
MIT License
426 stars 45 forks source link

Nested Attribute support #87

Closed faboulaws closed 5 years ago

faboulaws commented 5 years ago

There is no example of nested attributes. For example, if I want to create a mock an entity with the structure below

const article = {
    title: '...',
    seo: {
          title: "...",
          description: ""
    }
};

I need to create 2 entities

const articleSchema = {
    title: {
        chance: 'word'
   },
  seo: {
        hasOne: 'seo'
 }
};

const seoSchema = {
     title: {
        chance: 'word'
     },
    description: {
        chance: 'word'
    },
};

mocker().schema('article',articleSchema, 1)
.schema('seo',seoSchema, 1)

Am I missing something or this is the best way to generate nested properties.

danibram commented 5 years ago

Hi, You can use simply 1:

const articleSchema = {
    title: {
        chance: 'word'
    },
    seo: {
        title: {
            chance: 'word'
        },
        description: {
            chance: 'word'
        }
    }
};

mocker().schema('article',articleSchema, 1)

You can test here the result, also you can use 2 entities if you need to share between more schemas. Thanks for using mocker-data-generator!

faboulaws commented 5 years ago

Thanks for the quick response :-)