Skip to content

Commit

Permalink
fix: auto-formatting regression (#1117)
Browse files Browse the repository at this point in the history
Signed-off-by: Olzhas Alexandrov <[email protected]>
  • Loading branch information
o-alexandrov authored Dec 19, 2023
1 parent b889c88 commit 5ab74a3
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 267 deletions.
64 changes: 27 additions & 37 deletions samples/basic/api/endpoints/petstoreFromFileSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
* Swagger Petstore
* OpenAPI spec version: 1.0.0
*/
import axios from 'axios'
import type {
AxiosRequestConfig,
AxiosResponse
} from 'axios'
import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
export type CreatePetsBody = {
name: string;
tag: string;
};

export type ListPetsParams = {
/**
* How many items to return at one time (max 100)
*/
limit?: string;
/**
* How many items to return at one time (max 100)
*/
limit?: string;
};

export interface Error {
Expand All @@ -34,46 +31,39 @@ export interface Pet {

export type Pets = Pet[];





/**
/**
* @summary List all pets
*/
export const listPets = <TData = AxiosResponse<Pets>>(
params?: ListPetsParams, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets`,{
params?: ListPetsParams,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets`, {
...options,
params: {...params, ...options?.params},}
);
}
params: { ...params, ...options?.params },
});
};

/**
* @summary Create a pet
*/
export const createPets = <TData = AxiosResponse<void>>(
createPetsBody: CreatePetsBody, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.post(
`/pets`,
createPetsBody,options
);
}
createPetsBody: CreatePetsBody,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.post(`/pets`, createPetsBody, options);
};

/**
* @summary Info for a specific pet
*/
export const showPetById = <TData = AxiosResponse<Pet>>(
petId: string, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets/${petId}`,options
);
}
petId: string,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets/${petId}`, options);
};

export type ListPetsResult = AxiosResponse<Pets>
export type CreatePetsResult = AxiosResponse<void>
export type ShowPetByIdResult = AxiosResponse<Pet>
export type ListPetsResult = AxiosResponse<Pets>;
export type CreatePetsResult = AxiosResponse<void>;
export type ShowPetByIdResult = AxiosResponse<Pet>;
64 changes: 27 additions & 37 deletions samples/basic/api/endpoints/petstoreFromFileSpecWithConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
* Swagger Petstore
* OpenAPI spec version: 1.0.0
*/
import axios from 'axios'
import type {
AxiosRequestConfig,
AxiosResponse
} from 'axios'
import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
export type CreatePetsBody = {
name: string;
tag: string;
};

export type ListPetsParams = {
/**
* How many items to return at one time (max 100)
*/
limit?: string;
/**
* How many items to return at one time (max 100)
*/
limit?: string;
};

export interface Error {
Expand All @@ -34,46 +31,39 @@ export interface Pet {

export type Pets = Pet[];





/**
/**
* @summary List all pets
*/
export const listPets = <TData = AxiosResponse<Pets>>(
params?: ListPetsParams, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets`,{
params?: ListPetsParams,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets`, {
...options,
params: {...params, ...options?.params},}
);
}
params: { ...params, ...options?.params },
});
};

/**
* @summary Create a pet
*/
export const createPets = <TData = AxiosResponse<void>>(
createPetsBody: CreatePetsBody, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.post(
`/pets`,
createPetsBody,options
);
}
createPetsBody: CreatePetsBody,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.post(`/pets`, createPetsBody, options);
};

/**
* @summary Info for a specific pet
*/
export const showPetById = <TData = AxiosResponse<Pet>>(
petId: string, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets/${petId}`,options
);
}
petId: string,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets/${petId}`, options);
};

