-
Notifications
You must be signed in to change notification settings - Fork 0
/
orval.config.ts
64 lines (61 loc) · 1.7 KB
/
orval.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { UseQueryOptions } from "@tanstack/react-query";
import type { OperationOptions } from "@orval/core";
import { defineConfig } from "orval";
// For some complex requests, we use POST in order to send a body with what would otherwise be a GET.
// This lists the operation IDs for such requests.
// We configure Orval to generate simple `useQuery`-based code, as it would for a GET request,
// rather than its default `useMutation` approach for POSTs.
const getStylePostRequests = [
"getAvailableActions",
"eval-full",
"eval-bounded-interp",
];
const useQueryPost: {
[key: string]: OperationOptions;
} = Object.assign(
{},
...getStylePostRequests.map((op) => {
return {
[op]: {
query: {
useQuery: true,
},
},
};
})
);
// gc immediately, to disable showing cached data.
const queryOpts: UseQueryOptions = { gcTime: 0 };
export default defineConfig({
"primer-api": {
input: {
target: "./primer-api.json",
// Disabled until we can deal with the myriad validation issues
// that the IBM OpenAPI validator raises.
validation: false,
},
output: {
mode: "split",
workspace: "./src/primer-api",
target: "./primer-api.ts",
// cleaning the output ensures idempotency
clean: true,
schemas: "model",
client: "react-query",
// We do not yet use the generated mocks.
mock: false,
prettier: true,
override: {
mutator: {
path: "../orval/mutator/use-custom-instance.ts",
name: "useCustomInstance",
},
operations: {
...useQueryPost,
},
useDates: true,
query: { options: queryOpts },
},
},
},
});