Skip to content

Commit 2e553b0

Browse files
committed
docs: 增加参考文件
1 parent 6b24060 commit 2e553b0

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ openapi本地或者远程文件,支持格式:`yaml | json`
127127

128128
类的生成方式。
129129

130-
- `rest`,仅生成 **get|post|put|patch|delete** 几个方法,uri作为第一个参数传入
131-
- `rpc`,把 method+uri 拼接成一个新方法。
130+
- `rest`,仅生成 **get|post|put|patch|delete** 几个方法,uri作为第一个参数传入。参考:[rest-mode.js](./openapi/rest-mode.js)
131+
- `rpc`,把 method+uri 拼接成一个新方法。参考:[rpc-mode.js](./openapi/rpc-mode.js)
132132

133133
```typescript
134134
const client = new OpenapiClient();

openapi/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!*.js

openapi/rest-mode.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var OpenapiClient = class extends BaseOpenapiClient {
2+
get(uri, opts) {
3+
return this.request(uri, 'get', opts);
4+
}
5+
6+
post(uri, opts) {
7+
return this.request(uri, 'get', opts);
8+
}
9+
10+
put(uri, opts) {
11+
return this.request(uri, 'get', opts);
12+
}
13+
14+
delete(uri, opts) {
15+
return this.request(uri, 'get', opts);
16+
}
17+
18+
pickContentTypes(uri, method) {
19+
return contentTypesOpenapiClient[method + ' ' + uri] || [void 0, void 0];
20+
}
21+
};
22+
23+
const contentTypesOpenapiClient = {
24+
'put /users/avatar': ['multipart/form-data', void 0],
25+
};

openapi/rpc-mode.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var OpenapiClient = class extends BaseOpenapiClient {
2+
user = {
3+
getUsers: (opts) => {
4+
return this.request('/users', 'get', opts);
5+
},
6+
getUsersById: (opts) => {
7+
return this.request('/users/{id}', 'get', opts);
8+
},
9+
postUsers: (opts) => {
10+
return this.request('/users', 'post', opts);
11+
},
12+
postUsersV1: (opts) => {
13+
return this.request('/users/v1', 'post', opts);
14+
},
15+
putUsersById: (opts) => {
16+
return this.request('/users/{id}', 'put', opts);
17+
},
18+
putUsersAvatar: (opts) => {
19+
return this.request('/users/avatar', 'put', opts);
20+
},
21+
deleteUsersById: (opts) => {
22+
return this.request('/users/{id}', 'delete', opts);
23+
},
24+
};
25+
26+
pickContentTypes(uri, method) {
27+
return contentTypesOpenapiClient[method + ' ' + uri] || [void 0, void 0];
28+
}
29+
};
30+
31+
const contentTypesOpenapiClient = {
32+
'put /users/avatar': ['multipart/form-data', void 0],
33+
};

0 commit comments

Comments
 (0)