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 🙏

© 2026 – Pkg Stats / Ryan Hefner

swagger-to-playwright-api-clients

v1.0.21

Published

Generate TypeScript API clients from Swagger/OpenAPI specifications for Playwright testing

Readme

swagger-to-playwright-api-clients

Generate TypeScript API clients from Swagger/OpenAPI specifications for Playwright testing.

Installation

npm install swagger-to-playwright-api-clients

Quick Start

1. Initialize Configuration

npx swagger-to-playwright init

This creates a generator-config.ts file in your project root.

2. Configure Your Sources

Edit generator-config.ts:

import type { AutomationConfig } from 'swagger-to-playwright-api-clients';
import * as path from 'path';

const config: AutomationConfig = {
	// Output directory for generated clients
	outputDir: path.join(__dirname, 'src/clients'),

	// Clean output before generation
	cleanOutput: true,

	// Process sources in parallel
	parallel: false,

	// BaseAPIClient import path (optional - defaults to '../../../BaseAPIClient')
	// Generated clients are at: outputDir/generatedClients/ServiceName/FolderName/
	// The library will auto-copy BaseAPIClient.ts to your outputDir
	// baseClientPath: '../../../BaseAPIClient',

	// Swagger/OpenAPI sources
	sources: [
		{
			type: 'file',
			source: './swagger/api.json',
			serviceName: 'MyService',
		},
		{
			type: 'url',
			source: 'https://api.example.com/swagger.json',
			serviceName: 'ExampleService',
		},
	],
};

export default config;

3. Generate Clients

npx swagger-to-playwright

CLI Usage

# Generate from config file
npx swagger-to-playwright

# Generate from specific config
npx swagger-to-playwright --config ./my-config.ts

# Generate from single file
npx swagger-to-playwright --file ./swagger.json --output ./src/clients

# Generate from URL
npx swagger-to-playwright --url https://api.example.com/swagger.json --output ./src/clients

# Show help
npx swagger-to-playwright --help

# Initialize a new config file
npx swagger-to-playwright init

Programmatic Usage

import { generate, generateFromConfig } from 'swagger-to-playwright-api-clients';

// Generate from a single source
const result = await generate({
	source: './swagger.json',
	type: 'file',
	outputDir: './src/clients',
	serviceName: 'MyService',
});

// Generate from config object
const results = await generateFromConfig({
	outputDir: './src/clients',
	sources: [{ type: 'file', source: './swagger.json', serviceName: 'MyService' }],
});

Using Generated Clients

import { test, expect } from '@playwright/test';
import { BaseAPIClient } from './clients/BaseAPIClient';
import { MyServiceActivityClient } from './clients/generatedClients/MyService/Activity/MyServiceActivityClient';

test('API test example', async () => {
	const baseClient = new BaseAPIClient('https://api.example.com', {
		'Content-Type': 'application/json',
		Authorization: 'Bearer your-token',
	});
	await baseClient.init();

	const activityClient = new MyServiceActivityClient(baseClient);

	const { body, status } = await activityClient.getActivities();

	expect(status).toBe(200);
	expect(body.activities).toBeDefined();

	await baseClient.dispose();
});

With Request/Response Logging

import { getLogger, configureLogger } from 'swagger-to-playwright-api-clients';
import { BaseAPIClient } from './clients/BaseAPIClient';

// Configure logger (optional - uses defaults if not called)
configureLogger({
	level: 'debug',
	console: true,
	file: false,
});

// Pass logger to BaseAPIClient for request/response logging
const baseClient = new BaseAPIClient(
	'https://api.example.com',
	{ 'Content-Type': 'application/json' },
	getLogger() // Winston logger instance
);

Configuration Options

| Option | Type | Default | Description | | ---------------- | --------------------- | -------------------------- | ------------------------------------ | | outputDir | string | required | Output directory for generated files | | sources | SwaggerSourceConfig[] | required | Array of swagger sources | | baseClientPath | string | '../../../BaseAPIClient' | Custom path to BaseAPIClient | | copyBaseClient | boolean | true | Copy BaseAPIClient to output | | cleanOutput | boolean | true | Clean output before generation | | parallel | boolean | false | Process sources in parallel | | logger | LoggerConfig | see below | Logger configuration |

Logger Configuration

Configure logging for the generation process:

const config: AutomationConfig = {
	// ... other options
	logger: {
		level: 'info', // 'error' | 'warn' | 'info' | 'debug' | 'verbose'
		outputDir: './logs', // Log file output directory
		console: true, // Print logs to console
		file: true, // Write logs to file
	},
};

Generated Structure

src/clients/
├── BaseAPIClient.ts           # Base client (auto-copied)
└── generatedClients/
    └── MyService/
        ├── Activity/
        │   ├── types.ts
        │   └── MyServiceActivityClient.ts
        ├── Users/
        │   ├── types.ts
        │   └── MyServiceUsersClient.ts
        └── Root/
            ├── types.ts
            └── MyServiceRootClient.ts

Peer Dependencies

This library requires Playwright to be installed in your project:

npm install @playwright/test playwright

License

MIT