Skip to content

Commit f34d2fc

Browse files
perf: perf tip
1 parent 1295a23 commit f34d2fc

File tree

4 files changed

+49
-46
lines changed

4 files changed

+49
-46
lines changed

.changeset/purple-trains-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': patch
3+
---
4+
5+
perf: perf tip

README-en_US.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ create ```openapi-ts-request.config.ts``` file in the project root directory
3333
> the config file also supports ***.openapi-ts-request.ts***, ***openapi-ts-request.config.cjs*** format, reference [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig?tab=readme-ov-file#cosmiconfig)
3434
3535
```ts
36+
import type { GenerateServiceProps } from 'openapi-ts-request'
37+
3638
export default {
3739
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
38-
}
40+
} as GenerateServiceProps
3941
```
4042

4143
support passing in array config for generate
4244

4345
```ts
46+
import type { GenerateServiceProps } from 'openapi-ts-request'
47+
4448
export default [
4549
{
4650
schemaPath: 'http://app.swagger.io/v2/swagger.json',
@@ -50,7 +54,7 @@ export default [
5054
schemaPath: 'http://auth.swagger.io/v2/swagger.json',
5155
serversPath: './src/apis/auth',
5256
}
53-
]
57+
] as GenerateServiceProps[]
5458
```
5559

5660
add the command in ```script``` of ```package.json```: ```"openapi": "openapi-ts",```
@@ -129,21 +133,20 @@ $ openapi --help
129133
Options:
130134
-V, --version output the version number
131135
-i, --input <string> OpenAPI specification, can be a path, url (required)
132-
-o, --output <string> Output directory (required)
136+
-o, --output <string> output directory (required)
133137
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch"
134-
--allowedTags <string[]> Generate results from allowed tags
135-
--requestOptionsType <string> Custom request method options parameter type (default: "{ [key:
138+
--allowedTags <string[]> generate results from allowed tags
139+
--requestOptionsType <string> custom request method options parameter type (default: "{ [key:
136140
string]: unknown }")
137141
--requestImportStatement <string> custom request import statement, for example: "const request =
138-
require(`@/request`)"
139-
--apiPrefix <string> Custom the prefix of the api path, for example: "api"(variable),
140-
`"api"`(string)
141-
--isDisplayTypeLabel <boolean> Generate label matching type field (default: false) (default: false)
142-
--isGenJsonSchemas <boolean> Generate JSON Schemas (default: false) (default: false)
143-
--mockFolder <string> Mock file path, (default: "./mocks")
144-
--nullable <boolean> null instead of optional (default: false) (default: false)
145-
--isCamelCase <boolean> CamelCase naming of controller files and request client (default: true)
146-
(default: true)
142+
require('@/request')"
143+
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable),
144+
"'api'"(string)
145+
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
146+
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
147+
--mockFolder <string> mock file path (default: "./mocks")
148+
--nullable <boolean> null instead of optional (default: false)
149+
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
147150
-h, --help display help for command
148151
```
149152

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ pnpm i openapi-ts-request -D
3333
> 配置文件还支持 ***.openapi-ts-request.ts***, ***openapi-ts-request.config.cjs*** 等格式,参考 [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig?tab=readme-ov-file#cosmiconfig)
3434
3535
```ts
36+
import type { GenerateServiceProps } from 'openapi-ts-request'
37+
3638
export default {
3739
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
38-
}
40+
} as GenerateServiceProps
3941
```
4042

4143
支持传入数组配置进行生成
4244

4345
```ts
46+
import type { GenerateServiceProps } from 'openapi-ts-request'
47+
4448
export default [
4549
{
4650
schemaPath: 'http://app.swagger.io/v2/swagger.json',
@@ -50,7 +54,7 @@ export default [
5054
schemaPath: 'http://auth.swagger.io/v2/swagger.json',
5155
serversPath: './src/apis/auth',
5256
}
53-
]
57+
] as GenerateServiceProps[]
5458
```
5559

5660
```package.json``````script``` 中添加命令: ```"openapi": "openapi-ts",```
@@ -129,21 +133,20 @@ $ openapi --help
129133
Options:
130134
-V, --version output the version number
131135
-i, --input <string> OpenAPI specification, can be a path, url (required)
132-
-o, --output <string> Output directory (required)
136+
-o, --output <string> output directory (required)
133137
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch"
134-
--allowedTags <string[]> Generate results from allowed tags
135-
--requestOptionsType <string> Custom request method options parameter type (default: "{ [key:
138+
--allowedTags <string[]> generate results from allowed tags
139+
--requestOptionsType <string> custom request method options parameter type (default: "{ [key:
136140
string]: unknown }")
137141
--requestImportStatement <string> custom request import statement, for example: "const request =
138-
require(`@/request`)"
139-
--apiPrefix <string> Custom the prefix of the api path, for example: "api"(variable),
140-
`"api"`(string)
141-
--isDisplayTypeLabel <boolean> Generate label matching type field (default: false) (default: false)
142-
--isGenJsonSchemas <boolean> Generate JSON Schemas (default: false) (default: false)
143-
--mockFolder <string> Mock file path, (default: "./mocks")
144-
--nullable <boolean> null instead of optional (default: false) (default: false)
145-
--isCamelCase <boolean> CamelCase naming of controller files and request client (default: true)
146-
(default: true)
142+
require('@/request')"
143+
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable),
144+
"'api'"(string)
145+
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
146+
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
147+
--mockFolder <string> mock file path (default: "./mocks")
148+
--nullable <boolean> null instead of optional (default: false)
149+
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
147150
-h, --help display help for command
148151
```
149152

