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

@jtgober/playwright-service-generator

v1.1.1

Published

Generates Playwright API services from Swagger/OpenAPI specifications

Readme

Playwright Service Generator

Generate Playwright API service classes from your OpenAPI specification.
This package converts your API endpoints into clean, camelCase methods.

🚀 Features

  • 🛠 Generates Playwright service classes directly from an OpenAPI spec
  • 🐫 Creates clean camelCase method names (getUsersById, postOrders)
  • 🧩 Automatically generates custom Playwright fixtures for each service, so you can inject them directly into your tests
  • ⚡ Works seamlessly with Playwright’s built-in request fixture

📦 Installation

npm install @jtgober/playwright-service-generator

📖 Usage

  1. Generate services from your OpenAPI spec
npx generate-services  --swaggerUrl YOUR-SWAGGER-JSON
# or alias
npx generate-services  --s YOUR-SWAGGER-JSON
  1. Example generated service

Given this swagger.json:

https://fakerestapi.azurewebsites.net/swagger/v1/swagger.json

You’ll get a services like:

//services/ActivitiesService.ts
import { APIRequestContext } from '@playwright/test';

export class ActivitiesService {

  private request: APIRequestContext;

  constructor(request: APIRequestContext) {
    this.request = request;
  }

  async getActivities() {
    const res = this.request.get(`/api/v1/Activities`);
    return res;
  }

  async postActivities(data?: any) {
    const res = this.request.post(`/api/v1/Activities`, { data });
    return res;
  }

  async getActivitiesById(id) {
    const res = this.request.get(`/api/v1/Activities/${id}`);
    return res;
  }

  async putActivitiesById(id, data?: any) {
    const res = this.request.put(`/api/v1/Activities/${id}`, { data });
    return res;
  }

  async deleteActivitiesById(id) {
    const res = this.request.delete(`/api/v1/Activities/${id}`);
    return res;
  }
}
  1. They are also added as custom fixtures - creating a base.ts class
//base.ts
import { test as base } from '@playwright/test';
import { ActivitiesService } from '../services/ActivitiesService.js';
import { AuthorsService } from '../services/AuthorsService.js';
 //... all other imports

type MyFixtures = {
  activitiesService: ActivitiesService;
  authorsService: AuthorsService;
 //... all other typed fixtures
};

export const test = base.extend<MyFixtures>({
  activitiesService: async ({ request }, use) => {
    const service = new ActivitiesService(request);
    await use(service);
  },
  authorsService: async ({ request }, use) => {
    const service = new AuthorsService(request);
    await use(service);
  },
  //... all other services
});

export { expect } from '@playwright/test';
  1. Tests can now use any fixture
//my-test.spec.ts
import { test, expect } from './base';

test('Sample test to verify setup', async ({ usersService }) => {
    const response = await usersService.getUsers();
    expect(response.status()).toBe(200);
});

Additional Option: output-dir

You can specify where you want your services to go by using

--output-dir MY-SERVICES-FOLDER
## or alias
--o MY-SERVICES-FOLDER

Example:

npx generate-services  --s https://fakerestapi.azurewebsites.net/swagger/v1/swagger.json --o new/folder/location

Additional Option: merge

When working with APIs that have multiple versions (v1, v2, etc.), you can use the merge option to preserve existing service files and create versioned service names.

--merge
## or alias
-m

Without merge (default behavior):

  • Routes like /v1/users and /v2/users both create UsersService
  • Later versions overwrite earlier ones
  • Only the last version's service file remains

With merge:

  • Routes like /v1/users create UsersV1Service
  • Routes like /v2/users create UsersV2Service
  • Routes without versions (like /orders) create OrdersService
  • All service files are preserved
  • Existing base.ts file is preserved and updated with new services

Example:

npx generate-services --s https://api.example.com/swagger.json --m

This is particularly useful when:

  • Your API has multiple versions you want to test
  • You have existing service files you don't want to overwrite
  • You want to maintain backward compatibility with older API versions