Skip to content

Commit 69a2712

Browse files
committed
Update snapshots further
1 parent 71eb9c5 commit 69a2712

File tree

6 files changed

+112
-92
lines changed

6 files changed

+112
-92
lines changed

packages/rtk-query-codegen-openapi/src/generate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export async function generateApi(
134134
if (apiFile.startsWith('.')) {
135135
apiFile = path.relative(path.dirname(outputFile), apiFile);
136136
apiFile = apiFile.replace(/\\/g, '/');
137-
if (!apiFile.startsWith('.')) apiFile = './' + apiFile;
137+
if (!apiFile.startsWith('.')) apiFile = `./${apiFile}`;
138138
}
139139
}
140140
apiFile = apiFile.replace(/\.[jt]sx?$/, '');
@@ -189,7 +189,7 @@ export async function generateApi(
189189
);
190190

191191
function extractAllTagTypes({ operationDefinitions }: { operationDefinitions: OperationDefinition[] }) {
192-
let allTagTypes = new Set<string>();
192+
const allTagTypes = new Set<string>();
193193

194194
for (const operationDefinition of operationDefinitions) {
195195
const { verb, pathItem } = operationDefinition;
@@ -278,7 +278,7 @@ export async function generateApi(
278278
}
279279
// if there are still any naming conflicts, prepend with underscore
280280
while (name in queryArg) {
281-
name = '_' + name;
281+
name = `_${name}`;
282282
}
283283
return name;
284284
}

packages/rtk-query-codegen-openapi/test/__snapshots__/cli.test.ts.snap

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`CLI options testing generation with \`config.example.js\` 1`] = `
4-
import { api } from '../fixtures/emptyApi';
3+
exports[`CLI options testing > generation with \`config.example.js\` 1`] = `
4+
"import { api } from '../fixtures/emptyApi';
55
const injectedRtkApi = api.injectEndpoints({
66
endpoints: (build) => ({
77
updatePet: build.mutation<UpdatePetApiResponse, UpdatePetApiArg>({
@@ -192,7 +192,7 @@ export type Pet = {
192192
category?: Category;
193193
photoUrls: string[];
194194
tags?: Tag[];
195-
status?: 'available' | 'pending' | 'sold';
195+
status?: Status;
196196
};
197197
export type ApiResponse = {
198198
code?: number;
@@ -204,7 +204,7 @@ export type Order = {
204204
petId?: number;
205205
quantity?: number;
206206
shipDate?: string;
207-
status?: 'placed' | 'approved' | 'delivered';
207+
status?: Status2;
208208
complete?: boolean;
209209
};
210210
export type User = {
@@ -217,11 +217,21 @@ export type User = {
217217
phone?: string;
218218
userStatus?: number;
219219
};
220-
220+
export enum Status {
221+
Available = 'available',
222+
Pending = 'pending',
223+
Sold = 'sold',
224+
}
225+
export enum Status2 {
226+
Placed = 'placed',
227+
Approved = 'approved',
228+
Delivered = 'delivered',
229+
}
230+
"
221231
`;
222232
223-
exports[`CLI options testing paths are relative to configfile, not to cwd 1`] = `
224-
import { api } from '../fixtures/emptyApi';
233+
exports[`CLI options testing > paths are relative to configfile, not to cwd 1`] = `
234+
"import { api } from '../fixtures/emptyApi';
225235
const injectedRtkApi = api.injectEndpoints({
226236
endpoints: (build) => ({
227237
updatePet: build.mutation<UpdatePetApiResponse, UpdatePetApiArg>({
@@ -412,7 +422,7 @@ export type Pet = {
412422
category?: Category;
413423
photoUrls: string[];
414424
tags?: Tag[];
415-
status?: 'available' | 'pending' | 'sold';
425+
status?: Status;
416426
};
417427
export type ApiResponse = {
418428
code?: number;
@@ -424,7 +434,7 @@ export type Order = {
424434
petId?: number;
425435
quantity?: number;
426436
shipDate?: string;
427-
status?: 'placed' | 'approved' | 'delivered';
437+
status?: Status2;
428438
complete?: boolean;
429439
};
430440
export type User = {
@@ -437,5 +447,15 @@ export type User = {
437447
phone?: string;
438448
userStatus?: number;
439449
};
440-
450+
export enum Status {
451+
Available = 'available',
452+
Pending = 'pending',
453+
Sold = 'sold',
454+
}
455+
export enum Status2 {
456+
Placed = 'placed',
457+
Approved = 'approved',
458+
Delivered = 'delivered',
459+
}
460+
"
441461
`;

packages/rtk-query-codegen-openapi/test/__snapshots__/generateEndpoints.test.ts.snap

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`calling without \`outputFile\` returns the generated api 1`] = `
4-
import { api } from "./fixtures/emptyApi";
4+
"import { api } from "./fixtures/emptyApi";
55
const injectedRtkApi = api.injectEndpoints({
66
endpoints: (build) => ({
77
getHealthcheck: build.query<
@@ -283,11 +283,11 @@ export type User = {
283283
phone?: string | undefined;
284284
userStatus?: number | undefined;
285285
};
286-
286+
"
287287
`;
288288

289289
exports[`duplicate parameter names must be prefixed with a path or query prefix 1`] = `
290-
import { api } from "./fixtures/emptyApi";
290+
"import { api } from "./fixtures/emptyApi";
291291
const injectedRtkApi = api.injectEndpoints({
292292
endpoints: (build) => ({
293293
patchApiV1ListByItemId: build.mutation<
@@ -324,11 +324,11 @@ export type PatchApiV2BySomeNameApiArg = {
324324
pathSomeName: string;
325325
querySomeName: string;
326326
};
327-
327+
"
328328
`;
329329

330330
exports[`endpoint filtering > should only have endpoints loginUser, placeOrder, getOrderById, deleteOrder 1`] = `
331-
import { api } from "./fixtures/emptyApi";
331+
"import { api } from "./fixtures/emptyApi";
332332
const injectedRtkApi = api.injectEndpoints({
333333
endpoints: (build) => ({
334334
placeOrder: build.mutation<PlaceOrderApiResponse, PlaceOrderApiArg>({
@@ -389,11 +389,11 @@ export type Order = {
389389
status?: ("placed" | "approved" | "delivered") | undefined;
390390
complete?: boolean | undefined;
391391
};
392-
392+
"
393393
`;
394394

395395
exports[`endpoint overrides > loginUser should be a mutation 1`] = `
396-
import { api } from "./fixtures/emptyApi";
396+
"import { api } from "./fixtures/emptyApi";
397397
const injectedRtkApi = api.injectEndpoints({
398398
endpoints: (build) => ({
399399
loginUser: build.mutation<LoginUserApiResponse, LoginUserApiArg>({
@@ -415,11 +415,11 @@ export type LoginUserApiArg = {
415415
/** The password for login in clear text */
416416
password?: string;
417417
};
418-
418+
"
419419
`;
420420

421421
exports[`falls back to the \`title\` parameter for the body parameter name when no other name is available 1`] = `
422-
import { api } from "fixtures/emptyApi";
422+
"import { api } from "fixtures/emptyApi";
423423
const injectedRtkApi = api.injectEndpoints({
424424
endpoints: (build) => ({
425425
postV1Export: build.mutation<PostV1ExportApiResponse, PostV1ExportApiArg>({
@@ -449,11 +449,11 @@ export type PostV1ImportApiArg = {
449449
rawData: string;
450450
};
451451
export type IdList = number[];
452-
452+
"
453453
`;
454454

455455
exports[`hooks generation > should generate an \`useGetPetByIdQuery\` query hook and an \`useAddPetMutation\` mutation hook 1`] = `
456-
import { api } from "./fixtures/emptyApi";
456+
"import { api } from "./fixtures/emptyApi";
457457
const injectedRtkApi = api.injectEndpoints({
458458
endpoints: (build) => ({
459459
addPet: build.mutation<AddPetApiResponse, AddPetApiArg>({
@@ -497,11 +497,11 @@ export type Pet = {
497497
status?: ("available" | "pending" | "sold") | undefined;
498498
};
499499
export const { useAddPetMutation, useGetPetByIdQuery } = injectedRtkApi;
500-
500+
"
501501
`;
502502

503503
exports[`hooks generation uses overrides > should generate an \`useLoginMutation\` mutation hook 1`] = `
504-
import { api } from "./fixtures/emptyApi";
504+
"import { api } from "./fixtures/emptyApi";
505505
const injectedRtkApi = api.injectEndpoints({
506506
endpoints: (build) => ({
507507
loginUser: build.mutation<LoginUserApiResponse, LoginUserApiArg>({
@@ -524,11 +524,11 @@ export type LoginUserApiArg = {
524524
password?: string;
525525
};
526526
export const { useLoginUserMutation } = injectedRtkApi;
527-
527+
"
528528
`;
529529

530530
exports[`openapi spec > readOnly / writeOnly are merged 1`] = `
531-
import { api } from "./fixtures/emptyApi";
531+
"import { api } from "./fixtures/emptyApi";
532532
const injectedRtkApi = api.injectEndpoints({
533533
endpoints: (build) => ({
534534
getExample: build.query<GetExampleApiResponse, GetExampleApiArg>({
@@ -556,11 +556,11 @@ export type ExampleSchema = {
556556
read_only_prop: string;
557557
write_only_prop: string;
558558
};
559-
559+
"
560560
`;
561561

562562
exports[`openapi spec > readOnly / writeOnly are respected 1`] = `
563-
import { api } from "./fixtures/emptyApi";
563+
"import { api } from "./fixtures/emptyApi";
564564
const injectedRtkApi = api.injectEndpoints({
565565
endpoints: (build) => ({
566566
getExample: build.query<GetExampleApiResponse, GetExampleApiArg>({
@@ -594,11 +594,11 @@ export type ExampleSchemaWrite = {
594594
always_present: string;
595595
write_only_prop: string;
596596
};
597-
597+
"
598598
`;
599599

600600
exports[`should use brackets in a querystring urls arg, when the arg contains full stops 1`] = `
601-
import { api } from "./fixtures/emptyApi";
601+
"import { api } from "./fixtures/emptyApi";
602602
const injectedRtkApi = api.injectEndpoints({
603603
endpoints: (build) => ({
604604
patchApiV1ListByItemId: build.mutation<
@@ -635,11 +635,11 @@ export type PatchApiV2BySomeNameApiArg = {
635635
pathSomeName: string;
636636
querySomeName: string;
637637
};
638-
638+
"
639639
`;
640640

641641
exports[`supports granular hooks generation that includes all query types 1`] = `
642-
import { api } from "./fixtures/emptyApi";
642+
"import { api } from "./fixtures/emptyApi";
643643
const injectedRtkApi = api.injectEndpoints({
644644
endpoints: (build) => ({
645645
addPet: build.mutation<AddPetApiResponse, AddPetApiArg>({
@@ -684,11 +684,11 @@ export type Pet = {
684684
};
685685
export const { useAddPetMutation, useGetPetByIdQuery, useLazyGetPetByIdQuery } =
686686
injectedRtkApi;
687-
687+
"
688688
`;
689689

690690
exports[`supports granular hooks generation with only lazy queries 1`] = `
691-
import { api } from "./fixtures/emptyApi";
691+
"import { api } from "./fixtures/emptyApi";
692692
const injectedRtkApi = api.injectEndpoints({
693693
endpoints: (build) => ({
694694
addPet: build.mutation<AddPetApiResponse, AddPetApiArg>({
@@ -732,11 +732,11 @@ export type Pet = {
732732
status?: "available" | "pending" | "sold";
733733
};
734734
export const { useLazyGetPetByIdQuery } = injectedRtkApi;
735-
735+
"
736736
`;
737737

738738
exports[`supports granular hooks generation with only mutations 1`] = `
739-
import { api } from "./fixtures/emptyApi";
739+
"import { api } from "./fixtures/emptyApi";
740740
const injectedRtkApi = api.injectEndpoints({
741741
endpoints: (build) => ({
742742
addPet: build.mutation<AddPetApiResponse, AddPetApiArg>({
@@ -780,11 +780,11 @@ export type Pet = {
780780
status?: "available" | "pending" | "sold";
781781
};
782782
export const { useAddPetMutation } = injectedRtkApi;
783-
783+
"
784784
`;
785785

786786
exports[`supports granular hooks generation with only queries 1`] = `
787-
import { api } from "./fixtures/emptyApi";
787+
"import { api } from "./fixtures/emptyApi";
788788
const injectedRtkApi = api.injectEndpoints({
789789
endpoints: (build) => ({
790790
addPet: build.mutation<AddPetApiResponse, AddPetApiArg>({
@@ -828,11 +828,11 @@ export type Pet = {
828828
status?: "available" | "pending" | "sold";
829829
};
830830
export const { useGetPetByIdQuery } = injectedRtkApi;
831-
831+
"
832832
`;
833833

834834
exports[`tests from issues > issue #2002: should be able to generate proper intersection types 1`] = `
835-
import { api } from "./tmp/emptyApi";
835+
"import { api } from "./tmp/emptyApi";
836836
const injectedRtkApi = api.injectEndpoints({
837837
endpoints: (build) => ({
838838
getApiV1Animals: build.query<
@@ -872,11 +872,11 @@ export type Cat = {
872872
catUniqueProp?: string | null;
873873
};
874874
export const { useGetApiV1AnimalsQuery } = injectedRtkApi;
875-
875+
"
876876
`;
877877

878878
exports[`yaml parsing > should be able to use read a yaml file 1`] = `
879-
import { api } from "./tmp/emptyApi";
879+
"import { api } from "./tmp/emptyApi";
880880
export const addTagTypes = ["pet", "store", "user"] as const;
881881
const injectedRtkApi = api
882882
.enhanceEndpoints({
@@ -1199,11 +1199,11 @@ export const {
11991199
useUpdateUserMutation,
12001200
useDeleteUserMutation,
12011201
} = injectedRtkApi;
1202-
1202+
"
12031203
`;
12041204

12051205
exports[`yaml parsing > should generate params with non quoted keys if they don't contain special characters 1`] = `
1206-
import { api } from "./tmp/emptyApi";
1206+
"import { api } from "./tmp/emptyApi";
12071207
export const addTagTypes = ["StructureDefinition"] as const;
12081208
const injectedRtkApi = api
12091209
.enhanceEndpoints({
@@ -1256,11 +1256,11 @@ export type GetStructureDefinitionApiArg = {
12561256
};
12571257
export type FhirJsonResource = object;
12581258
export const { useGetStructureDefinitionQuery } = injectedRtkApi;
1259-
1259+
"
12601260
`;
12611261

12621262
exports[`yaml parsing > should parse a yaml schema from a URL 1`] = `
1263-
import { api } from "./tmp/emptyApi";
1263+
"import { api } from "./tmp/emptyApi";
12641264
export const addTagTypes = ["pet", "store", "user"] as const;
12651265
const injectedRtkApi = api
12661266
.enhanceEndpoints({
@@ -1583,5 +1583,5 @@ export const {
15831583
useUpdateUserMutation,
15841584
useDeleteUserMutation,
15851585
} = injectedRtkApi;
1586-
1586+
"
15871587
`;

packages/rtk-query-codegen-openapi/test/cli.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ function cli(args: string[], cwd: string): Promise<{ error: ExecException | null
2323

2424
const tmpDir = path.resolve(__dirname, 'tmp');
2525

26-
beforeAll(async () => {
27-
if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir, { recursive: true });
28-
});
26+
describe('CLI options testing', () => {
27+
beforeAll(async () => {
28+
if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir, { recursive: true });
29+
});
2930

30-
afterEach(() => {
31-
del.sync(`${tmpDir}/*.ts`);
32-
});
31+
afterEach(() => {
32+
del.sync(`${tmpDir}/*.ts`);
33+
});
3334

34-
describe('CLI options testing', () => {
3535
test('generation with `config.example.js`', async () => {
3636
const out = await cli([`./config.example.js`], __dirname);
3737

0 commit comments

Comments
 (0)