msw-auto-mock  by zoubingwu

CLI tool for generating mock data from OpenAPI definitions for MSW

created 3 years ago
355 stars

Top 79.7% on sourcepulse

GitHubView on GitHub
Project Summary

This CLI tool generates random mock data from OpenAPI definitions for Mock Service Worker (MSW). It automates the creation of response resolvers, saving developers from manual, repetitive coding. The tool supports both Faker.js and generative AI (OpenAI, Azure, Anthropic) for data generation, catering to teams needing efficient API mocking for frontend development and testing.

How It Works

The tool parses OpenAPI specifications (JSON or YAML) to understand API endpoints, request parameters, and response schemas. It then leverages either @faker-js/faker or configured AI providers to generate realistic mock data that conforms to these schemas. The output is a set of MSW request handlers, ready to be integrated into an application's service worker for intercepting network requests. The AI integration allows for more contextually relevant and potentially complex mock data generation.

Quick Start & Requirements

  • Install: yarn add msw-auto-mock @faker-js/faker -D
  • Generate mocks: npx msw-auto-mock <http_url_or_file_path> -o ./mock
  • MSW dependency: @faker-js/faker >= 8, msw >= 2.
  • AI providers require API keys and potentially specific environment variables (e.g., OPENAI_API_KEY).
  • Official docs: https://github.com/zoubingwu/msw-auto-mock

Highlighted Details

  • Supports generative AI (OpenAI, Azure, Anthropic) for mock data creation.
  • Generates mock data for browser, Node.js, and React Native environments.
  • Offers options for controlling array lengths, filtering endpoints, and specifying status codes.
  • Can generate static mocks or dynamic mocks based on OpenAPI definitions.

Maintenance & Community

The project appears to be actively maintained by a single author, zoubingwu. There are no explicit links to community channels like Discord or Slack provided in the README.

Licensing & Compatibility

The README does not explicitly state a license. However, the dependencies (@faker-js/faker and msw) are typically MIT licensed, suggesting potential MIT compatibility. Commercial use would require explicit license confirmation.

Limitations & Caveats

The AI integration requires careful configuration of API keys and environment variables, with potential costs associated with AI API usage. The README does not detail performance benchmarks or specific limitations regarding the complexity of OpenAPI schemas it can handle.

Health Check
Last commit

3 months ago

Responsiveness

Inactive

Pull Requests (30d)
1
Issues (30d)
0
Star History
22 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.