npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

otdgen

v3.1.1

Published

The script outputs test data from the OpenApi schema file to the folder specified by the argument.

Downloads

19

Readme

otdgen: API Test Data Generator with OpenAI

otdgen is an open-source tool that generates JavaScript/TypeScript/Json test data from an OpenAPI schema file in YAML format. It provides two options for users:

Generate random test data from an OpenAPI schema file in YAML format Generate test data using OpenAI to generate text data for specific schema properties

Reporting Bugs/Feature Requests

tmizuma Open Bugs Feature Requests Closed Issues

Installation

Install otdgen via npm:

$ npm install otdgen

Usage

To use otdgen, you'll need an OpenAPI schema file in YAML format and an OpenAI API KEY.

$ mkdir output # create output folder for test data
$ otdgen generate -i example-openapi.yaml -o output/ -ai true -api-key <Your API_KEY>

Example file: example-openapi.yaml

//  This file was automatically generated and should not be edited.
export const employee = {
	id: '12345',
	companyId: 293093,
	role: 'MANAGER',
	name: 'John Doe',
	registdate: '2017-01-27 05:10:29',
	profile: {
		family_name: 'Smith',
		age: 33,
		address: '123 Main Street, Anytown, USA',
		birthdate: '2003-12-13',
		sex: 'MALE',
		hobby: ['Playing the guitar', 'Painting', 'Gardening']
	},
	department: {
		id: '12345',
		employee: 'Marketing'
	},
	submemners: [
		{
			id: '12345',
			name: 'John Doe'
		},
		{
			id: '67890',
			name: 'Jane Smith'
		},
		{
			id: 'abcde',
			name: 'Jack Johnson'
		}
	]
};
// employee is the same as employee_0
const employee0 = {
	id: '12345',
	companyId: 293093,
	role: 'MANAGER',
	name: 'John Doe',
	registdate: '2017-01-27 05:10:29',
	profile: {
		family_name: 'Smith',
		age: 33,
		address: '123 Main Street, Anytown, USA',
		birthdate: '2003-12-13',
		sex: 'MALE',
		hobby: ['Playing the guitar', 'Painting', 'Gardening']
	},
	department: {
		id: '12345',
		employee: 'Marketing'
	},
	submemners: [
		{
			id: '12345',
			name: 'John Doe'
		},
		{
			id: '67890',
			name: 'Jane Smith'
		},
		{
			id: 'abcde',
			name: 'Jack Johnson'
		}
	]
};
const employee1 = {
	id: '67890',
	companyId: 918270,
	role: 'ENGINEER',
	name: 'Jane Smith',
	registdate: '2021-02-08 06:33:25',
	profile: {
		family_name: 'Johnson',
		age: 20,
		address: '456 Maple Avenue, Anytown, USA',
		birthdate: '2020-02-28',
		sex: 'MALE',
		hobby: ['Playing the guitar', 'Painting', 'Gardening']
	},
	department: {
		id: '67890',
		employee: 'Human Resouce'
	},
	submemners: [
		{
			id: '12345',
			name: 'John Doe'
		},
		{
			id: '67890',
			name: 'Jane Smith'
		},
		{
			id: 'abcde',
			name: 'Jack Johnson'
		}
	]
};
const employee2 = {
	id: 'abcde',
	companyId: 943744,
	role: 'ASSISTANT',
	name: 'Jack Johnson',
	registdate: '2006-01-26 05:22:12',
	profile: {
		family_name: 'Williams',
		age: 33,
		address: '789 Oak Street, Anytown, USA',
		birthdate: '2008-03-25',
		sex: 'MALE',
		hobby: ['Playing the guitar', 'Painting', 'Gardening']
	},
	department: {
		id: 'abcde',
		employee: 'Development'
	},
	submemners: [
		{
			id: '12345',
			name: 'John Doe'
		},
		{
			id: '67890',
			name: 'Jane Smith'
		},
		{
			id: 'abcde',
			name: 'Jack Johnson'
		}
	]
};

