Skip to content

Commit 0cad0bd

Browse files
Merge pull request #155 from openapi-ui/main
Release V1.0
2 parents e9cab30 + ad10702 commit 0cad0bd

21 files changed

+605
-332
lines changed

.changeset/dry-tables-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': major
3+
---
4+
5+
refactor: refactor client request params to adapt support react-query

.changeset/lovely-laws-press.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 translate multiple Chinese tag into English tag
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': minor
3+
---
4+
5+
feat: support generate react-query

.changeset/ten-eyes-marry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': minor
3+
---
4+
5+
feat: support generate JavaScript

.eslintrc.cjs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ module.exports = {
55
'plugin:@typescript-eslint/recommended',
66
'plugin:@typescript-eslint/recommended-requiring-type-checking',
77
],
8-
ignorePatterns: [
9-
'dist',
10-
'node_modules',
11-
'test',
12-
'.eslintrc.cjs',
13-
'commitlint.config.cjs',
14-
'lint-staged.config.cjs',
15-
'prettier.config.cjs',
16-
],
8+
ignorePatterns: ['dist', 'node_modules', 'test', '*.cjs'],
179
plugins: [],
1810
parserOptions: {
1911
ecmaVersion: 'latest',

README-en_US.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ English | <a href="https://github.com/openapi-ui/openapi-ts-request/blob/master/
66

77
based on [Swagger2/OpenAPI3/Apifox](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) specification Generate
88

9-
- TS interfaces
10-
- request client
9+
- TypeScript/JavaScript
10+
- request client(support any client)
1111
- request mock service
1212
- enum and enum translation
13+
- react-query
1314
- type field label
1415
- JSON Schemas
1516

@@ -18,9 +19,9 @@ docs:[use docs](https://github.com/openapi-ui/openapi-ts-request/issues/100)
1819
## Features
1920

2021
- support Swagger2.0/OpenAPI/Apifox 3.0,3.1 specification
21-
- generate TypeScript interface, reuquest client, request mock service, enum, type field label, JSON Schemas
22+
- generate TypeScript/JavaScript, reuquest client(support any client), request mock service, enum and enum translation, react-query, type field label, JSON Schemas
2223
- support work with npx, CLI, Nodejs
23-
- support custom request function, Fetch、Axios、[UniApp-request](https://github.com/openapi-ui/openapi-ts-request/issues/46)、Node.js、XHR client available
24+
- support custom request function, Fetch、Axios、[UniApp-request](https://github.com/openapi-ui/openapi-ts-request/issues/46)Taro-Request、Node.js、XHR client available
2425
- support filter generate result by tags
2526
- support JSON/YAML specification
2627
- support translate chinese tag name to english tag name
@@ -94,10 +95,13 @@ import request from 'axios';
9495
import * as API from './types';
9596

9697
/** Update an existing pet PUT /pet */
97-
export async function updatePet(
98-
body: API.Pet,
99-
options?: { [key: string]: unknown }
100-
) {
98+
export async function updatePet({
99+
body,
100+
options,
101+
}: {
102+
body: API.Pet;
103+
options?: { [key: string]: unknown };
104+
}) {
101105
return request<unknown>(`/pet`, {
102106
method: 'PUT',
103107
headers: {
@@ -177,31 +181,30 @@ $ openapi --help
177181
Usage: openapi [options]
178182
179183
Options:
180-
-V, --version output the version number
181-
-i, --input <string> OpenAPI specification, can be a path, url (required)
182-
-o, --output <string> output directory (required)
183-
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
184-
--enableLogging <boolean> open the log (default: false)
185-
--priorityRule <string> priority rule, include/exclude/both (default: "include")
186-
--includeTags <(string|RegExp)[]> generate code from include tags
187-
--includePaths <(string|RegExp)[]> generate code from include paths
188-
--excludeTags <(string|RegExp)[]> generate code from exclude tags
189-
--excludePaths <(string|RegExp)[]> generate code from exclude paths
190-
--requestOptionsType <string> custom request method options parameter type (default: "{ [key:
191-
string]: unknown }")
192-
--requestImportStatement <string> custom request import statement, for example: "const request =
193-
require('@/request')"
194-
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable),
195-
"'api'"(string)
196-
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
197-
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
198-
--mockFolder <string> mock file path, for example: './mocks'
199-
--authorization <string> docs authorization
200-
--nullable <boolean> null instead of optional (default: false)
201-
--isTranslateToEnglishTag <boolean>translate chinese tag name to english tag name (default: false)
202-
--isOnlyGenTypeScriptType <boolean>only generate typescript type (default: false)
203-
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
204-
-h, --help display help for command
184+
-V, --version output the version number
185+
-i, --input <string> OpenAPI specification, can be a path, url (required)
186+
-o, --output <string> output directory (required)
187+
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
188+
--enableLogging <boolean> open the log (default: false)
189+
--priorityRule <string> priority rule, include/exclude/both (default: "include")
190+
--includeTags <(string|RegExp)[]> generate code from include tags
191+
--includePaths <(string|RegExp)[]> generate code from include paths
192+
--excludeTags <(string|RegExp)[]> generate code from exclude tags
193+
--excludePaths <(string|RegExp)[]> generate code from exclude paths
194+
--requestOptionsType <string> custom request method options parameter type (default: "{ [key: string]: unknown }")
195+
--requestImportStatement <string> custom request import statement, for example: "const request = require('@/request')"
196+
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable), "'api'"(string)
197+
--isGenReactQuery <boolean> generate react-query (default: false)
198+
--isGenJavaScript <boolean> generate JavaScript (default: false)
199+
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
200+
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
201+
--mockFolder <string> mock file path, for example: './mocks'
202+
--authorization <string> docs authorization
203+
--nullable <boolean> null instead of optional (default: false)
204+
--isTranslateToEnglishTag <boolean> translate chinese tag name to english tag name (default: false)
205+
--isOnlyGenTypeScriptType <boolean> only generate typescript type (default: false)
206+
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
207+
-h, --help display help for command
205208
```
206209

207210
run:
@@ -226,6 +229,8 @@ openapi -i ./spec.json -o ./apis
226229
| requestOptionsType | no | string | '{ [key: string]: unknown }' | custom request method options parameter type |
227230
| requestImportStatement | no | string | - | custom request import statement, for example: "const request = require('@/request')" |
228231
| apiPrefix | no | string | - | custom the prefix of the api path, for example: 'api'(variable), "'api'"(string) |
232+
| isGenReactQuery | no | boolean | false | generate react-query |
233+
| isGenJavaScript | no | boolean | false | generate JavaScript |
229234
| isDisplayTypeLabel | no | boolean | false | generate label matching type field |
230235
| isGenJsonSchemas | no | boolean | false | generate JSON Schemas |
231236
| mockFolder | no | string | - | mock file path, for example: './mocks' |

README.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
根据 [Swagger2/OpenAPI3/Apifox](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) 文档生成:
88

9-
- TS 类型
10-
- 客户端请求函数
9+
- TypeScript/JavaScript
10+
- 客户端请求函数(支持任意客户端)
1111
- 模拟请求响应服务
1212
- 枚举和枚举翻译
13+
- react-query
1314
- 类型字段翻译
1415
- JSON Schemas
1516

@@ -18,9 +19,9 @@
1819
## 功能
1920

2021
- 支持 Swagger2.0/OpenAPI/Apifox 3.0,3.1 定义
21-
- 生成 TS 类型, 请求客户端, 请求模拟服务, 枚举, 类型字段翻译, JSON Schemas
22+
- 生成 TypeScript/JavaScript, 请求客户端(支持任意客户端), 请求模拟服务, 枚举和枚举翻译, react-query, 类型字段翻译, JSON Schemas
2223
- 支持通过 npx、CLI、Nodejs 的方式使用
23-
- 支持自定义请求工具函数, 支持 Fetch、Axios、[UniApp-Request](https://github.com/openapi-ui/openapi-ts-request/issues/46)、Node.js、XHR 客户端
24+
- 支持自定义请求工具函数, 支持 Fetch、Axios、[UniApp-Request](https://github.com/openapi-ui/openapi-ts-request/issues/46)Taro-Request、Node.js、XHR 客户端
2425
- 支持通过 tags 过滤生成结果
2526
- 支持 JSON/YAML 定义文件
2627
- 支持将中文 tag 名称翻译为英文 tag 名称
@@ -94,10 +95,13 @@ import request from 'axios';
9495
import * as API from './types';
9596

9697
/** Update an existing pet PUT /pet */
97-
export async function updatePet(
98-
body: API.Pet,
99-
options?: { [key: string]: unknown }
100-
) {
98+
export async function updatePet({
99+
body,
100+
options,
101+
}: {
102+
body: API.Pet;
103+
options?: { [key: string]: unknown };
104+
}) {
101105
return request<unknown>(`/pet`, {
102106
method: 'PUT',
103107
headers: {
@@ -177,31 +181,30 @@ $ openapi --help
177181
Usage: openapi [options]
178182
179183
Options:
180-
-V, --version output the version number
181-
-i, --input <string> OpenAPI specification, can be a path, url (required)
182-
-o, --output <string> output directory (required)
183-
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
184-
--enableLogging <boolean> open the log (default: false)
185-
--priorityRule <string> priority rule, include/exclude/both (default: "include")
186-
--includeTags <(string|RegExp)[]> generate code from include tags
187-
--includePaths <(string|RegExp)[]> generate code from include paths
188-
--excludeTags <(string|RegExp)[]> generate code from exclude tags
189-
--excludePaths <(string|RegExp)[]> generate code from exclude paths
190-
--requestOptionsType <string> custom request method options parameter type (default: "{ [key:
191-
string]: unknown }")
192-
--requestImportStatement <string> custom request import statement, for example: "const request =
193-
require('@/request')"
194-
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable),
195-
"'api'"(string)
196-
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
197-
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
198-
--mockFolder <string> mock file path, for example: './mocks'
199-
--authorization <string> docs authorization
200-
--nullable <boolean> null instead of optional (default: false)
201-
--isTranslateToEnglishTag <boolean>translate chinese tag name to english tag name (default: false)
202-
--isOnlyGenTypeScriptType <boolean>only generate typescript type (default: false)
203-
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
204-
-h, --help display help for command
184+
-V, --version output the version number
185+
-i, --input <string> OpenAPI specification, can be a path, url (required)
186+
-o, --output <string> output directory (required)
187+
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
188+
--enableLogging <boolean> open the log (default: false)
189+
--priorityRule <string> priority rule, include/exclude/both (default: "include")
190+
--includeTags <(string|RegExp)[]> generate code from include tags
191+
--includePaths <(string|RegExp)[]> generate code from include paths
192+
--excludeTags <(string|RegExp)[]> generate code from exclude tags
193+
--excludePaths <(string|RegExp)[]> generate code from exclude paths
194+
--requestOptionsType <string> custom request method options parameter type (default: "{ [key: string]: unknown }")
195+
--requestImportStatement <string> custom request import statement, for example: "const request = require('@/request')"
196+
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable), "'api'"(string)
197+
--isGenReactQuery <boolean> generate react-query (default: false)
198+
--isGenJavaScript <boolean> generate JavaScript (default: false)
199+
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
200+
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
201+
--mockFolder <string> mock file path, for example: './mocks'
202+
--authorization <string> docs authorization
203+
--nullable <boolean> null instead of optional (default: false)
204+
--isTranslateToEnglishTag <boolean> translate chinese tag name to english tag name (default: false)
205+
--isOnlyGenTypeScriptType <boolean> only generate typescript type (default: false)
206+
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
207+
-h, --help display help for command
205208
```
206209

207210
运行:
@@ -226,6 +229,8 @@ openapi --i ./spec.json --o ./apis
226229
| requestOptionsType || string | '{ [key: string]: unknown }' | 自定义请求方法 options 参数类型 |
227230
| requestImportStatement || string | - | 自定义请求方法表达式,例如:"const request = require('@/request')" |
228231
| apiPrefix || string | - | api path的前缀,例如:'api'(动态变量), "'api'"(字符串) |
232+
| isGenReactQuery || boolean | false | 是否生成 react-query |
233+
| isGenJavaScript || boolean | false | 是否生成 JavaScript |
229234
| isDisplayTypeLabel || boolean | false | 是否生成 type 对应的label |
230235
| isGenJsonSchemas || boolean | false | 是否生成 JSON Schemas |
231236
| mockFolder || string | - | mock文件路径,例如:'./mocks' |

package.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "openapi-ts-request",
33
"version": "0.13.4",
4-
"description": "Swagger2/OpenAPI3 to TypeScript, request client, request mock service, enum, type field label, JSON Schemas",
5-
"packageManager": "pnpm@9.11.0",
4+
"description": "Swagger2/OpenAPI3/Apifox to TypeScript/JavaScript, request client(support any client), request mock service, enum and enum translation, react-query, type field label, JSON Schemas",
5+
"packageManager": "pnpm@9.15.0",
66
"engines": {
77
"node": ">=18.0.0",
88
"pnpm": ">=9"
@@ -62,6 +62,7 @@
6262
"@changesets/cli": "^2.27.6",
6363
"@commitlint/cli": "^19.2.1",
6464
"@commitlint/config-conventional": "^19.2.2",
65+
"@tanstack/react-query": "^5.62.10",
6566
"@types/js-yaml": "^4.0.9",
6667
"@types/lodash": "^4.17.5",
6768
"@types/memoizee": "^0.4.11",
@@ -74,20 +75,24 @@
7475
"@typescript-eslint/parser": "^7.9.0",
7576
"eslint": "^8.57.1",
7677
"husky": "^9.0.11",
77-
"lint-staged": "^15.2.5",
78+
"lint-staged": "^15.3.0",
7879
"openapi-types": "^12.1.3",
7980
"ts-node": "^10.9.2",
8081
"typescript": "5.7.2"
8182
},
8283
"keywords": [
8384
"openapi",
84-
"openapi3",
8585
"swagger",
86-
"openapi to ts",
87-
"openapi to request client",
88-
"openapi to axios client",
89-
"openapi to fetch client",
90-
"openapi to uni request client",
91-
"openapi to JSON Schemas"
86+
"openapi-ts",
87+
"swagger-ts",
88+
"openapi-typescript",
89+
"swagger-typescript",
90+
"openapi-react-query",
91+
"openapi-fetch",
92+
"openapi-axios",
93+
"openapi-uniapp",
94+
"openapi-taro",
95+
"openapi-node-fetch",
96+
"openapi-JSON-Schemas"
9297
]
9398
}

0 commit comments

Comments
 (0)