@tcorley/pdsc-mock-generator v0.0.2
PDSC Mock Generator
Create mock messages from PDSC schemas.
Usage
Call the generator with the schema:
import generateMsg from '@tcorley/pdsc-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: Ankey/valueobject of generator functions.key: thetype(orlogicalType)value: should be a generator function(type, context) => valuewhere -type: the content of thetypefield in the schema, either astringfor simple type, or the type configuration for complex types -context: an object with contextual data, including thegeneratorsIt 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 PDSC features
This package was forked from @ovotech/avro-mock-generagtor to support PDSC Syntax
The original package was based on the Avro 1.9.0 specification.
- All primitive types
- All logical types
- including custom logicalTypes using the
optionsparameter. If alogicalTypeis missing a generator, data will be generated matching the underlyingtype.
- including custom logicalTypes using the
- All complex types
- Note that for
enumtypes, the first element of the array will always be chosen.
- Note that for
- Type Alias
Partial support for namespaces. Only union types are namespaced, unconditionally.
This package also includes support for Unions with Aliases
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).