Skip to content

Commit 9bfad84

Browse files
authored
feat: enrich readme files (#141)
* docs: enrich readme files
1 parent 755e3a6 commit 9bfad84

File tree

3 files changed

+98
-5
lines changed

3 files changed

+98
-5
lines changed

.changeset/proud-melons-dress.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+
enrich readme files

README-en_US.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44

55
English | <a href="https://github.com/openapi-ui/openapi-ts-request/blob/master/README.md">简体中文</a>
66

7-
Generate TS interfaces, request client, request mock service, enum, type field label, JSON Schemas based on [Swagger2/OpenAPI3/Apifox](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) specification
7+
based on [Swagger2/OpenAPI3/Apifox](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) specification Generate
88

9-
文档:[use docs](https://github.com/openapi-ui/openapi-ts-request/issues/100)
9+
- TS interfaces
10+
- request client
11+
- request mock service
12+
- enum and enum translation
13+
- type field label
14+
- JSON Schemas
15+
16+
docs:[use docs](https://github.com/openapi-ui/openapi-ts-request/issues/100)
1017

1118
## Features
1219

@@ -38,6 +45,8 @@ create `openapi-ts-request.config.ts` file in the project root directory
3845
import type { GenerateServiceProps } from 'openapi-ts-request';
3946

4047
export default {
48+
// schemaPath: './openapi.json', // local openapi file
49+
// serversPath: './src/apis', // interface storage path
4150
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
4251
} as GenerateServiceProps;
4352
```
@@ -61,12 +70,47 @@ export default [
6170

6271
add the command in `script` of `package.json`: `"openapi": "openapi-ts",`
6372

64-
generate result:
73+
run:
6574

6675
```bash
6776
npm run openapi
6877
```
6978

79+
generate result:
80+
81+
```bash
82+
src/apis/index.ts #interface entry file
83+
src/apis/types.ts #type definition file
84+
src/apis/app #app interface
85+
```
86+
87+
```typescript
88+
// src/apis/pet.ts
89+
90+
/* eslint-disable */
91+
// @ts-ignore
92+
import request from 'axios';
93+
94+
import * as API from './types';
95+
96+
/** Update an existing pet PUT /pet */
97+
export async function updatePet(
98+
body: API.Pet,
99+
options?: { [key: string]: unknown }
100+
) {
101+
return request<unknown>(`/pet`, {
102+
method: 'PUT',
103+
headers: {
104+
'Content-Type': 'application/json',
105+
},
106+
data: body,
107+
...(options || {}),
108+
});
109+
}
110+
111+
// ... more interfaces
112+
```
113+
70114
### JS
71115

72116
create a new `openapi-ts-request.config.js` file in any directory `xxx/xxx`

README.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55
<a href="https://github.com/openapi-ui/openapi-ts-request/blob/master/README-en_US.md">English</a> | 简体中文
66

7-
根据 [Swagger2/OpenAPI3/Apifox](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) 文档生成 TS 类型, 客户端请求函数, 模拟请求响应服务, 枚举, 类型字段翻译, JSON Schemas
7+
根据 [Swagger2/OpenAPI3/Apifox](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) 文档生成:
8+
9+
- TS 类型
10+
- 客户端请求函数
11+
- 模拟请求响应服务
12+
- 枚举和枚举翻译
13+
- 类型字段翻译
14+
- JSON Schemas
815

916
文档:[使用手册](https://github.com/openapi-ui/openapi-ts-request/issues/100)
1017

@@ -38,6 +45,8 @@ pnpm i openapi-ts-request -D
3845
import type { GenerateServiceProps } from 'openapi-ts-request';
3946

4047
export default {
48+
// schemaPath: './openapi.json', // 本地openapi文件
49+
// serversPath: './src/apis', // 接口存放路径
4150
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
4251
} as GenerateServiceProps;
4352
```
@@ -61,12 +70,47 @@ export default [
6170

6271
`package.json``script` 中添加命令: `"openapi": "openapi-ts",`
6372

64-
生成结果
73+
运行
6574

6675
```bash
6776
npm run openapi
6877
```
6978

79+
生成的接口:
80+
81+
```bash
82+
src/apis/index.ts #接口入口文件
83+
src/apis/types.ts #类型定义文件
84+
src/apis/pet.ts #接口文件
85+
```
86+
87+
```typescript
88+
// src/apis/pet.ts
89+
90+
/* eslint-disable */
91+
// @ts-ignore
92+
import request from 'axios';
93+
94+
import * as API from './types';
95+
96+
/** Update an existing pet PUT /pet */
97+
export async function updatePet(
98+
body: API.Pet,
99+
options?: { [key: string]: unknown }
100+
) {
101+
return request<unknown>(`/pet`, {
102+
method: 'PUT',
103+
headers: {
104+
'Content-Type': 'application/json',
105+
},
106+
data: body,
107+
...(options || {}),
108+
});
109+
}
110+
111+
// ... 其他接口
112+
```
113+
70114
### JS
71115

72116
任意目录 `xxx/xxx` 新建 `openapi-ts-request.config.js`

0 commit comments

Comments
 (0)