Skip to content

Commit

Permalink
refactor: release 3.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
yangqianjun committed Jul 16, 2021
1 parent f67af6e commit 5248808
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 25 deletions.
65 changes: 64 additions & 1 deletion GettingStarted.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,70 @@ Autos 支持交互勾选界面、增量同步远程增、删、改差异到本
- 直接进入下一步
- Autos 调用 Swagger Codegen 生成目标代码

## 5. CHANGELOG
## 5. 简洁模式

从 3.5.4 版本起,当配置 `swaggerParser['-t']` 参数为 `'plugins/typescript-tkit-autos'` 时,Autos 会生成通过 url 调用的类型安全的 service 代码,如以下示例所示:

```ts
import { ExtraFetchParams } from '@ajax';
import * as models from '../model/models';

declare global {
interface AutosAPIS {
'GET /ts-boilerplate/api/user/info': [
(
| []
| [
{
opt?: ExtraFetchParams;
}
]
),
models.UserInfo
];
}
}
```

此时,我们需要使用新版的框架配套的 ajax 或者自行实现 `autosFetch`,如以下示例所示:

```ts
declare global {
interface AutosAPIS {
/** 测试接口 */
'DEMO /ajax/test': [[{}], {}];
}
}
// ...
function autosFetch<S extends keyof AutosAPIS>(
source: S,
...args: AutosAPIS[S][0]
): Promise<AutosAPIS[S][1]> {
const { isFile, opt, ...config } = (args[0] || {}) as AutosParams;
let { headers = {} } = opt || {};
if (isFile) {
headers = {
...headers,
'Content-Type': 'multipart/form-data'
};
}
// ...
}
```

如此,我们就可以直接通过 url 调用 service 代码,如以下示例所示(tCall 需要更新 redux-model 到最新的版本):

```ts
function* test() {
const data = autosFetch('POST /ts-boilerplate/api/download');
const res: AutosAPIS['POST /ts-boilerplate/api/download'][1] = yield tCall(
autosFetch,
'POST /ts-boilerplate/api/download'
);
}
```

## 6. CHANGELOG

import CHANGELOG from './CHANGELOG.md';

Expand Down
14 changes: 7 additions & 7 deletions docs/assets.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"vendors.js": "/auto-service/static/js/vendors.35ef962c.js",
"vendors.js.map": "/auto-service/static/js/vendors.142fc463e245acba841b.js.map",
"app.js": "/auto-service/static/js/app.142fc463e245acba841b.js",
"app.js.map": "/auto-service/static/js/app.142fc463e245acba841b.js.map",
"getting-started.js": "/auto-service/static/js/getting-started.59de2712.js",
"getting-started.js.map": "/auto-service/static/js/getting-started.142fc463e245acba841b.js.map",
"vendors.js.map": "/auto-service/static/js/vendors.3d171d7da211e5a3c26a.js.map",
"app.js": "/auto-service/static/js/app.3d171d7da211e5a3c26a.js",
"app.js.map": "/auto-service/static/js/app.3d171d7da211e5a3c26a.js.map",
"getting-started.js": "/auto-service/static/js/getting-started.d38d6af0.js",
"getting-started.js.map": "/auto-service/static/js/getting-started.3d171d7da211e5a3c26a.js.map",
"readme.js": "/auto-service/static/js/readme.d1053ec1.js",
"readme.js.map": "/auto-service/static/js/readme.142fc463e245acba841b.js.map",
"readme.js.map": "/auto-service/static/js/readme.3d171d7da211e5a3c26a.js.map",
"src-validate-readme.js": "/auto-service/static/js/src-validate-readme.77f332ac.js",
"src-validate-readme.js.map": "/auto-service/static/js/src-validate-readme.142fc463e245acba841b.js.map",
"src-validate-readme.js.map": "/auto-service/static/js/src-validate-readme.3d171d7da211e5a3c26a.js.map",
"index.html": "/auto-service/index.html",
"static/img/logo.png": "/auto-service/static/img/logo.f34d6017.png",
"static/img/swagger.png": "/auto-service/static/img/swagger.fcc098d8.png"
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="description" content="auto generate swagger or yapi mock to typescript services and models"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Autos</title><link rel="icon" type="image/x-icon" href="https://cdn-std.dprcdn.net/files/acc_649651/LUKiMl"></head><body><div id="root"></div><script src="/auto-service/static/js/vendors.35ef962c.js"></script><script src="/auto-service/static/js/app.142fc463e245acba841b.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="description" content="auto generate swagger or yapi mock to typescript services and models"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Autos</title><link rel="icon" type="image/x-icon" href="https://cdn-std.dprcdn.net/files/acc_649651/LUKiMl"></head><body><div id="root"></div><script src="/auto-service/static/js/vendors.35ef962c.js"></script><script src="/auto-service/static/js/app.3d171d7da211e5a3c26a.js"></script></body></html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/static/js/getting-started.142fc463e245acba841b.js.map

