@genapi/presets 3.0.0 → 3.1.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 +7 -4
- 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
|
@@ -1,101 +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
|
-
transformParameters,
|
|
13
|
-
transformQueryParams,
|
|
14
|
-
transformUrlSyntax,
|
|
15
|
-
traversePaths,
|
|
16
|
-
} from '@genapi/parser'
|
|
17
|
-
|
|
18
|
-
export interface PathsTransformOptions {
|
|
19
|
-
configRead: ApiPipeline.ConfigRead
|
|
20
|
-
interfaces: StatementInterface[]
|
|
21
|
-
functions: StatementFunction[]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
25
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
26
|
-
|
|
27
|
-
const comments = parseHeaderCommits(source)
|
|
28
|
-
|
|
29
|
-
const interfaces: StatementInterface[] = []
|
|
30
|
-
const functions: StatementFunction[] = []
|
|
31
|
-
|
|
32
|
-
transformBaseURL(source, {
|
|
33
|
-
configRead,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
transformDefinitions(source.definitions, {
|
|
37
|
-
interfaces,
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
transformPaths(source.paths, {
|
|
41
|
-
configRead,
|
|
42
|
-
functions,
|
|
43
|
-
interfaces,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
configRead.graphs.comments = comments
|
|
47
|
-
configRead.graphs.functions = functions
|
|
48
|
-
configRead.graphs.interfaces = interfaces
|
|
49
|
-
|
|
50
|
-
return configRead
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
54
|
-
traversePaths(paths, (config) => {
|
|
55
|
-
/**
|
|
56
|
-
* function params/function options/function use interfaces
|
|
57
|
-
*/
|
|
58
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config)
|
|
59
|
-
let { name, description, url, responseType } = parseMethodMetadata(config)
|
|
60
|
-
|
|
61
|
-
interfaces.push(...attachInters)
|
|
62
|
-
parameters.push({
|
|
63
|
-
name: 'config',
|
|
64
|
-
type: 'import(\'got\').OptionsOfTextResponseBody',
|
|
65
|
-
required: false,
|
|
66
|
-
})
|
|
67
|
-
options.push(['...', 'config'])
|
|
68
|
-
if (configRead.config.baseURL)
|
|
69
|
-
options.unshift(['prefixUrl', 'baseURL'])
|
|
70
|
-
|
|
71
|
-
for (const parameter of parameters) {
|
|
72
|
-
if (parameter.type === 'FormData')
|
|
73
|
-
parameter.type = 'any'
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
transformParameters(parameters, {
|
|
77
|
-
syntax: 'ecmascript',
|
|
78
|
-
configRead,
|
|
79
|
-
description,
|
|
80
|
-
interfaces,
|
|
81
|
-
responseType,
|
|
82
|
-
})
|
|
83
|
-
transformBodyStringify('body', { options, parameters })
|
|
84
|
-
transformQueryParams('query', { optionKey: 'searchParams', options })
|
|
85
|
-
url = transformUrlSyntax(url)
|
|
86
|
-
|
|
87
|
-
functions.push({
|
|
88
|
-
export: true,
|
|
89
|
-
async: true,
|
|
90
|
-
name,
|
|
91
|
-
description,
|
|
92
|
-
parameters,
|
|
93
|
-
body: [
|
|
94
|
-
`const response = await http(${url}, {
|
|
95
|
-
${literalFieldsToString(options)}
|
|
96
|
-
})`,
|
|
97
|
-
'return response.json()',
|
|
98
|
-
],
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
}
|
|
@@ -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 || 'got'
|
|
7
|
-
|
|
8
|
-
const configRead = _config(userConfig)
|
|
9
|
-
|
|
10
|
-
configRead.graphs.imports.push({
|
|
11
|
-
name: 'http',
|
|
12
|
-
names: userConfig.import.http === 'got' ? ['OptionsOfTextResponseBody'] : undefined,
|
|
13
|
-
value: userConfig.import.http,
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
if (userConfig.import.http !== 'got') {
|
|
17
|
-
configRead.graphs.imports.push({
|
|
18
|
-
names: ['OptionsOfTextResponseBody'],
|
|
19
|
-
value: 'got',
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return configRead
|
|
24
|
-
}
|
package/src/got/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,102 +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
|
-
transformParameters,
|
|
13
|
-
transformQueryParams,
|
|
14
|
-
transformUrlSyntax,
|
|
15
|
-
traversePaths,
|
|
16
|
-
} from '@genapi/parser'
|
|
17
|
-
|
|
18
|
-
export interface PathsTransformOptions {
|
|
19
|
-
configRead: ApiPipeline.ConfigRead
|
|
20
|
-
interfaces: StatementInterface[]
|
|
21
|
-
functions: StatementFunction[]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
25
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
26
|
-
|
|
27
|
-
const comments = parseHeaderCommits(source)
|
|
28
|
-
|
|
29
|
-
const interfaces: StatementInterface[] = []
|
|
30
|
-
const functions: StatementFunction[] = []
|
|
31
|
-
|
|
32
|
-
transformBaseURL(source, {
|
|
33
|
-
configRead,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
transformDefinitions(source.definitions, {
|
|
37
|
-
interfaces,
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
transformPaths(source.paths, {
|
|
41
|
-
configRead,
|
|
42
|
-
functions,
|
|
43
|
-
interfaces,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
configRead.graphs.comments = comments
|
|
47
|
-
configRead.graphs.functions = functions
|
|
48
|
-
configRead.graphs.interfaces = interfaces
|
|
49
|
-
|
|
50
|
-
return configRead
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
54
|
-
traversePaths(paths, (config) => {
|
|
55
|
-
/**
|
|
56
|
-
* function params/function options/function use interfaces
|
|
57
|
-
*/
|
|
58
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config)
|
|
59
|
-
let { name, description, url, responseType } = parseMethodMetadata(config)
|
|
60
|
-
|
|
61
|
-
interfaces.push(...attachInters)
|
|
62
|
-
parameters.push({
|
|
63
|
-
name: 'config',
|
|
64
|
-
type: 'OptionsOfTextResponseBody',
|
|
65
|
-
required: false,
|
|
66
|
-
})
|
|
67
|
-
options.push(['...', 'config'])
|
|
68
|
-
if (configRead.config.baseURL)
|
|
69
|
-
options.unshift(['prefixUrl', 'baseURL'])
|
|
70
|
-
|
|
71
|
-
for (const parameter of parameters) {
|
|
72
|
-
if (parameter.type === 'FormData')
|
|
73
|
-
parameter.type = 'any'
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const { spaceResponseType } = transformParameters(parameters, {
|
|
77
|
-
syntax: 'typescript',
|
|
78
|
-
configRead,
|
|
79
|
-
description,
|
|
80
|
-
interfaces,
|
|
81
|
-
responseType,
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
transformBodyStringify('body', { options, parameters })
|
|
85
|
-
transformQueryParams('query', { optionKey: 'searchParams', options })
|
|
86
|
-
url = transformUrlSyntax(url)
|
|
87
|
-
|
|
88
|
-
functions.push({
|
|
89
|
-
export: true,
|
|
90
|
-
async: true,
|
|
91
|
-
name,
|
|
92
|
-
description,
|
|
93
|
-
parameters,
|
|
94
|
-
body: [
|
|
95
|
-
`const response = http.${config.method}(${url}, {
|
|
96
|
-
${literalFieldsToString(options)}
|
|
97
|
-
})`,
|
|
98
|
-
`return response.json<${spaceResponseType}>()`,
|
|
99
|
-
],
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as axios from './axios'
|
|
2
|
-
import * as fetch from './fetch'
|
|
3
|
-
import * as got from './got'
|
|
4
|
-
import * as ky from './ky'
|
|
5
|
-
import * as ofetch from './ofetch'
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
axios,
|
|
9
|
-
fetch,
|
|
10
|
-
got,
|
|
11
|
-
ky,
|
|
12
|
-
ofetch,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default {
|
|
16
|
-
axios,
|
|
17
|
-
fetch,
|
|
18
|
-
got,
|
|
19
|
-
ky,
|
|
20
|
-
ofetch,
|
|
21
|
-
}
|
package/src/ky/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 || 'ky'
|
|
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/ky/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
|
|
@@ -1,97 +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
|
-
transformParameters,
|
|
13
|
-
transformQueryParams,
|
|
14
|
-
transformUrlSyntax,
|
|
15
|
-
traversePaths,
|
|
16
|
-
} from '@genapi/parser'
|
|
17
|
-
|
|
18
|
-
export interface PathsTransformOptions {
|
|
19
|
-
configRead: ApiPipeline.ConfigRead
|
|
20
|
-
interfaces: StatementInterface[]
|
|
21
|
-
functions: StatementFunction[]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
25
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
26
|
-
|
|
27
|
-
const comments = parseHeaderCommits(source)
|
|
28
|
-
|
|
29
|
-
const interfaces: StatementInterface[] = []
|
|
30
|
-
const functions: StatementFunction[] = []
|
|
31
|
-
|
|
32
|
-
transformBaseURL(source, {
|
|
33
|
-
configRead,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
transformDefinitions(source.definitions, {
|
|
37
|
-
interfaces,
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
transformPaths(source.paths, {
|
|
41
|
-
configRead,
|
|
42
|
-
functions,
|
|
43
|
-
interfaces,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
configRead.graphs.comments = comments
|
|
47
|
-
configRead.graphs.functions = functions
|
|
48
|
-
configRead.graphs.interfaces = interfaces
|
|
49
|
-
|
|
50
|
-
return configRead
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
54
|
-
traversePaths(paths, (config) => {
|
|
55
|
-
/**
|
|
56
|
-
* function params/function options/function use interfaces
|
|
57
|
-
*/
|
|
58
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config)
|
|
59
|
-
let { name, description, url, responseType } = parseMethodMetadata(config)
|
|
60
|
-
|
|
61
|
-
interfaces.push(...attachInters)
|
|
62
|
-
parameters.push({
|
|
63
|
-
name: 'config',
|
|
64
|
-
type: 'import(\'ky\').Options',
|
|
65
|
-
required: false,
|
|
66
|
-
})
|
|
67
|
-
options.push(['...', 'config'])
|
|
68
|
-
if (configRead.config.baseURL)
|
|
69
|
-
options.unshift(['prefixUrl', 'baseURL'])
|
|
70
|
-
|
|
71
|
-
transformParameters(parameters, {
|
|
72
|
-
syntax: 'ecmascript',
|
|
73
|
-
configRead,
|
|
74
|
-
description,
|
|
75
|
-
interfaces,
|
|
76
|
-
responseType,
|
|
77
|
-
generic: 'import(\'ky\').KyResponse<{__type__}>',
|
|
78
|
-
})
|
|
79
|
-
transformBodyStringify('body', { options, parameters })
|
|
80
|
-
transformQueryParams('query', { optionKey: 'searchParams', options })
|
|
81
|
-
url = transformUrlSyntax(url)
|
|
82
|
-
|
|
83
|
-
functions.push({
|
|
84
|
-
export: true,
|
|
85
|
-
async: true,
|
|
86
|
-
name,
|
|
87
|
-
description,
|
|
88
|
-
parameters,
|
|
89
|
-
body: [
|
|
90
|
-
`const response = await http(${url}, {
|
|
91
|
-
${literalFieldsToString(options)}
|
|
92
|
-
})`,
|
|
93
|
-
'return response.json()',
|
|
94
|
-
],
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
}
|
|
@@ -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 || 'ky'
|
|
7
|
-
|
|
8
|
-
const configRead = _config(userConfig)
|
|
9
|
-
|
|
10
|
-
configRead.graphs.imports.push({
|
|
11
|
-
name: 'http',
|
|
12
|
-
names: userConfig.import.http === 'ky' ? ['Options'] : undefined,
|
|
13
|
-
value: userConfig.import.http,
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
if (userConfig.import.http !== 'ky') {
|
|
17
|
-
configRead.graphs.imports.push({
|
|
18
|
-
names: ['Options'],
|
|
19
|
-
value: 'ky',
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return configRead
|
|
24
|
-
}
|
package/src/ky/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,97 +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
|
-
transformParameters,
|
|
13
|
-
transformQueryParams,
|
|
14
|
-
transformUrlSyntax,
|
|
15
|
-
traversePaths,
|
|
16
|
-
} from '@genapi/parser'
|
|
17
|
-
|
|
18
|
-
export interface PathsTransformOptions {
|
|
19
|
-
configRead: ApiPipeline.ConfigRead
|
|
20
|
-
interfaces: StatementInterface[]
|
|
21
|
-
functions: StatementFunction[]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
25
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
26
|
-
|
|
27
|
-
const comments = parseHeaderCommits(source)
|
|
28
|
-
|
|
29
|
-
const interfaces: StatementInterface[] = []
|
|
30
|
-
const functions: StatementFunction[] = []
|
|
31
|
-
|
|
32
|
-
transformBaseURL(source, {
|
|
33
|
-
configRead,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
transformDefinitions(source.definitions, {
|
|
37
|
-
interfaces,
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
transformPaths(source.paths, {
|
|
41
|
-
configRead,
|
|
42
|
-
functions,
|
|
43
|
-
interfaces,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
configRead.graphs.comments = comments
|
|
47
|
-
configRead.graphs.functions = functions
|
|
48
|
-
configRead.graphs.interfaces = interfaces
|
|
49
|
-
|
|
50
|
-
return configRead
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
54
|
-
traversePaths(paths, (config) => {
|
|
55
|
-
/**
|
|
56
|
-
* function params/function options/function use interfaces
|
|
57
|
-
*/
|
|
58
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config)
|
|
59
|
-
let { name, description, url, responseType } = parseMethodMetadata(config)
|
|
60
|
-
|
|
61
|
-
interfaces.push(...attachInters)
|
|
62
|
-
parameters.push({
|
|
63
|
-
name: 'config',
|
|
64
|
-
type: 'Options',
|
|
65
|
-
required: false,
|
|
66
|
-
})
|
|
67
|
-
options.push(['...', 'config'])
|
|
68
|
-
if (configRead.config.baseURL)
|
|
69
|
-
options.unshift(['prefixUrl', 'baseURL'])
|
|
70
|
-
|
|
71
|
-
const { spaceResponseType } = transformParameters(parameters, {
|
|
72
|
-
syntax: 'typescript',
|
|
73
|
-
configRead,
|
|
74
|
-
description,
|
|
75
|
-
interfaces,
|
|
76
|
-
responseType,
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
transformBodyStringify('body', { options, parameters })
|
|
80
|
-
transformQueryParams('query', { optionKey: 'searchParams', options })
|
|
81
|
-
url = transformUrlSyntax(url)
|
|
82
|
-
|
|
83
|
-
functions.push({
|
|
84
|
-
export: true,
|
|
85
|
-
async: true,
|
|
86
|
-
name,
|
|
87
|
-
description,
|
|
88
|
-
parameters,
|
|
89
|
-
body: [
|
|
90
|
-
`const response = await http(${url}, {
|
|
91
|
-
${literalFieldsToString(options)}
|
|
92
|
-
})`,
|
|
93
|
-
`return response.json<${spaceResponseType}>()`,
|
|
94
|
-
],
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
}
|
package/src/ofetch/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 || 'ofetch'
|
|
9
|
-
userConfig.output = replaceMainext(userConfig.output) || 'src/api/index.js'
|
|
10
|
-
|
|
11
|
-
const configRead = _config(userConfig)
|
|
12
|
-
|
|
13
|
-
configRead.graphs.imports.push({
|
|
14
|
-
name: 'ofetch',
|
|
15
|
-
value: userConfig.import.http,
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
return configRead
|
|
19
|
-
}
|
package/src/ofetch/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
|