bentonam / fakeit

Generates JSON documents based on models defined in YAML and adds them to a Couchbase Bucket
MIT License
86 stars 21 forks source link

Definitions within Definitions #66

Closed mistersender closed 7 years ago

mistersender commented 7 years ago

It would be great to be able to use definitions from within other definitions. I have some extremely complex data models that would benefit from being able to break definitions down more, but it doesn't appear that one can use a definition from inside of another. I attached a simple yaml file that demonstrates this-- email can be included from the primary document, but not from within the contacts definition (returns null).

name: Test
type: object
key: _id
data:
  dependencies:
properties:
  _id:
    type: string
    data:
      build: "return 'test-' + chance.guid();"
  emails:
    type: array
    description: An array of emails for the user
    items:
      $ref: '#/definitions/Email'
      data:
        min: 1
        max: 3
  contact:
    type: array
    description: An array of contact info for the user
    items:
      $ref: '#/definitions/Contact'
      data:
        min: 1
        max: 3
  name:
    type: string
    data:
      value: "Some name"
definitions:
  Email:
    type: object
    properties:
      type:
        type: string
        description: The phone type
        data:
          build: "return faker.random.arrayElement(globals.email_types);"
      email_address:
        type: string
        description: The email address
        data:
          build: "return faker.internet.email()"
      primary:
        type: boolean
        description: If the email address is the primary email address or not
        data:
          value: false
  Contact:
    type: object
    properties:
      address:
        type: "string"
        data:
          value: "123 test st"
      emails:
        type: array
        description: An array of emails for the user
        items:
          $ref: '#/definitions/Email'
          data:
            min: 1
            max: 3