This file was deleted.

1 change: 1 addition & 0 deletions docs/static/js/getting-started.3d171d7da211e5a3c26a.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions docs/static/js/getting-started.59de2712.js

This file was deleted.

2 changes: 2 additions & 0 deletions docs/static/js/getting-started.d38d6af0.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/static/js/readme.d1053ec1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/static/js/src-validate-readme.77f332ac.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/static/js/vendors.35ef962c.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-service",
"version": "3.5.3",
"version": "3.5.4",
"description": "auto generate swagger or yapi mock to typescript services and models",
"repository": "[email protected]:gogoyqj/auto-service.git",
"author": "杨乾军 <yang@yang>",
Expand Down
Binary file modified plugins/swagger-codegen-cli.jar
Binary file not shown.
19 changes: 15 additions & 4 deletions plugins/typescript-tkit-autos/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ import * as models from '../model/models';
declare global {
interface AutosAPIS {
{{#operation}}
{{#description}}/** {{&description}} */{{/description}}
'{{httpMethod}} {{{contextPath}}}{{{path}}}': [[
/**
* {{&notes}}
{{#summary}}
* @summary {{&summary}}
{{/summary}}
{{#description}}
* {{&description}}
{{/description}}
*/
'{{httpMethod}} {{{contextPath}}}{{{path}}}': [{{#hasNoParams}}
[] |
{{/hasNoParams}}[
{
opt?: {{^headerParams.0}}ExtraFetchParams{{/headerParams.0}}{{#headerParams.0}}{ headers: ParamsHeader{{nickname}} } & Omit<ExtraFetchParams, 'headers'> {{/headerParams.0}}
{{^headerParams.0}}opt?: ExtraFetchParams{{/headerParams.0}}{{#headerParams.0}}opt: { headers: ParamsHeader{{nickname}} } & Omit<ExtraFetchParams, 'headers'> {{/headerParams.0}}
{{#queryParams.0}}
query: {
{{#queryParams}}
Expand Down Expand Up @@ -56,7 +66,8 @@ declare global {
{{/bodyParam}}
};
{{/bodyParam.0}}
}], {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}];
}
], {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}];
{{/operation}}
}
}
Expand Down
8 changes: 8 additions & 0 deletions plugins/typescript-tkit-autos/apis.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{#apiInfo}}
{{#apis}}
{{#operations}}
export * from './{{ classFilename }}';
{{/operations}}
{{/apis}}
{{/apiInfo}}
throw Error('禁止运行时引入 apis.ts !!!');
3 changes: 2 additions & 1 deletion plugins/typescript-tkit-autos/index.mustache
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './api/api';
export * from './model/models';
export * from './model/models';
throw Error('禁止运行时引入 index.ts !!!');
3 changes: 2 additions & 1 deletion plugins/typescript-tkit-autos/models.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export * from './{{{ classFilename }}}';
{{/models}}
export type ModelInteger = number;
export type ModelFloat = number;
export type LocalDate = Date;
export type LocalDate = Date;
throw Error('禁止运行时引入 models.ts !!!');

0 comments on commit 5248808

Please sign in to comment.