forked from orval-labs/orval
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit-modes.ts
More file actions
110 lines (104 loc) 路 2.93 KB
/
Copy pathsplit-modes.ts
File metadata and controls
110 lines (104 loc) 路 2.93 KB
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
107
108
109
110
import path from 'node:path';
import {
type GeneratorOperation,
NamingConvention,
type NormalizedOutputOptions,
OutputClient,
OutputMockType,
OutputMode,
type WriteSpecBuilder,
} from '../types';
// Test fixtures for the split-style writers (writeSplitMode, writeTagsMode,
// writeSplitTagsMode). Construct minimal builder/output objects using `as
// unknown as` casts to avoid hand-typing every field of the large
// NormalizedOutputOptions / WriteSpecBuilder shapes.
export const createSplitModeOperation = (
overrides: Partial<GeneratorOperation> = {},
): GeneratorOperation => ({
imports: [],
implementation: '',
mockOutputs: [
{
type: OutputMockType.MSW,
implementation: {
function: '',
handler: '',
handlerName: 'mockHandler',
},
imports: [],
},
],
tags: ['pets'],
operationName: 'listPets',
...overrides,
});
export const createSplitModeBuilder = (target: string): WriteSpecBuilder =>
({
operations: { listPets: createSplitModeOperation() },
verbOptions: {},
schemas: [],
title: () => ({ implementation: '', implementationMock: '' }),
header: () => ({ implementation: '', implementationMock: '' }),
footer: () => ({ implementation: '', implementationMock: '' }),
imports: () => '',
importsMock: () => '',
extraFiles: [],
info: { title: 'pet-store' },
target,
spec: {},
}) as unknown as WriteSpecBuilder;
export const createSplitModeOutput = (
target: string,
overrides: Partial<NormalizedOutputOptions> = {},
): NormalizedOutputOptions =>
({
target,
fileExtension: '.ts',
mode: OutputMode.SPLIT,
namingConvention: NamingConvention.CAMEL_CASE,
client: OutputClient.AXIOS,
httpClient: 'axios',
schemas: undefined,
mock: { indexMockFiles: false, generators: [] },
clean: false,
docs: false,
headers: false,
indexFiles: false,
allParamsOptional: false,
urlEncodeParameters: false,
unionAddMissingProperties: false,
optionsParamRequired: false,
propertySortOrder: 'Alphabetical',
override: {
tags: {},
operations: {},
mutator: undefined,
paramsSerializerOptions: undefined,
requestOptions: true,
header: false,
formData: { disabled: false, mutator: undefined },
formUrlEncoded: false,
components: {
schemas: { suffix: '', itemSuffix: '' },
responses: { suffix: '' },
parameters: { suffix: '' },
requestBodies: { suffix: '' },
},
namingConvention: {},
hono: {},
mcp: {},
query: {},
angular: { provideIn: false },
swr: {},
zod: {},
fetch: {},
},
...overrides,
}) as unknown as NormalizedOutputOptions;
export const createSplitModeProps = (target: string) => ({
builder: createSplitModeBuilder(target),
workspace: path.dirname(target),
output: createSplitModeOutput(target),
projectName: undefined,
header: '',
});