@web-bee-ru/msw-types
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

Библиотека для типизации моков msw при помощи схем taxios и openapi-typescript

Для msw@1 использовать версию 0.1.0

msw - Github, NPM

taxios - Github, NPM, Пример схем

openapi-typescript - Github, NPM, Пример схем

Примеры

taxios

import { HttpResponse, http } from "msw";
import { TypedHttp } from "@web-bee-ru/msw-types";
import { TaxiosTestApi } from "./data";

const typedHttp = new TypedHttp<TaxiosTestApi>(http, '/api');
typedHttp.get("/test1/{id}", async ({ request, params }) => {
  return HttpResponse.text("test");
});

openapi-typescript

import { HttpResponse, http } from "msw";
import { TypedOpenApiHttp } from "@web-bee-ru/msw-types";
import { TestOpenApi } from "./data";

const typedHttpOpenapi = new TypedOpenApiHttp<TestOpenApi>(http, '/api');
typedHttpOpenapi.get("/breeds/{id}", ({ request, params }) => {
  return HttpResponse.text("test");
});

taxios для msw@1 (версия @web-bee-ru/msw-types 0.1.0)

import { rest } from 'msw';
import { TypedRest } from "@web-bee-ru/msw-types"
import { IncidentsAPI } from './IncidentsAPI';

const incidentsRest = new TypedRest<IncidentsAPI>(rest, '/api');

incidentsRest.get('/v1/ui/{slxIds}', async (req, res, ctx) => {
    const params = req.params;
    return res(ctx.json({
    params
  }));
})

Readme

Keywords

Package Sidebar

Install

npm i @web-bee-ru/msw-types

Weekly Downloads

2

Version

0.3.0

License

ISC

Unpacked Size

72.4 kB

Total Files

35

Last publish

Collaborators

  • denwa799
  • simplesmiler
  • crutch12
  • gleam-ru
  • devirek