-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
generate.mts
61 lines (59 loc) · 1.84 KB
/
generate.mts
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
import { type UserConfig, createClient } from "@hey-api/openapi-ts";
import type { LimitedUserConfig } from "./cli.mjs";
import {
buildQueriesOutputPath,
buildRequestsOutputPath,
formatOptions,
} from "./common.mjs";
import { createSource } from "./createSource.mjs";
import { formatOutput, processOutput } from "./format.mjs";
import { print } from "./print.mjs";
export async function generate(options: LimitedUserConfig, version: string) {
const openApiOutputPath = buildRequestsOutputPath(options.output);
const formattedOptions = formatOptions(options);
const config: UserConfig = {
base: formattedOptions.base,
client: formattedOptions.client,
debug: formattedOptions.debug,
dryRun: false,
exportCore: true,
output: {
format: formattedOptions.format,
lint: formattedOptions.lint,
path: openApiOutputPath,
},
input: formattedOptions.input,
request: formattedOptions.request,
schemas: {
export: !formattedOptions.noSchemas,
type: formattedOptions.schemaType,
},
services: {
export: true,
response: formattedOptions.serviceResponse,
asClass: false,
},
types: {
dates: formattedOptions.useDateType,
export: true,
enums: formattedOptions.enums,
},
useOptions: true,
};
await createClient(config);
const source = await createSource({
outputPath: openApiOutputPath,
version,
pageParam: formattedOptions.pageParam,
nextPageParam: formattedOptions.nextPageParam,
initialPageParam: formattedOptions.initialPageParam.toString(),
});
await print(source, formattedOptions);
const queriesOutputPath = buildQueriesOutputPath(options.output);
await formatOutput(queriesOutputPath);
await processOutput({
output: queriesOutputPath,
format: formattedOptions.format,
lint: formattedOptions.lint,
});
}