@genapi/presets 3.0.0 → 3.2.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/package.json +17 -14
- package/src/axios/index.ts +0 -2
- package/src/axios/js/config/index.ts +0 -19
- package/src/axios/js/index.ts +0 -19
- package/src/axios/js/parser/index.ts +0 -96
- package/src/axios/ts/config/index.ts +0 -24
- package/src/axios/ts/index.ts +0 -20
- package/src/axios/ts/parser/index.ts +0 -95
- package/src/fetch/index.ts +0 -2
- package/src/fetch/js/config/index.ts +0 -12
- package/src/fetch/js/index.ts +0 -19
- package/src/fetch/js/parser/index.ts +0 -107
- package/src/fetch/ts/config/index.ts +0 -11
- package/src/fetch/ts/index.ts +0 -20
- package/src/fetch/ts/parser/index.ts +0 -98
- package/src/got/index.ts +0 -2
- package/src/got/js/config/index.ts +0 -19
- package/src/got/js/index.ts +0 -20
- package/src/got/js/parser/index.ts +0 -101
- package/src/got/ts/config/index.ts +0 -24
- package/src/got/ts/index.ts +0 -20
- package/src/got/ts/parser/index.ts +0 -102
- package/src/index.ts +0 -21
- package/src/ky/index.ts +0 -2
- package/src/ky/js/config/index.ts +0 -19
- package/src/ky/js/index.ts +0 -20
- package/src/ky/js/parser/index.ts +0 -97
- package/src/ky/ts/config/index.ts +0 -24
- package/src/ky/ts/index.ts +0 -20
- package/src/ky/ts/parser/index.ts +0 -97
- package/src/ofetch/index.ts +0 -2
- package/src/ofetch/js/config/index.ts +0 -19
- package/src/ofetch/js/index.ts +0 -20
- package/src/ofetch/js/parser/index.ts +0 -97
- package/src/ofetch/ts/config/index.ts +0 -24
- package/src/ofetch/ts/index.ts +0 -20
- package/src/ofetch/ts/parser/index.ts +0 -96
- package/tsup.config.ts +0 -18
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genapi/presets",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.2.0",
|
|
5
5
|
"author": "Hairyf <wwu710632@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/hairyf/genapi#readme",
|
|
@@ -19,50 +19,53 @@
|
|
|
19
19
|
".": "./dist/index.mjs",
|
|
20
20
|
"./swag-axios-js": {
|
|
21
21
|
"types": "./dist/axios/js/index.d.ts",
|
|
22
|
-
"
|
|
22
|
+
"default": "./dist/axios/js/index.mjs"
|
|
23
23
|
},
|
|
24
24
|
"./swag-axios-ts": {
|
|
25
25
|
"types": "./dist/axios/ts/index.d.ts",
|
|
26
|
-
"
|
|
26
|
+
"default": "./dist/axios/ts/index.mjs"
|
|
27
27
|
},
|
|
28
28
|
"./swag-fetch-js": {
|
|
29
29
|
"types": "./dist/fetch/js/index.d.ts",
|
|
30
|
-
"
|
|
30
|
+
"default": "./dist/fetch/js/index.mjs"
|
|
31
31
|
},
|
|
32
32
|
"./swag-fetch-ts": {
|
|
33
33
|
"types": "./dist/fetch/ts/index.d.ts",
|
|
34
|
-
"
|
|
34
|
+
"default": "./dist/fetch/ts/index.mjs"
|
|
35
35
|
},
|
|
36
36
|
"./swag-got-js": {
|
|
37
37
|
"types": "./dist/got/js/index.d.ts",
|
|
38
|
-
"
|
|
38
|
+
"default": "./dist/got/js/index.mjs"
|
|
39
39
|
},
|
|
40
40
|
"./swag-got-ts": {
|
|
41
41
|
"types": "./dist/got/ts/index.d.ts",
|
|
42
|
-
"
|
|
42
|
+
"default": "./dist/got/ts/index.mjs"
|
|
43
43
|
},
|
|
44
44
|
"./swag-ky-js": {
|
|
45
45
|
"types": "./dist/ky/js/index.d.ts",
|
|
46
|
-
"
|
|
46
|
+
"default": "./dist/ky/js/index.mjs"
|
|
47
47
|
},
|
|
48
48
|
"./swag-ky-ts": {
|
|
49
49
|
"types": "./dist/ky/ts/index.d.ts",
|
|
50
|
-
"
|
|
50
|
+
"default": "./dist/ky/ts/index.mjs"
|
|
51
51
|
},
|
|
52
52
|
"./swag-ofetch-js": {
|
|
53
53
|
"types": "./dist/ofetch/js/index.d.ts",
|
|
54
|
-
"
|
|
54
|
+
"default": "./dist/ofetch/js/index.mjs"
|
|
55
55
|
},
|
|
56
56
|
"./swag-ofetch-ts": {
|
|
57
57
|
"types": "./dist/ofetch/ts/index.d.ts",
|
|
58
|
-
"
|
|
58
|
+
"default": "./dist/ofetch/ts/index.mjs"
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
|
+
"files": [
|
|
62
|
+
"dist"
|
|
63
|
+
],
|
|
61
64
|
"dependencies": {
|
|
62
65
|
"openapi-specification-types": "^0.0.3",
|
|
63
|
-
"@genapi/
|
|
64
|
-
"@genapi/
|
|
65
|
-
"@genapi/
|
|
66
|
+
"@genapi/parser": "3.2.0",
|
|
67
|
+
"@genapi/shared": "3.2.0",
|
|
68
|
+
"@genapi/pipeline": "3.2.0"
|
|
66
69
|
},
|
|
67
70
|
"scripts": {
|
|
68
71
|
"build": "tsup",
|
package/src/axios/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import { replaceMainext } from '@genapi/parser'
|
|
3
|
-
import { config as _config } from '@genapi/pipeline'
|
|
4
|
-
|
|
5
|
-
export function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead {
|
|
6
|
-
userConfig.import = userConfig.import || {}
|
|
7
|
-
userConfig.output = userConfig.output || {}
|
|
8
|
-
userConfig.import.http = userConfig.import.http || 'axios'
|
|
9
|
-
userConfig.output = replaceMainext(userConfig.output) || 'src/api/index.js'
|
|
10
|
-
|
|
11
|
-
const configRead = _config(userConfig)
|
|
12
|
-
|
|
13
|
-
configRead.graphs.imports.push({
|
|
14
|
-
name: 'http',
|
|
15
|
-
value: userConfig.import.http,
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
return configRead
|
|
19
|
-
}
|
package/src/axios/js/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import pipeline, { compiler, dest, generate, original } from '@genapi/pipeline'
|
|
3
|
-
import { config } from './config'
|
|
4
|
-
import { parser } from './parser'
|
|
5
|
-
|
|
6
|
-
function openapiPipeline(userConfig: ApiPipeline.Config) {
|
|
7
|
-
const process = pipeline(
|
|
8
|
-
userConfig => config(userConfig),
|
|
9
|
-
configRead => original(configRead),
|
|
10
|
-
configRead => parser(configRead),
|
|
11
|
-
configRead => compiler(configRead),
|
|
12
|
-
configRead => generate(configRead),
|
|
13
|
-
configRead => dest(configRead),
|
|
14
|
-
)
|
|
15
|
-
return process(userConfig)
|
|
16
|
-
}
|
|
17
|
-
export { compiler, config, dest, generate, original, parser }
|
|
18
|
-
|
|
19
|
-
export default openapiPipeline
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline, StatementFunction, StatementInterface } from '@genapi/shared'
|
|
2
|
-
import type { Paths } from 'openapi-specification-types'
|
|
3
|
-
import {
|
|
4
|
-
literalFieldsToString,
|
|
5
|
-
parseHeaderCommits,
|
|
6
|
-
parseMethodMetadata,
|
|
7
|
-
parseMethodParameters,
|
|
8
|
-
parseOpenapiSpecification,
|
|
9
|
-
transformBaseURL,
|
|
10
|
-
transformDefinitions,
|
|
11
|
-
transformParameters,
|
|
12
|
-
transformUrlSyntax,
|
|
13
|
-
traversePaths,
|
|
14
|
-
} from '@genapi/parser'
|
|
15
|
-
|
|
16
|
-
export interface PathsTransformOptions {
|
|
17
|
-
configRead: ApiPipeline.ConfigRead
|
|
18
|
-
interfaces: StatementInterface[]
|
|
19
|
-
functions: StatementFunction[]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
23
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
24
|
-
|
|
25
|
-
const comments = parseHeaderCommits(source)
|
|
26
|
-
|
|
27
|
-
const interfaces: StatementInterface[] = []
|
|
28
|
-
const functions: StatementFunction[] = []
|
|
29
|
-
|
|
30
|
-
transformBaseURL(source, {
|
|
31
|
-
configRead,
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
transformDefinitions(source.definitions, {
|
|
35
|
-
interfaces,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
transformPaths(source.paths, {
|
|
39
|
-
configRead,
|
|
40
|
-
functions,
|
|
41
|
-
interfaces,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
configRead.graphs.comments = comments
|
|
45
|
-
configRead.graphs.functions = functions
|
|
46
|
-
configRead.graphs.interfaces = interfaces
|
|
47
|
-
|
|
48
|
-
return configRead
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
52
|
-
traversePaths(paths, (config) => {
|
|
53
|
-
/**
|
|
54
|
-
* function params/function options/function use interfaces
|
|
55
|
-
*/
|
|
56
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
|
|
57
|
-
body: 'data',
|
|
58
|
-
query: 'params',
|
|
59
|
-
})
|
|
60
|
-
let { name, description, url, responseType } = parseMethodMetadata(config)
|
|
61
|
-
|
|
62
|
-
options.push(['...', 'config'])
|
|
63
|
-
interfaces.push(...attachInters)
|
|
64
|
-
parameters.push({
|
|
65
|
-
type: 'import(\'axios\').AxiosRequestConfig',
|
|
66
|
-
name: 'config',
|
|
67
|
-
required: false,
|
|
68
|
-
})
|
|
69
|
-
options.unshift('url')
|
|
70
|
-
options.unshift(['method', `"${config.method}"`])
|
|
71
|
-
if (configRead.config.baseURL)
|
|
72
|
-
options.unshift('baseURL')
|
|
73
|
-
|
|
74
|
-
transformParameters(parameters, {
|
|
75
|
-
syntax: 'ecmascript',
|
|
76
|
-
configRead,
|
|
77
|
-
description,
|
|
78
|
-
interfaces,
|
|
79
|
-
responseType,
|
|
80
|
-
generic: 'import(\'axios\').AxiosResponse<{__type__}>',
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
url = transformUrlSyntax(url)
|
|
84
|
-
|
|
85
|
-
functions.push({
|
|
86
|
-
export: true,
|
|
87
|
-
name,
|
|
88
|
-
description,
|
|
89
|
-
parameters,
|
|
90
|
-
body: [
|
|
91
|
-
`const url = ${url}`,
|
|
92
|
-
`return http.request({ ${literalFieldsToString(options)} })`,
|
|
93
|
-
],
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import { config as _config } from '@genapi/pipeline'
|
|
3
|
-
|
|
4
|
-
export function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead {
|
|
5
|
-
userConfig.import = userConfig.import || {}
|
|
6
|
-
userConfig.import.http = userConfig.import.http || 'axios'
|
|
7
|
-
|
|
8
|
-
const configRead = _config(userConfig)
|
|
9
|
-
|
|
10
|
-
configRead.graphs.imports.push({
|
|
11
|
-
name: 'http',
|
|
12
|
-
names: userConfig.import.http === 'axios' ? ['AxiosRequestConfig'] : undefined,
|
|
13
|
-
value: userConfig.import.http,
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
if (userConfig.import.http !== 'axios') {
|
|
17
|
-
configRead.graphs.imports.push({
|
|
18
|
-
names: ['AxiosRequestConfig'],
|
|
19
|
-
value: 'axios',
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return configRead
|
|
24
|
-
}
|
package/src/axios/ts/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import pipeline, { compiler, dest, generate, original } from '@genapi/pipeline'
|
|
3
|
-
|
|
4
|
-
import { config } from './config'
|
|
5
|
-
import { parser } from './parser'
|
|
6
|
-
|
|
7
|
-
function openapiPipeline(userConfig: ApiPipeline.Config) {
|
|
8
|
-
const process = pipeline(
|
|
9
|
-
userConfig => config(userConfig),
|
|
10
|
-
configRead => original(configRead),
|
|
11
|
-
configRead => parser(configRead),
|
|
12
|
-
configRead => compiler(configRead),
|
|
13
|
-
configRead => generate(configRead),
|
|
14
|
-
configRead => dest(configRead),
|
|
15
|
-
)
|
|
16
|
-
return process(userConfig)
|
|
17
|
-
}
|
|
18
|
-
export { compiler, config, dest, generate, original, parser }
|
|
19
|
-
|
|
20
|
-
export default openapiPipeline
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline, StatementFunction, StatementInterface } from '@genapi/shared'
|
|
2
|
-
import type { Paths } from 'openapi-specification-types'
|
|
3
|
-
import {
|
|
4
|
-
literalFieldsToString,
|
|
5
|
-
parseHeaderCommits,
|
|
6
|
-
parseMethodMetadata,
|
|
7
|
-
parseMethodParameters,
|
|
8
|
-
parseOpenapiSpecification,
|
|
9
|
-
transformBaseURL,
|
|
10
|
-
transformDefinitions,
|
|
11
|
-
transformParameters,
|
|
12
|
-
transformUrlSyntax,
|
|
13
|
-
traversePaths,
|
|
14
|
-
} from '@genapi/parser'
|
|
15
|
-
|
|
16
|
-
export interface PathsTransformOptions {
|
|
17
|
-
configRead: ApiPipeline.ConfigRead
|
|
18
|
-
interfaces: StatementInterface[]
|
|
19
|
-
functions: StatementFunction[]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
23
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
24
|
-
|
|
25
|
-
const comments = parseHeaderCommits(source)
|
|
26
|
-
|
|
27
|
-
const interfaces: StatementInterface[] = []
|
|
28
|
-
const functions: StatementFunction[] = []
|
|
29
|
-
|
|
30
|
-
transformBaseURL(source, {
|
|
31
|
-
configRead,
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
transformDefinitions(source.definitions, {
|
|
35
|
-
interfaces,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
transformPaths(source.paths, {
|
|
39
|
-
configRead,
|
|
40
|
-
functions,
|
|
41
|
-
interfaces,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
configRead.graphs.comments = comments
|
|
45
|
-
configRead.graphs.functions = functions
|
|
46
|
-
configRead.graphs.interfaces = interfaces
|
|
47
|
-
|
|
48
|
-
return configRead
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
52
|
-
traversePaths(paths, (config) => {
|
|
53
|
-
/**
|
|
54
|
-
* function params/function options/function use interfaces
|
|
55
|
-
*/
|
|
56
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
|
|
57
|
-
body: 'data',
|
|
58
|
-
query: 'params',
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
let { name, description, url, responseType } = parseMethodMetadata(config)
|
|
62
|
-
|
|
63
|
-
options.push(['...', 'config'])
|
|
64
|
-
interfaces.push(...attachInters)
|
|
65
|
-
parameters.push({
|
|
66
|
-
name: 'config',
|
|
67
|
-
type: 'AxiosRequestConfig',
|
|
68
|
-
required: false,
|
|
69
|
-
})
|
|
70
|
-
options.unshift('url')
|
|
71
|
-
options.unshift(['method', `"${config.method}"`])
|
|
72
|
-
if (configRead.config.baseURL)
|
|
73
|
-
options.unshift('baseURL')
|
|
74
|
-
|
|
75
|
-
const { spaceResponseType } = transformParameters(parameters, {
|
|
76
|
-
syntax: 'typescript',
|
|
77
|
-
configRead,
|
|
78
|
-
description,
|
|
79
|
-
interfaces,
|
|
80
|
-
responseType,
|
|
81
|
-
})
|
|
82
|
-
url = transformUrlSyntax(url)
|
|
83
|
-
|
|
84
|
-
functions.push({
|
|
85
|
-
export: true,
|
|
86
|
-
name,
|
|
87
|
-
description,
|
|
88
|
-
parameters,
|
|
89
|
-
body: [
|
|
90
|
-
`const url = ${url}`,
|
|
91
|
-
`return http.request<${spaceResponseType}>({ ${literalFieldsToString(options)} })`,
|
|
92
|
-
],
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
|
-
}
|
package/src/fetch/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import { replaceMainext } from '@genapi/parser'
|
|
3
|
-
import { config as _config } from '@genapi/pipeline'
|
|
4
|
-
|
|
5
|
-
export function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead {
|
|
6
|
-
userConfig.import = userConfig.import || {}
|
|
7
|
-
userConfig.output = userConfig.output || {}
|
|
8
|
-
userConfig.output = replaceMainext(userConfig.output) || 'src/api/index.js'
|
|
9
|
-
const configRead = _config(userConfig)
|
|
10
|
-
|
|
11
|
-
return configRead
|
|
12
|
-
}
|
package/src/fetch/js/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import pipeline, { compiler, dest, generate, original } from '@genapi/pipeline'
|
|
3
|
-
import { config } from './config'
|
|
4
|
-
import { parser } from './parser'
|
|
5
|
-
|
|
6
|
-
function openapiPipeline(userConfig: ApiPipeline.Config) {
|
|
7
|
-
const process = pipeline(
|
|
8
|
-
userConfig => config(userConfig),
|
|
9
|
-
configRead => original(configRead),
|
|
10
|
-
configRead => parser(configRead),
|
|
11
|
-
configRead => compiler(configRead),
|
|
12
|
-
configRead => generate(configRead),
|
|
13
|
-
configRead => dest(configRead),
|
|
14
|
-
)
|
|
15
|
-
return process(userConfig)
|
|
16
|
-
}
|
|
17
|
-
export { compiler, config, dest, generate, original, parser }
|
|
18
|
-
|
|
19
|
-
export default openapiPipeline
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline, StatementFunction, StatementInterface } from '@genapi/shared'
|
|
2
|
-
import type { Paths } from 'openapi-specification-types'
|
|
3
|
-
import {
|
|
4
|
-
literalFieldsToString,
|
|
5
|
-
parseHeaderCommits,
|
|
6
|
-
parseMethodMetadata,
|
|
7
|
-
parseMethodParameters,
|
|
8
|
-
parseOpenapiSpecification,
|
|
9
|
-
transformBaseURL,
|
|
10
|
-
transformBodyStringify,
|
|
11
|
-
transformDefinitions,
|
|
12
|
-
transformHeaderOptions,
|
|
13
|
-
transformParameters,
|
|
14
|
-
transformQueryParams,
|
|
15
|
-
transformUrlSyntax,
|
|
16
|
-
traversePaths,
|
|
17
|
-
} from '@genapi/parser'
|
|
18
|
-
|
|
19
|
-
export interface PathsTransformOptions {
|
|
20
|
-
configRead: ApiPipeline.ConfigRead
|
|
21
|
-
interfaces: StatementInterface[]
|
|
22
|
-
functions: StatementFunction[]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
26
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
27
|
-
|
|
28
|
-
const comments = parseHeaderCommits(source)
|
|
29
|
-
|
|
30
|
-
const interfaces: StatementInterface[] = []
|
|
31
|
-
const functions: StatementFunction[] = []
|
|
32
|
-
|
|
33
|
-
transformBaseURL(source, {
|
|
34
|
-
configRead,
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
transformDefinitions(source.definitions, {
|
|
38
|
-
interfaces,
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
transformPaths(source.paths, {
|
|
42
|
-
configRead,
|
|
43
|
-
functions,
|
|
44
|
-
interfaces,
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
configRead.graphs.comments = comments
|
|
48
|
-
configRead.graphs.functions = functions
|
|
49
|
-
configRead.graphs.interfaces = interfaces
|
|
50
|
-
|
|
51
|
-
return configRead
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
55
|
-
traversePaths(paths, (config) => {
|
|
56
|
-
/**
|
|
57
|
-
* function params/function options/function use interfaces
|
|
58
|
-
*/
|
|
59
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
|
|
60
|
-
formData: 'body',
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
let { name, description, url, responseType, body } = parseMethodMetadata(config)
|
|
64
|
-
|
|
65
|
-
interfaces.push(...attachInters)
|
|
66
|
-
parameters.push({
|
|
67
|
-
name: 'config',
|
|
68
|
-
type: 'RequestInit',
|
|
69
|
-
required: false,
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
if (config.method.toLowerCase() !== 'get')
|
|
73
|
-
options.unshift(['method', `"${config.method}"`])
|
|
74
|
-
|
|
75
|
-
transformHeaderOptions('body', { options, parameters })
|
|
76
|
-
|
|
77
|
-
options.push(['...', 'config'])
|
|
78
|
-
|
|
79
|
-
transformParameters(parameters, {
|
|
80
|
-
syntax: 'ecmascript',
|
|
81
|
-
configRead,
|
|
82
|
-
description,
|
|
83
|
-
interfaces,
|
|
84
|
-
responseType,
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
transformBodyStringify('body', { options, parameters })
|
|
88
|
-
|
|
89
|
-
url = transformQueryParams('query', { body, options, url })
|
|
90
|
-
url = transformUrlSyntax(url, { baseURL: configRead.config.baseURL })
|
|
91
|
-
|
|
92
|
-
functions.push({
|
|
93
|
-
export: true,
|
|
94
|
-
async: true,
|
|
95
|
-
name,
|
|
96
|
-
description,
|
|
97
|
-
parameters,
|
|
98
|
-
body: [
|
|
99
|
-
...body,
|
|
100
|
-
`const response = await fetch(${url}, {
|
|
101
|
-
${literalFieldsToString(options)}
|
|
102
|
-
})`,
|
|
103
|
-
'return response.json()',
|
|
104
|
-
],
|
|
105
|
-
})
|
|
106
|
-
})
|
|
107
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import { config as _config } from '@genapi/pipeline'
|
|
3
|
-
|
|
4
|
-
export function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead {
|
|
5
|
-
userConfig.import = userConfig.import || {}
|
|
6
|
-
userConfig.import.http = userConfig.import.http || 'axios'
|
|
7
|
-
|
|
8
|
-
const configRead = _config(userConfig)
|
|
9
|
-
|
|
10
|
-
return configRead
|
|
11
|
-
}
|
package/src/fetch/ts/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import pipeline, { compiler, dest, generate, original } from '@genapi/pipeline'
|
|
3
|
-
|
|
4
|
-
import { config } from './config'
|
|
5
|
-
import { parser } from './parser'
|
|
6
|
-
|
|
7
|
-
function openapiPipeline(userConfig: ApiPipeline.Config) {
|
|
8
|
-
const process = pipeline(
|
|
9
|
-
userConfig => config(userConfig),
|
|
10
|
-
configRead => original(configRead),
|
|
11
|
-
configRead => parser(configRead),
|
|
12
|
-
configRead => compiler(configRead),
|
|
13
|
-
configRead => generate(configRead),
|
|
14
|
-
configRead => dest(configRead),
|
|
15
|
-
)
|
|
16
|
-
return process(userConfig)
|
|
17
|
-
}
|
|
18
|
-
export { compiler, config, dest, generate, original, parser }
|
|
19
|
-
|
|
20
|
-
export default openapiPipeline
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline, StatementFunction, StatementInterface } from '@genapi/shared'
|
|
2
|
-
import type { Paths } from 'openapi-specification-types'
|
|
3
|
-
import {
|
|
4
|
-
parseHeaderCommits,
|
|
5
|
-
parseMethodMetadata,
|
|
6
|
-
parseMethodParameters,
|
|
7
|
-
parseOpenapiSpecification,
|
|
8
|
-
transformBaseURL,
|
|
9
|
-
transformBodyStringify,
|
|
10
|
-
transformDefinitions,
|
|
11
|
-
transformFetchBody,
|
|
12
|
-
transformHeaderOptions,
|
|
13
|
-
transformParameters,
|
|
14
|
-
transformQueryParams,
|
|
15
|
-
transformUrlSyntax,
|
|
16
|
-
traversePaths,
|
|
17
|
-
} from '@genapi/parser'
|
|
18
|
-
|
|
19
|
-
export interface PathsTransformOptions {
|
|
20
|
-
configRead: ApiPipeline.ConfigRead
|
|
21
|
-
interfaces: StatementInterface[]
|
|
22
|
-
functions: StatementFunction[]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
26
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
27
|
-
const comments = parseHeaderCommits(source)
|
|
28
|
-
|
|
29
|
-
const interfaces: StatementInterface[] = []
|
|
30
|
-
const functions: StatementFunction[] = []
|
|
31
|
-
|
|
32
|
-
transformBaseURL(source, {
|
|
33
|
-
configRead,
|
|
34
|
-
})
|
|
35
|
-
transformDefinitions(source.definitions, {
|
|
36
|
-
interfaces,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
transformPaths(source.paths, {
|
|
40
|
-
configRead,
|
|
41
|
-
functions,
|
|
42
|
-
interfaces,
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
configRead.graphs.comments = comments
|
|
46
|
-
configRead.graphs.functions = functions
|
|
47
|
-
configRead.graphs.interfaces = interfaces
|
|
48
|
-
|
|
49
|
-
return configRead
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
53
|
-
traversePaths(paths, (config) => {
|
|
54
|
-
/**
|
|
55
|
-
* function params/function options/function use interfaces
|
|
56
|
-
*/
|
|
57
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config)
|
|
58
|
-
let { name, description, url, responseType, body } = parseMethodMetadata(config)
|
|
59
|
-
|
|
60
|
-
interfaces.push(...attachInters)
|
|
61
|
-
parameters.push({
|
|
62
|
-
name: 'config',
|
|
63
|
-
type: 'RequestInit',
|
|
64
|
-
required: false,
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
if (config.method.toLowerCase() !== 'get')
|
|
68
|
-
options.unshift(['method', `"${config.method}"`])
|
|
69
|
-
|
|
70
|
-
transformHeaderOptions('body', { options, parameters })
|
|
71
|
-
|
|
72
|
-
options.push(['...', 'config'])
|
|
73
|
-
|
|
74
|
-
const { spaceResponseType } = transformParameters(parameters, {
|
|
75
|
-
syntax: 'typescript',
|
|
76
|
-
configRead,
|
|
77
|
-
description,
|
|
78
|
-
interfaces,
|
|
79
|
-
responseType,
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
transformBodyStringify('body', { options, parameters })
|
|
83
|
-
url = transformQueryParams('query', { body, options, url })
|
|
84
|
-
url = transformUrlSyntax(url, { baseURL: configRead.config.baseURL })
|
|
85
|
-
const fetch = transformFetchBody(url, options, spaceResponseType)
|
|
86
|
-
functions.push({
|
|
87
|
-
export: true,
|
|
88
|
-
async: true,
|
|
89
|
-
name,
|
|
90
|
-
description,
|
|
91
|
-
parameters,
|
|
92
|
-
body: [
|
|
93
|
-
...body,
|
|
94
|
-
...fetch,
|
|
95
|
-
],
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
}
|
package/src/got/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import { replaceMainext } from '@genapi/parser'
|
|
3
|
-
import { config as _config } from '@genapi/pipeline'
|
|
4
|
-
|
|
5
|
-
export function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead {
|
|
6
|
-
userConfig.import = userConfig.import || {}
|
|
7
|
-
userConfig.output = userConfig.output || {}
|
|
8
|
-
userConfig.import.http = userConfig.import.http || 'got'
|
|
9
|
-
userConfig.output = replaceMainext(userConfig.output) || 'src/api/index.js'
|
|
10
|
-
|
|
11
|
-
const configRead = _config(userConfig)
|
|
12
|
-
|
|
13
|
-
configRead.graphs.imports.push({
|
|
14
|
-
name: 'http',
|
|
15
|
-
value: userConfig.import.http,
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
return configRead
|
|
19
|
-
}
|
package/src/got/js/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import pipeline, { compiler, dest, generate, original } from '@genapi/pipeline'
|
|
3
|
-
|
|
4
|
-
import { config } from './config'
|
|
5
|
-
import { parser } from './parser'
|
|
6
|
-
|
|
7
|
-
function openapiPipeline(userConfig: ApiPipeline.Config) {
|
|
8
|
-
const process = pipeline(
|
|
9
|
-
userConfig => config(userConfig),
|
|
10
|
-
configRead => original(configRead),
|
|
11
|
-
configRead => parser(configRead),
|
|
12
|
-
configRead => compiler(configRead),
|
|
13
|
-
configRead => generate(configRead),
|
|
14
|
-
configRead => dest(configRead),
|
|
15
|
-
)
|
|
16
|
-
return process(userConfig)
|
|
17
|
-
}
|
|
18
|
-
export { compiler, config, dest, generate, original, parser }
|
|
19
|
-
|
|
20
|
-
export default openapiPipeline
|