export const employeeList = [employee0, employee1, employee2];
//  This file was automatically generated and should not be edited.
export const member = {
	id: '12345',
	name: 'John Doe'
};
// member is the same as member_0
const member0 = {
	id: '12345',
	name: 'John Doe'
};
const member1 = {
	id: '67890',
	name: 'Jane Smith'
};
const member2 = {
	id: 'abcde',
	name: 'Jack Johnson'
};

export const memberList = [member0, member1, member2];
//  This file was automatically generated and should not be edited.
export const profile = {
	family_name: 'Smith',
	age: 38,
	address: '123 Main Street, Anytown, USA',
	birthdate: '2002-07-23',
	sex: 'MALE',
	hobby: ['Playing the guitar', 'Painting', 'Gardening']
};
// profile is the same as profile_0
const profile0 = {
	family_name: 'Smith',
	age: 38,
	address: '123 Main Street, Anytown, USA',
	birthdate: '2002-07-23',
	sex: 'MALE',
	hobby: ['Playing the guitar', 'Painting', 'Gardening']
};
const profile1 = {
	family_name: 'Johnson',
	age: 28,
	address: '456 Maple Avenue, Anytown, USA',
	birthdate: '2015-07-26',
	sex: 'FEMALE',
	hobby: ['Playing the guitar', 'Painting', 'Gardening']
};
const profile2 = {
	family_name: 'Williams',
	age: 43,
	address: '789 Oak Street, Anytown, USA',
	birthdate: '2000-10-07',
	sex: 'ELSE',
	hobby: ['Playing the guitar', 'Painting', 'Gardening']
};

export const profileList = [profile0, profile1, profile2];

In this example, AI generates test data for the five properties [id,name,family_name,address,hobby]. It's important to note that OpenAI generates test data only for string types. Otherwise, otdgen generates random values from the attribute values (e.g., minimum, maximum, enum) specified in each schema.

export const profile = {
	family_name: 'Smith', // generated by OpenAI!!
	age: 38, // random value between minimum and maximum
	address: '123 Main Street, Anytown, USA', // generated by OpenAI!!
	birthdate: '2002-07-23', // random value
	hobby: ['Playing the guitar', 'Painting', 'Gardening'] // generated by OpenAI!!
};

otdgen generates test data in the output/ folder. If the -ai option is not specified, otdgen generates random test data.

# generate test data randomly without OpenAI
$ otdgen generate -i example-openapi.yaml -o output/

Options

| Options | Description | Default | Required | | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------: | :------: | | -i, --input <file path> | The path to the OpenAPI schema file in YAML format | - | ● | | -o, --output <output folder path> | The output folder for test data folder | - | ● | | -n, --number-of-array-data <test data size> | The size of the test data. This option is limited to a maximum of 10 cases when using the -ai true option. | 3 | - | | -ext, --extension <output file extension> | The output file extension: .ts,.js or .json. | .ts | - | | -ignore, --ignore <ignore schema list> | A list of schemas that should not generate test data. Please specify comma-separated values. For example: -ignore Employee,Profile | - | - | | -s, --stateless <true | false> | Setting this option to true ensures that the generated test data is reproducible and has the same values across multiple test runs. This option is strongly recommended when using unit or snapshot tests. Please note that this option is disabled when using the -ai option. | true (if -ai is not specified or false) | - | | -ai, --ai | This option enables the OpenAI feature, which generates appropriate test data from the schema property names such as hobby, company name, and family name. Please note that you need to provide an API key if you use this option. | false | - | | -api-key, --api-key | If you use the -ai option, you must provide your OpenAI API key here. | false | - | | -avoid-ai, --avoid-ai | This option can be specified when the -ai option is true. When using the OpenAI feature, some property names may cause errors. In that case, you can use this option to disable specific properties. For example: -avoid-ai hobby,company_name | false | - | | -es, --example-suffix <true | false> | This option controls whether or not to add the suffix to the test data if the example attribute exists in the YAML file. If this option is true, the -ai option is ignored. | true (if -ai is not specified or false) | - |

Contributor

Please contact me! Twitter: https://twitter.com/mizuma_t