export type ListPetsResult = AxiosResponse<Pets>
export type CreatePetsResult = AxiosResponse<void>
export type ShowPetByIdResult = AxiosResponse<Pet>
export type ListPetsResult = AxiosResponse<Pets>;
export type CreatePetsResult = AxiosResponse<void>;
export type ShowPetByIdResult = AxiosResponse<Pet>;
168 changes: 73 additions & 95 deletions samples/basic/api/endpoints/petstoreFromFileSpecWithTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,119 +4,97 @@
* Swagger Petstore
* OpenAPI spec version: 1.0.0
*/
import axios from 'axios'
import type {
AxiosRequestConfig,
AxiosResponse
} from 'axios'
import type {
CreatePetsBody,
ListPetsParams,
Pet,
Pets
} from '../model'
import {
faker
} from '@faker-js/faker'
import {
HttpResponse,
delay,
http
} from 'msw'
import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
import type { CreatePetsBody, ListPetsParams, Pet, Pets } from '../model';
import { faker } from '@faker-js/faker';
import { HttpResponse, delay, http } from 'msw';
import listPetsMutator from '../mutator/response-type';




/**
/**
* @summary List all pets
*/
export const listPets = (
params?: ListPetsParams,
version: number = 1,
) => {
return listPetsMutator<Pets>(
{url: `/v${version}/pets`, method: 'GET',
params
},
);
}

export const listPets = (params?: ListPetsParams, version: number = 1) => {
return listPetsMutator<Pets>({
url: `/v${version}/pets`,
method: 'GET',
params,
});
};

/**
* @summary Create a pet
*/
export const createPets = <TData = AxiosResponse<void>>(
createPetsBody: CreatePetsBody,
version: number = 1, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.post(
`/v${version}/pets`,
createPetsBody,options
);
}
createPetsBody: CreatePetsBody,
version: number = 1,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.post(`/v${version}/pets`, createPetsBody, options);
};

/**
* @summary Info for a specific pet
*/
export const showPetById = <TData = AxiosResponse<Pet>>(
petId: string,
version: number = 1, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/v${version}/pets/${petId}`,options
);
}

petId: string,
version: number = 1,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/v${version}/pets/${petId}`, options);
};

type AwaitedInput<T> = PromiseLike<T> | T;

type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;

export type ListPetsResult = NonNullable<Awaited<ReturnType<typeof listPets>>>
export type CreatePetsResult = AxiosResponse<void>
export type ShowPetByIdResult = AxiosResponse<Pet>
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;

export type ListPetsResult = NonNullable<Awaited<ReturnType<typeof listPets>>>;
export type CreatePetsResult = AxiosResponse<void>;
export type ShowPetByIdResult = AxiosResponse<Pet>;

export const getListPetsMock = () => (Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({id: faker.number.int({min: undefined, max: undefined}), name: 'jon', tag: 'jon'})))
export const getListPetsMock = () =>
Array.from(
{ length: faker.number.int({ min: 1, max: 10 }) },
(_, i) => i + 1,
).map(() => ({
id: faker.number.int({ min: undefined, max: undefined }),
name: 'jon',
tag: 'jon',
}));

export const getShowPetByIdMock = () => ((() => ({
id: faker.number.int({ min: 1, max: 99 }),
name: faker.person.firstName(),
tag: faker.helpers.arrayElement([
faker.word.sample(),
void 0
])
}))())
export const getShowPetByIdMock = () =>
(() => ({
id: faker.number.int({ min: 1, max: 99 }),
name: faker.person.firstName(),
tag: faker.helpers.arrayElement([faker.word.sample(), void 0]),
}))();

export const getSwaggerPetstoreMock = () => [
http.get('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(JSON.stringify(getListPetsMock()),
{
status: 200,
headers: {
'Content-Type': 'application/json',
}
}
)
}),http.post('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(null,
{
status: 200,
headers: {
'Content-Type': 'application/json',
}
}
)
}),http.get('*/v:version/pets/:petId', async () => {
await delay(1000);
return new HttpResponse(JSON.stringify(getShowPetByIdMock()),
{
status: 200,
headers: {
'Content-Type': 'application/json',
}
}
)
}),]
http.get('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(JSON.stringify(getListPetsMock()), {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
}),
http.post('*/v:version/pets', async () => {
await delay(1000);
return new HttpResponse(null, {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
}),
http.get('*/v:version/pets/:petId', async () => {
await delay(1000);
return new HttpResponse(JSON.stringify(getShowPetByIdMock()), {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
}),
];
2 changes: 1 addition & 1 deletion samples/basic/api/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export * from './createPetsBody';
export * from './error';
export * from './listPetsParams';
export * from './pet';
export * from './pets';
export * from './pets';
Loading

0 comments on commit 5ab74a3

Please sign in to comment.