0.3.0 • Published 10 months ago

@web-bee-ru/msw-types v0.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

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

10 months ago

0.2.0

2 years ago

0.1.0

2 years ago