Skip to content

web-bee-ru/msw-types

Repository files navigation

Библиотека для типизации моков 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

DEPRECATED: Используйте openapi-msw

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
  }));
})