src/bin/openapi.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,35 @@ const params = program
1313
'-i, --input <string>',
1414
'OpenAPI specification, can be a path, url (required)'
1515
)
16-
.requiredOption('-o, --output <string>', 'Output directory (required)')
16+
.requiredOption('-o, --output <string>', 'output directory (required)')
1717
.option(
1818
'--requestLibPath <string>',
1919
'custom request lib path, for example: "@/request", "node-fetch"'
2020
)
21-
.option('--allowedTags <string[]>', 'Generate results from allowed tags')
21+
.option('--allowedTags <string[]>', 'generate results from allowed tags')
2222
.option(
2323
'--requestOptionsType <string>',
24-
'Custom request method options parameter type (default: "{ [key: string]: unknown }")'
24+
'custom request method options parameter type (default: "{ [key: string]: unknown }")'
2525
)
2626
.option(
2727
'--requestImportStatement <string>',
28-
'custom request import statement, for example: "const request = require(`@/request`)"'
28+
`custom request import statement, for example: "const request = require('@/request')"`
2929
)
3030
.option(
3131
'--apiPrefix <string>',
32-
'Custom the prefix of the api path, for example: "api"(variable), `"api"`(string)'
32+
`custom the prefix of the api path, for example: "api"(variable), "'api'"(string)`
3333
)
3434
.option(
3535
'--isDisplayTypeLabel <boolean>',
36-
'Generate label matching type field (default: false)',
37-
false
38-
)
39-
.option(
40-
'--isGenJsonSchemas <boolean>',
41-
'Generate JSON Schemas (default: false)',
42-
false
43-
)
44-
.option('--mockFolder <string>', 'Mock file path, (default: "./mocks")')
45-
.option(
46-
'--nullable <boolean>',
47-
'null instead of optional (default: false)',
36+
'generate label matching type field',
4837
false
4938
)
39+
.option('--isGenJsonSchemas <boolean>', 'generate JSON Schemas', false)
40+
.option('--mockFolder <string>', 'Mock file path (default: "./mocks")')
41+
.option('--nullable <boolean>', 'null instead of optional', false)
5042
.option(
5143
'--isCamelCase <boolean>',
52-
'CamelCase naming of controller files and request client (default: true)',
44+
'camelCase naming of controller files and request client',
5345
true
5446
)
5547
.parse(process.argv)

0 commit comments

Comments
 (0)