TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

Avro Mock Generator

Create mock messages from Avro schemas.


Call the generator with the schema:

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

const schema = {
  type: 'record',
  fields: [{ name: 'nbChickens', type: 'int' }],

// { nbChickens: 25672672 }

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


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.


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


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

Package Sidebar


npm i @ovotech/avro-mock-generator

Weekly Downloads






Unpacked Size

29.9 kB

Total Files


Last publish


  • ovox
  • oep-accounts-bot
  • ovo.backstage.admins
  • bookings-team
  • orion-bot
  • bizval-bot
  • oeptariffs
  • props
  • metering-reads-health-bot
  • ovotech-identity
  • paceteamkaluza
  • trading-and-dispatch
  • retail-payg-tech
  • accrecovo
  • ovo.trading.tech
  • qe-team
  • ovotech-smart-thermostat
  • rise-team
  • engagement-insights
  • myovo-self-serve-service-account
  • mars-rover
  • ape-team
  • kaluza-devex
  • ohs-aurora
  • kaluza-rnr
  • ipa-bot
  • kawbot
  • data.discovery.ovo
  • ovotech-sg
  • ovotech-qs
  • ovoenergyapps
  • homemoves
  • ovo-oot-bot
  • cp-ui-tooling
  • ovo-bit-tech
  • sir_hiss