Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dry-tables-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openapi-ts-request': major
---

refactor: refactor client request params to adapt support react-query
5 changes: 5 additions & 0 deletions .changeset/lovely-laws-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openapi-ts-request': patch
---

perf: perf translate multiple Chinese tag into English tag
5 changes: 5 additions & 0 deletions .changeset/popular-rabbits-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openapi-ts-request': minor
---

feat: support generate react-query
5 changes: 5 additions & 0 deletions .changeset/ten-eyes-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openapi-ts-request': minor
---

feat: support generate JavaScript
10 changes: 1 addition & 9 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
ignorePatterns: [
'dist',
'node_modules',
'test',
'.eslintrc.cjs',
'commitlint.config.cjs',
'lint-staged.config.cjs',
'prettier.config.cjs',
],
ignorePatterns: ['dist', 'node_modules', 'test', '*.cjs'],
plugins: [],
parserOptions: {
ecmaVersion: 'latest',
Expand Down
71 changes: 38 additions & 33 deletions README-en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ English | <a href="https://github.com/openapi-ui/openapi-ts-request/blob/master/

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

- TS interfaces
- request client
- TypeScript/JavaScript
- request client(support any client)
- request mock service
- enum and enum translation
- react-query
- type field label
- JSON Schemas

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

- support Swagger2.0/OpenAPI/Apifox 3.0,3.1 specification
- generate TypeScript interface, reuquest client, request mock service, enum, type field label, JSON Schemas
- generate TypeScript/JavaScript, reuquest client(support any client), request mock service, enum and enum translation, react-query, type field label, JSON Schemas
- support work with npx, CLI, Nodejs
- support custom request function, Fetch、Axios、[UniApp-request](https://github.com/openapi-ui/openapi-ts-request/issues/46)、Node.js、XHR client available
- 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
- support filter generate result by tags
- support JSON/YAML specification
- support translate chinese tag name to english tag name
Expand Down Expand Up @@ -94,10 +95,13 @@ import request from 'axios';
import * as API from './types';

/** Update an existing pet PUT /pet */
export async function updatePet(
body: API.Pet,
options?: { [key: string]: unknown }
) {
export async function updatePet({
body,
options,
}: {
body: API.Pet;
options?: { [key: string]: unknown };
}) {
return request<unknown>(`/pet`, {
method: 'PUT',
headers: {
Expand Down Expand Up @@ -177,31 +181,30 @@ $ openapi --help
Usage: openapi [options]

Options:
-V, --version output the version number
-i, --input <string> OpenAPI specification, can be a path, url (required)
-o, --output <string> output directory (required)
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
--enableLogging <boolean> open the log (default: false)
--priorityRule <string> priority rule, include/exclude/both (default: "include")
--includeTags <(string|RegExp)[]> generate code from include tags
--includePaths <(string|RegExp)[]> generate code from include paths
--excludeTags <(string|RegExp)[]> generate code from exclude tags
--excludePaths <(string|RegExp)[]> generate code from exclude paths
--requestOptionsType <string> custom request method options parameter type (default: "{ [key:
string]: unknown }")
--requestImportStatement <string> custom request import statement, for example: "const request =
require('@/request')"
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable),
"'api'"(string)
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
--mockFolder <string> mock file path, for example: './mocks'
--authorization <string> docs authorization
--nullable <boolean> null instead of optional (default: false)
--isTranslateToEnglishTag <boolean>translate chinese tag name to english tag name (default: false)
--isOnlyGenTypeScriptType <boolean>only generate typescript type (default: false)
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
-h, --help display help for command
-V, --version output the version number
-i, --input <string> OpenAPI specification, can be a path, url (required)
-o, --output <string> output directory (required)
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
--enableLogging <boolean> open the log (default: false)
--priorityRule <string> priority rule, include/exclude/both (default: "include")
--includeTags <(string|RegExp)[]> generate code from include tags
--includePaths <(string|RegExp)[]> generate code from include paths
--excludeTags <(string|RegExp)[]> generate code from exclude tags
--excludePaths <(string|RegExp)[]> generate code from exclude paths
--requestOptionsType <string> custom request method options parameter type (default: "{ [key: string]: unknown }")
--requestImportStatement <string> custom request import statement, for example: "const request = require('@/request')"
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable), "'api'"(string)
--isGenReactQuery <boolean> generate react-query (default: false)
--isGenJavaScript <boolean> generate JavaScript (default: false)
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
--mockFolder <string> mock file path, for example: './mocks'
--authorization <string> docs authorization
--nullable <boolean> null instead of optional (default: false)
--isTranslateToEnglishTag <boolean> translate chinese tag name to english tag name (default: false)
--isOnlyGenTypeScriptType <boolean> only generate typescript type (default: false)
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
-h, --help display help for command
```

run:
Expand All @@ -226,6 +229,8 @@ openapi -i ./spec.json -o ./apis
| requestOptionsType | no | string | '{ [key: string]: unknown }' | custom request method options parameter type |
| requestImportStatement | no | string | - | custom request import statement, for example: "const request = require('@/request')" |
| apiPrefix | no | string | - | custom the prefix of the api path, for example: 'api'(variable), "'api'"(string) |
| isGenReactQuery | no | boolean | false | generate react-query |
| isGenJavaScript | no | boolean | false | generate JavaScript |
| isDisplayTypeLabel | no | boolean | false | generate label matching type field |
| isGenJsonSchemas | no | boolean | false | generate JSON Schemas |
| mockFolder | no | string | - | mock file path, for example: './mocks' |
Expand Down
71 changes: 38 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

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

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

Expand All @@ -18,9 +19,9 @@
## 功能

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

/** Update an existing pet PUT /pet */
export async function updatePet(
body: API.Pet,
options?: { [key: string]: unknown }
) {
export async function updatePet({
body,
options,
}: {
body: API.Pet;
options?: { [key: string]: unknown };
}) {
return request<unknown>(`/pet`, {
method: 'PUT',
headers: {
Expand Down Expand Up @@ -177,31 +181,30 @@ $ openapi --help
Usage: openapi [options]

Options:
-V, --version output the version number
-i, --input <string> OpenAPI specification, can be a path, url (required)
-o, --output <string> output directory (required)
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
--enableLogging <boolean> open the log (default: false)
--priorityRule <string> priority rule, include/exclude/both (default: "include")
--includeTags <(string|RegExp)[]> generate code from include tags
--includePaths <(string|RegExp)[]> generate code from include paths
--excludeTags <(string|RegExp)[]> generate code from exclude tags
--excludePaths <(string|RegExp)[]> generate code from exclude paths
--requestOptionsType <string> custom request method options parameter type (default: "{ [key:
string]: unknown }")
--requestImportStatement <string> custom request import statement, for example: "const request =
require('@/request')"
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable),
"'api'"(string)
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
--mockFolder <string> mock file path, for example: './mocks'
--authorization <string> docs authorization
--nullable <boolean> null instead of optional (default: false)
--isTranslateToEnglishTag <boolean>translate chinese tag name to english tag name (default: false)
--isOnlyGenTypeScriptType <boolean>only generate typescript type (default: false)
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
-h, --help display help for command
-V, --version output the version number
-i, --input <string> OpenAPI specification, can be a path, url (required)
-o, --output <string> output directory (required)
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
--enableLogging <boolean> open the log (default: false)
--priorityRule <string> priority rule, include/exclude/both (default: "include")
--includeTags <(string|RegExp)[]> generate code from include tags
--includePaths <(string|RegExp)[]> generate code from include paths
--excludeTags <(string|RegExp)[]> generate code from exclude tags
--excludePaths <(string|RegExp)[]> generate code from exclude paths
--requestOptionsType <string> custom request method options parameter type (default: "{ [key: string]: unknown }")
--requestImportStatement <string> custom request import statement, for example: "const request = require('@/request')"
--apiPrefix <string> custom the prefix of the api path, for example: "api"(variable), "'api'"(string)
--isGenReactQuery <boolean> generate react-query (default: false)
--isGenJavaScript <boolean> generate JavaScript (default: false)
--isDisplayTypeLabel <boolean> generate label matching type field (default: false)
--isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
--mockFolder <string> mock file path, for example: './mocks'
--authorization <string> docs authorization
--nullable <boolean> null instead of optional (default: false)
--isTranslateToEnglishTag <boolean> translate chinese tag name to english tag name (default: false)
--isOnlyGenTypeScriptType <boolean> only generate typescript type (default: false)
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
-h, --help display help for command
```

运行:
Expand All @@ -226,6 +229,8 @@ openapi --i ./spec.json --o ./apis
| requestOptionsType | 否 | string | '{ [key: string]: unknown }' | 自定义请求方法 options 参数类型 |
| requestImportStatement | 否 | string | - | 自定义请求方法表达式,例如:"const request = require('@/request')" |
| apiPrefix | 否 | string | - | api path的前缀,例如:'api'(动态变量), "'api'"(字符串) |
| isGenReactQuery | 否 | boolean | false | 是否生成 react-query |
| isGenJavaScript | 否 | boolean | false | 是否生成 JavaScript |
| isDisplayTypeLabel | 否 | boolean | false | 是否生成 type 对应的label |
| isGenJsonSchemas | 否 | boolean | false | 是否生成 JSON Schemas |
| mockFolder | 否 | string | - | mock文件路径,例如:'./mocks' |
Expand Down
25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "openapi-ts-request",
"version": "0.13.4",
"description": "Swagger2/OpenAPI3 to TypeScript, request client, request mock service, enum, type field label, JSON Schemas",
"packageManager": "pnpm@9.11.0",
"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",
"packageManager": "pnpm@9.15.0",
"engines": {
"node": ">=18.0.0",
"pnpm": ">=9"
Expand Down Expand Up @@ -62,6 +62,7 @@
"@changesets/cli": "^2.27.6",
"@commitlint/cli": "^19.2.1",
"@commitlint/config-conventional": "^19.2.2",
"@tanstack/react-query": "^5.62.10",
"@types/js-yaml": "^4.0.9",
"@types/lodash": "^4.17.5",
"@types/memoizee": "^0.4.11",
Expand All @@ -74,20 +75,24 @@
"@typescript-eslint/parser": "^7.9.0",
"eslint": "^8.57.1",
"husky": "^9.0.11",
"lint-staged": "^15.2.5",
"lint-staged": "^15.3.0",
"openapi-types": "^12.1.3",
"ts-node": "^10.9.2",
"typescript": "5.7.2"
},
"keywords": [
"openapi",
"openapi3",
"swagger",
"openapi to ts",
"openapi to request client",
"openapi to axios client",
"openapi to fetch client",
"openapi to uni request client",
"openapi to JSON Schemas"
"openapi-ts",
"swagger-ts",
"openapi-typescript",
"swagger-typescript",
"openapi-react-query",
"openapi-fetch",
"openapi-axios",
"openapi-uniapp",
"openapi-taro",
"openapi-node-fetch",
"openapi-JSON-Schemas"
]
}
Loading
Loading