-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathorval.config.ts
106 lines (104 loc) · 3.6 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import {defineConfig} from "orval";
import {pascal} from "@orval/core";
export default defineConfig({
"soknad-api-client-old": {
input: "./soknad-api-old.json",
output: {
mode: "tags-split",
target: "src/generated",
schemas: "src/generated/model",
client: "react-query",
override: {
mutator: {
path: "./src/lib/api/axiosInstance.ts",
name: "axiosInstance",
},
},
// Vi bruker ikke mocks enda, og avventer ny versjon av orval
// som støtter msw v2.
mock: false,
},
hooks: {
afterAllFilesWrite: "prettier --write",
},
},
"soknad-api-client-old-ssr": {
input: "./soknad-api-old.json",
output: {
mode: "single",
target: "src/generated/old-ssr",
schemas: "src/generated/old-ssr/model",
client: "fetch",
override: {
mutator: {
path: "./src/lib/api/ssr/authenticatedFetch.ts",
name: "authenticatedFetch",
},
operationName: ({operationId}) => ssrCamelCasePrefixer(operationId),
},
mock: false,
},
hooks: {
afterAllFilesWrite: "prettier --write",
},
},
"soknad-api-client-new": {
input: "./soknad-api-new.json",
output: {
mode: "tags-split",
target: "src/generated/new",
schemas: "src/generated/new/model",
client: "react-query",
override: {
mutator: {
path: "./src/lib/api/axiosInstance.ts",
name: "axiosInstance",
},
},
// Vi bruker ikke mocks enda, og avventer ny versjon av orval
// som støtter msw v2.
mock: false,
},
hooks: {
afterAllFilesWrite: "prettier --write",
},
},
"soknad-api-client-new-ssr": {
input: "./soknad-api-new.json",
output: {
mode: "single",
target: "src/generated/new-ssr",
schemas: "src/generated/new-ssr/model",
client: "fetch",
override: {
mutator: {
path: "./src/lib/api/ssr/authenticatedFetch.ts",
name: "authenticatedFetch",
},
operationName: ({operationId}) => ssrCamelCasePrefixer(operationId),
},
mock: false,
},
hooks: {
afterAllFilesWrite: "prettier --write",
},
},
});
/**
* Custom Orval function to prefix methods with "ssr" while retaining camelCase.
*
* operationIds are not strictly schematically mandated by openapi, but
* we can still take them for granted because we use springdoc to generate
* schemas for our Spring Boot backends, and springdoc - at least as configured
* in soknad-api at the time of writing - always generates an operationId.
*
* If we're not using those operations, we don't have to care if one pops up unnamed.
* So if the schema some day happens to include operations where operationId is missing,
* we generate eye-catchingly implausible names for them rather than breaking the build.
*
* Maybe when the SSR code is used on a majority of pages, we can prefer it's always flagged,
* and consider this an error instead.
*/
const ssrCamelCasePrefixer = (operationId: string | undefined) => {
return `ssr${pascal(operationId ?? "MISSING_OPERATION_ID_IN_SPEC")}`;
};