GithubHelp home page GithubHelp logo

bobbyiliev / avro-mock-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ovotech/avro-mock-generator

1.0 1.0 0.0 248 KB

Generate random mock data from an Avro Schema

License: Apache License 2.0

JavaScript 1.36% TypeScript 98.64%

avro-mock-generator's Introduction

Avro Mock Generator

Create mock messages from Avro schemas.

Usage

Call the generator with the schema:

import generateMsg from '@ovotech/avro-mock-generator'

const schema = {
  type: 'record',
  fields: [{ name: 'nbChickens', type: 'int' }],
}
console.log(generateData(schema));

// { nbChickens: 25672672 }

All fields will contain randomly generated data that respects their type.

Options

An options object can optionnaly be provide as the second argument.

Supported Options:

  • generators: An key/value object of generator functions.
    • key: the type (or logicalType)
    • value: should be a generator function (type, context) => value where - type: the content of the type field in the schema, either a string for simple type, or the type configuration for complex types - context: an object with contextual data, including the generators It is possible to override the default generators, and add support for extra types/logicalTypes by providing
  • pickUnion: Array of strings to drive which member of union type to choose. Can be the short name of fully namespaced names. When this option is not provided, the first element in the union will be chosen

Reproducible generation

Use the Seeded factory to create a version of the generator that will use deterministic randomness.

The factory will return a function with the same signature as the default generator.

Supported Avro features

Based on the Avro 1.9.0 specification.

  • All primitive types
  • All logical types
    • including custom logicalTypes using the options parameter. If a logicalType is missing a generator, data will be generated matching the underlying type.
  • All complex types
    • Note that for enum types, the first element of the array will always be chosen.
  • Type Alias

Partial support for namespaces. Only union types are namespaced, unconditionally.

Contributing

All contributions are welcome, just fork the repository then create a PR. Once merged we will release a new version.

Releasing

Simply create a new release on master, with the tag being the new version (eg: 1.0.0).

avro-mock-generator's People

Contributors

mishabruml avatar nicolaslt avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.