@genapi/presets 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/axios/index.d.ts +9 -0
- package/dist/axios/index.mjs +7 -0
- package/dist/axios/js/config/index.d.ts +5 -0
- package/dist/axios/js/config/index.mjs +18 -0
- package/dist/axios/js/index.d.ts +6 -0
- package/dist/axios/js/index.mjs +25 -0
- package/dist/axios/js/parser/index.d.ts +12 -0
- package/dist/axios/js/parser/index.mjs +77 -0
- package/dist/axios/ts/config/index.d.ts +5 -0
- package/dist/axios/ts/config/index.mjs +22 -0
- package/dist/axios/ts/index.d.ts +6 -0
- package/dist/axios/ts/index.mjs +25 -0
- package/dist/axios/ts/parser/index.d.ts +12 -0
- package/dist/axios/ts/parser/index.mjs +76 -0
- package/dist/fetch/index.d.ts +9 -0
- package/dist/fetch/index.mjs +7 -0
- package/dist/fetch/js/config/index.d.ts +5 -0
- package/dist/fetch/js/config/index.mjs +13 -0
- package/dist/fetch/js/index.d.ts +6 -0
- package/dist/fetch/js/index.mjs +25 -0
- package/dist/fetch/js/parser/index.d.ts +12 -0
- package/dist/fetch/js/parser/index.mjs +83 -0
- package/dist/fetch/ts/config/index.d.ts +5 -0
- package/dist/fetch/ts/config/index.mjs +11 -0
- package/dist/fetch/ts/index.d.ts +6 -0
- package/dist/fetch/ts/index.mjs +25 -0
- package/dist/fetch/ts/parser/index.d.ts +12 -0
- package/dist/fetch/ts/parser/index.mjs +79 -0
- package/dist/got/index.d.ts +9 -0
- package/dist/got/index.mjs +7 -0
- package/dist/got/js/config/index.d.ts +5 -0
- package/dist/got/js/config/index.mjs +18 -0
- package/dist/got/js/index.d.ts +6 -0
- package/dist/got/js/index.mjs +25 -0
- package/dist/got/js/parser/index.d.ts +12 -0
- package/dist/got/js/parser/index.mjs +82 -0
- package/dist/got/ts/config/index.d.ts +5 -0
- package/dist/got/ts/config/index.mjs +22 -0
- package/dist/got/ts/index.d.ts +6 -0
- package/dist/got/ts/index.mjs +25 -0
- package/dist/got/ts/parser/index.d.ts +12 -0
- package/dist/got/ts/parser/index.mjs +82 -0
- package/dist/index--xiziIvG.d.ts +8 -0
- package/dist/index-BByL5W2V.d.ts +18 -0
- package/dist/index-BIRCFgYi.d.ts +18 -0
- package/dist/index-BJrp0lx3.d.ts +18 -0
- package/dist/index-BWvY4w5U.d.ts +8 -0
- package/dist/index-BnNpBsOT.d.ts +18 -0
- package/dist/index-CApSnKVf.d.ts +8 -0
- package/dist/index-CQJFGBWr.d.ts +8 -0
- package/dist/index-DBbTnSBj.d.ts +18 -0
- package/dist/index-DEC0eIj4.d.ts +18 -0
- package/dist/index-DZ7D8MkM.d.ts +18 -0
- package/dist/index-IqUGJ_D5.d.ts +8 -0
- package/dist/index-VKTbyIEw.d.ts +18 -0
- package/dist/index-pIxMzJ5o.d.ts +18 -0
- package/dist/index-vrb8mA6n.d.ts +18 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.mjs +21 -0
- package/dist/ky/index.d.ts +9 -0
- package/dist/ky/index.mjs +7 -0
- package/dist/ky/js/config/index.d.ts +5 -0
- package/dist/ky/js/config/index.mjs +18 -0
- package/dist/ky/js/index.d.ts +6 -0
- package/dist/ky/js/index.mjs +25 -0
- package/dist/ky/js/parser/index.d.ts +12 -0
- package/dist/ky/js/parser/index.mjs +79 -0
- package/dist/ky/ts/config/index.d.ts +5 -0
- package/dist/ky/ts/config/index.mjs +22 -0
- package/dist/ky/ts/index.d.ts +6 -0
- package/dist/ky/ts/index.mjs +25 -0
- package/dist/ky/ts/parser/index.d.ts +12 -0
- package/dist/ky/ts/parser/index.mjs +78 -0
- package/dist/ofetch/index.d.ts +9 -0
- package/dist/ofetch/index.mjs +7 -0
- package/dist/ofetch/js/config/index.d.ts +5 -0
- package/dist/ofetch/js/config/index.mjs +18 -0
- package/dist/ofetch/js/index.d.ts +6 -0
- package/dist/ofetch/js/index.mjs +25 -0
- package/dist/ofetch/js/parser/index.d.ts +12 -0
- package/dist/ofetch/js/parser/index.mjs +78 -0
- package/dist/ofetch/ts/config/index.d.ts +5 -0
- package/dist/ofetch/ts/config/index.mjs +22 -0
- package/dist/ofetch/ts/index.d.ts +6 -0
- package/dist/ofetch/ts/index.mjs +25 -0
- package/dist/ofetch/ts/parser/index.d.ts +12 -0
- package/dist/ofetch/ts/parser/index.mjs +76 -0
- package/package.json +71 -0
- package/src/axios/index.ts +2 -0
- package/src/axios/js/config/index.ts +19 -0
- package/src/axios/js/index.ts +19 -0
- package/src/axios/js/parser/index.ts +96 -0
- package/src/axios/ts/config/index.ts +24 -0
- package/src/axios/ts/index.ts +20 -0
- package/src/axios/ts/parser/index.ts +95 -0
- package/src/fetch/index.ts +2 -0
- package/src/fetch/js/config/index.ts +12 -0
- package/src/fetch/js/index.ts +19 -0
- package/src/fetch/js/parser/index.ts +107 -0
- package/src/fetch/ts/config/index.ts +11 -0
- package/src/fetch/ts/index.ts +20 -0
- package/src/fetch/ts/parser/index.ts +98 -0
- package/src/got/index.ts +2 -0
- package/src/got/js/config/index.ts +19 -0
- package/src/got/js/index.ts +20 -0
- package/src/got/js/parser/index.ts +101 -0
- package/src/got/ts/config/index.ts +24 -0
- package/src/got/ts/index.ts +20 -0
- package/src/got/ts/parser/index.ts +102 -0
- package/src/index.ts +21 -0
- package/src/ky/index.ts +2 -0
- package/src/ky/js/config/index.ts +19 -0
- package/src/ky/js/index.ts +20 -0
- package/src/ky/js/parser/index.ts +97 -0
- package/src/ky/ts/config/index.ts +24 -0
- package/src/ky/ts/index.ts +20 -0
- package/src/ky/ts/parser/index.ts +97 -0
- package/src/ofetch/index.ts +2 -0
- package/src/ofetch/js/config/index.ts +19 -0
- package/src/ofetch/js/index.ts +20 -0
- package/src/ofetch/js/parser/index.ts +97 -0
- package/src/ofetch/ts/config/index.ts +24 -0
- package/src/ofetch/ts/index.ts +20 -0
- package/src/ofetch/ts/parser/index.ts +96 -0
- package/tsup.config.ts +18 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/ky/js/config/index.ts
|
|
2
|
+
import { replaceMainext } from "@genapi/parser";
|
|
3
|
+
import { config as _config } from "@genapi/pipeline";
|
|
4
|
+
function config(userConfig) {
|
|
5
|
+
userConfig.import = userConfig.import || {};
|
|
6
|
+
userConfig.output = userConfig.output || {};
|
|
7
|
+
userConfig.import.http = userConfig.import.http || "ky";
|
|
8
|
+
userConfig.output = replaceMainext(userConfig.output) || "src/api/index.js";
|
|
9
|
+
const configRead = _config(userConfig);
|
|
10
|
+
configRead.graphs.imports.push({
|
|
11
|
+
name: "http",
|
|
12
|
+
value: userConfig.import.http
|
|
13
|
+
});
|
|
14
|
+
return configRead;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
config
|
|
18
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import '@genapi/shared';
|
|
2
|
+
export { compiler, dest, generate, original } from '@genapi/pipeline';
|
|
3
|
+
export { config } from './config/index.js';
|
|
4
|
+
export { parser } from './parser/index.js';
|
|
5
|
+
export { o as default } from '../../index-DZ7D8MkM.js';
|
|
6
|
+
import 'openapi-specification-types';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/ky/js/index.ts
|
|
2
|
+
import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
|
|
3
|
+
import { config } from "./config/index.mjs";
|
|
4
|
+
import { parser } from "./parser/index.mjs";
|
|
5
|
+
function openapiPipeline(userConfig) {
|
|
6
|
+
const process = pipeline(
|
|
7
|
+
(userConfig2) => config(userConfig2),
|
|
8
|
+
(configRead) => original(configRead),
|
|
9
|
+
(configRead) => parser(configRead),
|
|
10
|
+
(configRead) => compiler(configRead),
|
|
11
|
+
(configRead) => generate(configRead),
|
|
12
|
+
(configRead) => dest(configRead)
|
|
13
|
+
);
|
|
14
|
+
return process(userConfig);
|
|
15
|
+
}
|
|
16
|
+
var js_default = openapiPipeline;
|
|
17
|
+
export {
|
|
18
|
+
compiler,
|
|
19
|
+
config,
|
|
20
|
+
js_default as default,
|
|
21
|
+
dest,
|
|
22
|
+
generate,
|
|
23
|
+
original,
|
|
24
|
+
parser
|
|
25
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApiPipeline, StatementInterface, StatementFunction } from '@genapi/shared';
|
|
2
|
+
import { Paths } from 'openapi-specification-types';
|
|
3
|
+
|
|
4
|
+
interface PathsTransformOptions {
|
|
5
|
+
configRead: ApiPipeline.ConfigRead;
|
|
6
|
+
interfaces: StatementInterface[];
|
|
7
|
+
functions: StatementFunction[];
|
|
8
|
+
}
|
|
9
|
+
declare function parser(configRead: ApiPipeline.ConfigRead): ApiPipeline.ConfigRead<ApiPipeline.Config>;
|
|
10
|
+
declare function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions): void;
|
|
11
|
+
|
|
12
|
+
export { type PathsTransformOptions, parser, transformPaths };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/ky/js/parser/index.ts
|
|
2
|
+
import {
|
|
3
|
+
literalFieldsToString,
|
|
4
|
+
parseHeaderCommits,
|
|
5
|
+
parseMethodMetadata,
|
|
6
|
+
parseMethodParameters,
|
|
7
|
+
parseOpenapiSpecification,
|
|
8
|
+
transformBaseURL,
|
|
9
|
+
transformBodyStringify,
|
|
10
|
+
transformDefinitions,
|
|
11
|
+
transformParameters,
|
|
12
|
+
transformQueryParams,
|
|
13
|
+
transformUrlSyntax,
|
|
14
|
+
traversePaths
|
|
15
|
+
} from "@genapi/parser";
|
|
16
|
+
function parser(configRead) {
|
|
17
|
+
const source = parseOpenapiSpecification(configRead.source);
|
|
18
|
+
const comments = parseHeaderCommits(source);
|
|
19
|
+
const interfaces = [];
|
|
20
|
+
const functions = [];
|
|
21
|
+
transformBaseURL(source, {
|
|
22
|
+
configRead
|
|
23
|
+
});
|
|
24
|
+
transformDefinitions(source.definitions, {
|
|
25
|
+
interfaces
|
|
26
|
+
});
|
|
27
|
+
transformPaths(source.paths, {
|
|
28
|
+
configRead,
|
|
29
|
+
functions,
|
|
30
|
+
interfaces
|
|
31
|
+
});
|
|
32
|
+
configRead.graphs.comments = comments;
|
|
33
|
+
configRead.graphs.functions = functions;
|
|
34
|
+
configRead.graphs.interfaces = interfaces;
|
|
35
|
+
return configRead;
|
|
36
|
+
}
|
|
37
|
+
function transformPaths(paths, { configRead, functions, interfaces }) {
|
|
38
|
+
traversePaths(paths, (config) => {
|
|
39
|
+
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config);
|
|
40
|
+
let { name, description, url, responseType } = parseMethodMetadata(config);
|
|
41
|
+
interfaces.push(...attachInters);
|
|
42
|
+
parameters.push({
|
|
43
|
+
name: "config",
|
|
44
|
+
type: "import('ky').Options",
|
|
45
|
+
required: false
|
|
46
|
+
});
|
|
47
|
+
options.push(["...", "config"]);
|
|
48
|
+
if (configRead.config.baseURL)
|
|
49
|
+
options.unshift(["prefixUrl", "baseURL"]);
|
|
50
|
+
transformParameters(parameters, {
|
|
51
|
+
syntax: "ecmascript",
|
|
52
|
+
configRead,
|
|
53
|
+
description,
|
|
54
|
+
interfaces,
|
|
55
|
+
responseType,
|
|
56
|
+
generic: "import('ky').KyResponse<{__type__}>"
|
|
57
|
+
});
|
|
58
|
+
transformBodyStringify("body", { options, parameters });
|
|
59
|
+
transformQueryParams("query", { optionKey: "searchParams", options });
|
|
60
|
+
url = transformUrlSyntax(url);
|
|
61
|
+
functions.push({
|
|
62
|
+
export: true,
|
|
63
|
+
async: true,
|
|
64
|
+
name,
|
|
65
|
+
description,
|
|
66
|
+
parameters,
|
|
67
|
+
body: [
|
|
68
|
+
`const response = await http(${url}, {
|
|
69
|
+
${literalFieldsToString(options)}
|
|
70
|
+
})`,
|
|
71
|
+
"return response.json()"
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
parser,
|
|
78
|
+
transformPaths
|
|
79
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/ky/ts/config/index.ts
|
|
2
|
+
import { config as _config } from "@genapi/pipeline";
|
|
3
|
+
function config(userConfig) {
|
|
4
|
+
userConfig.import = userConfig.import || {};
|
|
5
|
+
userConfig.import.http = userConfig.import.http || "ky";
|
|
6
|
+
const configRead = _config(userConfig);
|
|
7
|
+
configRead.graphs.imports.push({
|
|
8
|
+
name: "http",
|
|
9
|
+
names: userConfig.import.http === "ky" ? ["Options"] : void 0,
|
|
10
|
+
value: userConfig.import.http
|
|
11
|
+
});
|
|
12
|
+
if (userConfig.import.http !== "ky") {
|
|
13
|
+
configRead.graphs.imports.push({
|
|
14
|
+
names: ["Options"],
|
|
15
|
+
value: "ky"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return configRead;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
config
|
|
22
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import '@genapi/shared';
|
|
2
|
+
export { compiler, dest, generate, original } from '@genapi/pipeline';
|
|
3
|
+
export { config } from './config/index.js';
|
|
4
|
+
export { parser } from './parser/index.js';
|
|
5
|
+
export { o as default } from '../../index-DEC0eIj4.js';
|
|
6
|
+
import 'openapi-specification-types';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/ky/ts/index.ts
|
|
2
|
+
import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
|
|
3
|
+
import { config } from "./config/index.mjs";
|
|
4
|
+
import { parser } from "./parser/index.mjs";
|
|
5
|
+
function openapiPipeline(userConfig) {
|
|
6
|
+
const process = pipeline(
|
|
7
|
+
(userConfig2) => config(userConfig2),
|
|
8
|
+
(configRead) => original(configRead),
|
|
9
|
+
(configRead) => parser(configRead),
|
|
10
|
+
(configRead) => compiler(configRead),
|
|
11
|
+
(configRead) => generate(configRead),
|
|
12
|
+
(configRead) => dest(configRead)
|
|
13
|
+
);
|
|
14
|
+
return process(userConfig);
|
|
15
|
+
}
|
|
16
|
+
var ts_default = openapiPipeline;
|
|
17
|
+
export {
|
|
18
|
+
compiler,
|
|
19
|
+
config,
|
|
20
|
+
ts_default as default,
|
|
21
|
+
dest,
|
|
22
|
+
generate,
|
|
23
|
+
original,
|
|
24
|
+
parser
|
|
25
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApiPipeline, StatementInterface, StatementFunction } from '@genapi/shared';
|
|
2
|
+
import { Paths } from 'openapi-specification-types';
|
|
3
|
+
|
|
4
|
+
interface PathsTransformOptions {
|
|
5
|
+
configRead: ApiPipeline.ConfigRead;
|
|
6
|
+
interfaces: StatementInterface[];
|
|
7
|
+
functions: StatementFunction[];
|
|
8
|
+
}
|
|
9
|
+
declare function parser(configRead: ApiPipeline.ConfigRead): ApiPipeline.ConfigRead<ApiPipeline.Config>;
|
|
10
|
+
declare function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions): void;
|
|
11
|
+
|
|
12
|
+
export { type PathsTransformOptions, parser, transformPaths };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/ky/ts/parser/index.ts
|
|
2
|
+
import {
|
|
3
|
+
literalFieldsToString,
|
|
4
|
+
parseHeaderCommits,
|
|
5
|
+
parseMethodMetadata,
|
|
6
|
+
parseMethodParameters,
|
|
7
|
+
parseOpenapiSpecification,
|
|
8
|
+
transformBaseURL,
|
|
9
|
+
transformBodyStringify,
|
|
10
|
+
transformDefinitions,
|
|
11
|
+
transformParameters,
|
|
12
|
+
transformQueryParams,
|
|
13
|
+
transformUrlSyntax,
|
|
14
|
+
traversePaths
|
|
15
|
+
} from "@genapi/parser";
|
|
16
|
+
function parser(configRead) {
|
|
17
|
+
const source = parseOpenapiSpecification(configRead.source);
|
|
18
|
+
const comments = parseHeaderCommits(source);
|
|
19
|
+
const interfaces = [];
|
|
20
|
+
const functions = [];
|
|
21
|
+
transformBaseURL(source, {
|
|
22
|
+
configRead
|
|
23
|
+
});
|
|
24
|
+
transformDefinitions(source.definitions, {
|
|
25
|
+
interfaces
|
|
26
|
+
});
|
|
27
|
+
transformPaths(source.paths, {
|
|
28
|
+
configRead,
|
|
29
|
+
functions,
|
|
30
|
+
interfaces
|
|
31
|
+
});
|
|
32
|
+
configRead.graphs.comments = comments;
|
|
33
|
+
configRead.graphs.functions = functions;
|
|
34
|
+
configRead.graphs.interfaces = interfaces;
|
|
35
|
+
return configRead;
|
|
36
|
+
}
|
|
37
|
+
function transformPaths(paths, { configRead, functions, interfaces }) {
|
|
38
|
+
traversePaths(paths, (config) => {
|
|
39
|
+
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config);
|
|
40
|
+
let { name, description, url, responseType } = parseMethodMetadata(config);
|
|
41
|
+
interfaces.push(...attachInters);
|
|
42
|
+
parameters.push({
|
|
43
|
+
name: "config",
|
|
44
|
+
type: "Options",
|
|
45
|
+
required: false
|
|
46
|
+
});
|
|
47
|
+
options.push(["...", "config"]);
|
|
48
|
+
if (configRead.config.baseURL)
|
|
49
|
+
options.unshift(["prefixUrl", "baseURL"]);
|
|
50
|
+
const { spaceResponseType } = transformParameters(parameters, {
|
|
51
|
+
syntax: "typescript",
|
|
52
|
+
configRead,
|
|
53
|
+
description,
|
|
54
|
+
interfaces,
|
|
55
|
+
responseType
|
|
56
|
+
});
|
|
57
|
+
transformBodyStringify("body", { options, parameters });
|
|
58
|
+
transformQueryParams("query", { optionKey: "searchParams", options });
|
|
59
|
+
url = transformUrlSyntax(url);
|
|
60
|
+
functions.push({
|
|
61
|
+
export: true,
|
|
62
|
+
async: true,
|
|
63
|
+
name,
|
|
64
|
+
description,
|
|
65
|
+
parameters,
|
|
66
|
+
body: [
|
|
67
|
+
`const response = await http(${url}, {
|
|
68
|
+
${literalFieldsToString(options)}
|
|
69
|
+
})`,
|
|
70
|
+
`return response.json<${spaceResponseType}>()`
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
parser,
|
|
77
|
+
transformPaths
|
|
78
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { i as js } from '../index-BJrp0lx3.js';
|
|
2
|
+
export { i as ts } from '../index-VKTbyIEw.js';
|
|
3
|
+
import '@genapi/shared';
|
|
4
|
+
import '@genapi/pipeline';
|
|
5
|
+
import './js/config/index.js';
|
|
6
|
+
import './js/parser/index.js';
|
|
7
|
+
import 'openapi-specification-types';
|
|
8
|
+
import './ts/config/index.js';
|
|
9
|
+
import './ts/parser/index.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/ofetch/js/config/index.ts
|
|
2
|
+
import { replaceMainext } from "@genapi/parser";
|
|
3
|
+
import { config as _config } from "@genapi/pipeline";
|
|
4
|
+
function config(userConfig) {
|
|
5
|
+
userConfig.import = userConfig.import || {};
|
|
6
|
+
userConfig.output = userConfig.output || {};
|
|
7
|
+
userConfig.import.http = userConfig.import.http || "ofetch";
|
|
8
|
+
userConfig.output = replaceMainext(userConfig.output) || "src/api/index.js";
|
|
9
|
+
const configRead = _config(userConfig);
|
|
10
|
+
configRead.graphs.imports.push({
|
|
11
|
+
name: "ofetch",
|
|
12
|
+
value: userConfig.import.http
|
|
13
|
+
});
|
|
14
|
+
return configRead;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
config
|
|
18
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import '@genapi/shared';
|
|
2
|
+
export { compiler, dest, generate, original } from '@genapi/pipeline';
|
|
3
|
+
export { config } from './config/index.js';
|
|
4
|
+
export { parser } from './parser/index.js';
|
|
5
|
+
export { o as default } from '../../index-BJrp0lx3.js';
|
|
6
|
+
import 'openapi-specification-types';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/ofetch/js/index.ts
|
|
2
|
+
import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
|
|
3
|
+
import { config } from "./config/index.mjs";
|
|
4
|
+
import { parser } from "./parser/index.mjs";
|
|
5
|
+
function openapiPipeline(userConfig) {
|
|
6
|
+
const process = pipeline(
|
|
7
|
+
(userConfig2) => config(userConfig2),
|
|
8
|
+
(configRead) => original(configRead),
|
|
9
|
+
(configRead) => parser(configRead),
|
|
10
|
+
(configRead) => compiler(configRead),
|
|
11
|
+
(configRead) => generate(configRead),
|
|
12
|
+
(configRead) => dest(configRead)
|
|
13
|
+
);
|
|
14
|
+
return process(userConfig);
|
|
15
|
+
}
|
|
16
|
+
var js_default = openapiPipeline;
|
|
17
|
+
export {
|
|
18
|
+
compiler,
|
|
19
|
+
config,
|
|
20
|
+
js_default as default,
|
|
21
|
+
dest,
|
|
22
|
+
generate,
|
|
23
|
+
original,
|
|
24
|
+
parser
|
|
25
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApiPipeline, StatementInterface, StatementFunction } from '@genapi/shared';
|
|
2
|
+
import { Paths } from 'openapi-specification-types';
|
|
3
|
+
|
|
4
|
+
interface PathsTransformOptions {
|
|
5
|
+
configRead: ApiPipeline.ConfigRead;
|
|
6
|
+
interfaces: StatementInterface[];
|
|
7
|
+
functions: StatementFunction[];
|
|
8
|
+
}
|
|
9
|
+
declare function parser(configRead: ApiPipeline.ConfigRead): ApiPipeline.ConfigRead<ApiPipeline.Config>;
|
|
10
|
+
declare function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions): void;
|
|
11
|
+
|
|
12
|
+
export { type PathsTransformOptions, parser, transformPaths };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/ofetch/js/parser/index.ts
|
|
2
|
+
import {
|
|
3
|
+
literalFieldsToString,
|
|
4
|
+
parseHeaderCommits,
|
|
5
|
+
parseMethodMetadata,
|
|
6
|
+
parseMethodParameters,
|
|
7
|
+
parseOpenapiSpecification,
|
|
8
|
+
transformBaseURL,
|
|
9
|
+
transformDefinitions,
|
|
10
|
+
transformParameters,
|
|
11
|
+
transformQueryParams,
|
|
12
|
+
transformUrlSyntax,
|
|
13
|
+
traversePaths
|
|
14
|
+
} from "@genapi/parser";
|
|
15
|
+
function parser(configRead) {
|
|
16
|
+
const source = parseOpenapiSpecification(configRead.source);
|
|
17
|
+
const comments = parseHeaderCommits(source);
|
|
18
|
+
const interfaces = [];
|
|
19
|
+
const functions = [];
|
|
20
|
+
transformBaseURL(source, {
|
|
21
|
+
configRead
|
|
22
|
+
});
|
|
23
|
+
transformDefinitions(source.definitions, {
|
|
24
|
+
interfaces
|
|
25
|
+
});
|
|
26
|
+
transformPaths(source.paths, {
|
|
27
|
+
configRead,
|
|
28
|
+
functions,
|
|
29
|
+
interfaces
|
|
30
|
+
});
|
|
31
|
+
configRead.graphs.comments = comments;
|
|
32
|
+
configRead.graphs.functions = functions;
|
|
33
|
+
configRead.graphs.interfaces = interfaces;
|
|
34
|
+
return configRead;
|
|
35
|
+
}
|
|
36
|
+
function transformPaths(paths, { configRead, functions, interfaces }) {
|
|
37
|
+
traversePaths(paths, (config) => {
|
|
38
|
+
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
|
|
39
|
+
formData: "body",
|
|
40
|
+
query: "params"
|
|
41
|
+
});
|
|
42
|
+
let { name, description, url, responseType, body } = parseMethodMetadata(config);
|
|
43
|
+
interfaces.push(...attachInters);
|
|
44
|
+
parameters.push({
|
|
45
|
+
name: "options",
|
|
46
|
+
type: "import('ofetch').FetchOptions",
|
|
47
|
+
required: false
|
|
48
|
+
});
|
|
49
|
+
options.push(["...", "options"]);
|
|
50
|
+
options.unshift(["method", `"${config.method}"`]);
|
|
51
|
+
if (configRead.config.baseURL)
|
|
52
|
+
options.unshift("baseURL");
|
|
53
|
+
transformParameters(parameters, {
|
|
54
|
+
syntax: "ecmascript",
|
|
55
|
+
configRead,
|
|
56
|
+
description,
|
|
57
|
+
interfaces,
|
|
58
|
+
responseType
|
|
59
|
+
});
|
|
60
|
+
url = transformQueryParams("query", { body, options, url });
|
|
61
|
+
url = transformUrlSyntax(url, { baseURL: configRead.config.baseURL });
|
|
62
|
+
functions.push({
|
|
63
|
+
export: true,
|
|
64
|
+
async: true,
|
|
65
|
+
name,
|
|
66
|
+
description,
|
|
67
|
+
parameters,
|
|
68
|
+
body: [
|
|
69
|
+
...body,
|
|
70
|
+
`return ofetch(${url}, {${literalFieldsToString(options)}})`
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
parser,
|
|
77
|
+
transformPaths
|
|
78
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/ofetch/ts/config/index.ts
|
|
2
|
+
import { config as _config } from "@genapi/pipeline";
|
|
3
|
+
function config(userConfig) {
|
|
4
|
+
userConfig.import = userConfig.import || {};
|
|
5
|
+
userConfig.import.http = userConfig.import.http || "ofetch";
|
|
6
|
+
const configRead = _config(userConfig);
|
|
7
|
+
configRead.graphs.imports.push({
|
|
8
|
+
name: "ofetch",
|
|
9
|
+
names: userConfig.import.http === "ofetch" ? ["FetchOptions"] : void 0,
|
|
10
|
+
value: userConfig.import.http
|
|
11
|
+
});
|
|
12
|
+
if (userConfig.import.http !== "ofetch") {
|
|
13
|
+
configRead.graphs.imports.push({
|
|
14
|
+
names: ["FetchOptions"],
|
|
15
|
+
value: "ofetch"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return configRead;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
config
|
|
22
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import '@genapi/shared';
|
|
2
|
+
export { compiler, dest, generate, original } from '@genapi/pipeline';
|
|
3
|
+
export { config } from './config/index.js';
|
|
4
|
+
export { parser } from './parser/index.js';
|
|
5
|
+
export { o as default } from '../../index-VKTbyIEw.js';
|
|
6
|
+
import 'openapi-specification-types';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/ofetch/ts/index.ts
|
|
2
|
+
import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
|
|
3
|
+
import { config } from "./config/index.mjs";
|
|
4
|
+
import { parser } from "./parser/index.mjs";
|
|
5
|
+
function openapiPipeline(userConfig) {
|
|
6
|
+
const process = pipeline(
|
|
7
|
+
(userConfig2) => config(userConfig2),
|
|
8
|
+
(configRead) => original(configRead),
|
|
9
|
+
(configRead) => parser(configRead),
|
|
10
|
+
(configRead) => compiler(configRead),
|
|
11
|
+
(configRead) => generate(configRead),
|
|
12
|
+
(configRead) => dest(configRead)
|
|
13
|
+
);
|
|
14
|
+
return process(userConfig);
|
|
15
|
+
}
|
|
16
|
+
var ts_default = openapiPipeline;
|
|
17
|
+
export {
|
|
18
|
+
compiler,
|
|
19
|
+
config,
|
|
20
|
+
ts_default as default,
|
|
21
|
+
dest,
|
|
22
|
+
generate,
|
|
23
|
+
original,
|
|
24
|
+
parser
|
|
25
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApiPipeline, StatementInterface, StatementFunction } from '@genapi/shared';
|
|
2
|
+
import { Paths } from 'openapi-specification-types';
|
|
3
|
+
|
|
4
|
+
interface PathsTransformOptions {
|
|
5
|
+
configRead: ApiPipeline.ConfigRead;
|
|
6
|
+
interfaces: StatementInterface[];
|
|
7
|
+
functions: StatementFunction[];
|
|
8
|
+
}
|
|
9
|
+
declare function parser(configRead: ApiPipeline.ConfigRead): ApiPipeline.ConfigRead<ApiPipeline.Config>;
|
|
10
|
+
declare function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions): void;
|
|
11
|
+
|
|
12
|
+
export { type PathsTransformOptions, parser, transformPaths };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/ofetch/ts/parser/index.ts
|
|
2
|
+
import {
|
|
3
|
+
literalFieldsToString,
|
|
4
|
+
parseHeaderCommits,
|
|
5
|
+
parseMethodMetadata,
|
|
6
|
+
parseMethodParameters,
|
|
7
|
+
parseOpenapiSpecification,
|
|
8
|
+
transformBaseURL,
|
|
9
|
+
transformDefinitions,
|
|
10
|
+
transformParameters,
|
|
11
|
+
transformQueryParams,
|
|
12
|
+
transformUrlSyntax,
|
|
13
|
+
traversePaths
|
|
14
|
+
} from "@genapi/parser";
|
|
15
|
+
function parser(configRead) {
|
|
16
|
+
const source = parseOpenapiSpecification(configRead.source);
|
|
17
|
+
const comments = parseHeaderCommits(source);
|
|
18
|
+
const interfaces = [];
|
|
19
|
+
const functions = [];
|
|
20
|
+
transformBaseURL(source, {
|
|
21
|
+
configRead
|
|
22
|
+
});
|
|
23
|
+
transformDefinitions(source.definitions, {
|
|
24
|
+
interfaces
|
|
25
|
+
});
|
|
26
|
+
transformPaths(source.paths, {
|
|
27
|
+
configRead,
|
|
28
|
+
functions,
|
|
29
|
+
interfaces
|
|
30
|
+
});
|
|
31
|
+
configRead.graphs.comments = comments;
|
|
32
|
+
configRead.graphs.functions = functions;
|
|
33
|
+
configRead.graphs.interfaces = interfaces;
|
|
34
|
+
return configRead;
|
|
35
|
+
}
|
|
36
|
+
function transformPaths(paths, { configRead, functions, interfaces }) {
|
|
37
|
+
traversePaths(paths, (config) => {
|
|
38
|
+
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
|
|
39
|
+
formData: "body",
|
|
40
|
+
query: "params"
|
|
41
|
+
});
|
|
42
|
+
let { name, description, url, responseType, body } = parseMethodMetadata(config);
|
|
43
|
+
interfaces.push(...attachInters);
|
|
44
|
+
parameters.push({
|
|
45
|
+
name: "options",
|
|
46
|
+
type: "FetchOptions",
|
|
47
|
+
required: false
|
|
48
|
+
});
|
|
49
|
+
options.push(["...", "options"]);
|
|
50
|
+
options.unshift(["method", `"${config.method}"`]);
|
|
51
|
+
if (configRead.config.baseURL)
|
|
52
|
+
options.unshift("baseURL");
|
|
53
|
+
const { spaceResponseType } = transformParameters(parameters, {
|
|
54
|
+
syntax: "typescript",
|
|
55
|
+
configRead,
|
|
56
|
+
description,
|
|
57
|
+
interfaces,
|
|
58
|
+
responseType
|
|
59
|
+
});
|
|
60
|
+
url = transformQueryParams("query", { body, options, url });
|
|
61
|
+
url = transformUrlSyntax(url);
|
|
62
|
+
functions.push({
|
|
63
|
+
export: true,
|
|
64
|
+
name,
|
|
65
|
+
description,
|
|
66
|
+
parameters,
|
|
67
|
+
body: [
|
|
68
|
+
`return ofetch<${spaceResponseType}>(${url}, {${literalFieldsToString(options)}})`
|
|
69
|
+
]
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
parser,
|
|
75
|
+
transformPaths
|
|
76
|
+
};
|