Skip to content

Commit cfa4232

Browse files
committed
refactor: 配置名path重命名为url
BREAKING CHANGE: 配置名path改为url
1 parent 101fe88 commit cfa4232

File tree

7 files changed

+21
-23
lines changed

7 files changed

+21
-23
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { defineConfig } from 'foca-openapi';
2727

2828
export default defineConfig({
2929
// 可以是本地路径,也可以是远程地址
30-
path: 'http://domain.com/openapi.json',
30+
url: 'http://domain.com/openapi.json',
3131
});
3232
```
3333

@@ -73,12 +73,12 @@ import { defineConfig } from 'foca-openapi';
7373

7474
export default defineConfig([
7575
{
76-
path: 'http://domain.com/openapi_1.json',
76+
url: 'http://domain.com/openapi_1.json',
7777
// 项目名称,必须是唯一的值
7878
projectName: 'foo',
7979
},
8080
{
81-
path: 'http://domain.com/openapi_2.json',
81+
url: 'http://domain.com/openapi_2.json',
8282
// 项目名称,必须是唯一的值
8383
projectName: 'bar',
8484
},
@@ -110,7 +110,7 @@ import { defineConfig } from 'foca-openapi';
110110

111111
export default defineConfig((env) => {
112112
return {
113-
path:
113+
url:
114114
env === 'production'
115115
? 'https://api.com/openapi.json'
116116
: 'http://localhost:3000/openapi.json',
@@ -120,7 +120,7 @@ export default defineConfig((env) => {
120120

121121
# 参数
122122

123-
### path
123+
### url
124124

125125
类型:`string`<br>
126126

openapi.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineConfig } from './src/define-config';
22

33
export default defineConfig({
4-
path: './openapi/openapi.json',
4+
url: './openapi/openapi.json',
55
});

src/bin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ spinner.add({
4747
title: '获取openapi文档',
4848
task: async (ctx) => {
4949
ctx.docs = await Promise.all(
50-
ctx.configs.map((config) => pathToOpenapi(config.path, config.onDocumentLoaded)),
50+
ctx.configs.map((config) => pathToOpenapi(config.url, config.onDocumentLoaded)),
5151
);
5252
await sleep();
5353
},

src/define-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface OpenapiClientConfig {
44
/**
55
* openapi本地或者远程文件,支持格式:`yaml | json`
66
*/
7-
path: string;
7+
url: string;
88
/**
99
* 过滤指定路由前缀的接口
1010
*/

test/lib/filter-tag.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ test('未指定过滤标签则不处理', () => {
1111
},
1212
});
1313

14-
filterTag(docs, { path: '' });
14+
filterTag(docs, { url: '' });
1515
expect(Object.keys(docs.paths['/'] || {})).toMatchInlineSnapshot(`
1616
[
1717
"get",
1818
"post",
1919
"put",
2020
]
2121
`);
22-
filterTag(docs, { path: '', includeTag: [] });
22+
filterTag(docs, { url: '', includeTag: [] });
2323
expect(Object.keys(docs.paths['/'] || {})).toMatchInlineSnapshot(`
2424
[
2525
"get",
@@ -38,7 +38,7 @@ test('未提供标签的接口会被删除', () => {
3838
},
3939
});
4040

41-
filterTag(docs, { path: '', includeTag: 'abc' });
41+
filterTag(docs, { url: '', includeTag: 'abc' });
4242
expect(Object.keys(docs.paths['/'] || {})).toMatchInlineSnapshot(`
4343
[
4444
"post",
@@ -57,7 +57,7 @@ test('不符合的标签被删除', () => {
5757
},
5858
});
5959

60-
filterTag(docs, { path: '', includeTag: 'def' });
60+
filterTag(docs, { url: '', includeTag: 'def' });
6161
expect(Object.keys(docs.paths['/'] || {})).toMatchInlineSnapshot(`
6262
[
6363
"put",
@@ -77,7 +77,7 @@ test('同时过滤多个标签', () => {
7777
},
7878
});
7979

80-
filterTag(docs, { path: '', includeTag: ['mn', 'def'] });
80+
filterTag(docs, { url: '', includeTag: ['mn', 'def'] });
8181
expect(Object.keys(docs.paths['/'] || {})).toMatchInlineSnapshot(`
8282
[
8383
"put",

test/lib/filter-url.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('未指定过滤路由则不处理', () => {
1010
'/other': {},
1111
});
1212

13-
filterUrl(docs, { path: '' });
13+
filterUrl(docs, { url: '' });
1414
expect(Object.keys(docs.paths)).toMatchInlineSnapshot(`
1515
[
1616
"/",
@@ -19,7 +19,7 @@ test('未指定过滤路由则不处理', () => {
1919
"/other",
2020
]
2121
`);
22-
filterUrl(docs, { path: '', includeUriPrefix: [] });
22+
filterUrl(docs, { url: '', includeUriPrefix: [] });
2323
expect(Object.keys(docs.paths)).toMatchInlineSnapshot(`
2424
[
2525
"/",
@@ -38,7 +38,7 @@ test('不符合前缀的路由被删除', () => {
3838
'/other': {},
3939
});
4040

41-
filterUrl(docs, { path: '', includeUriPrefix: '/test' });
41+
filterUrl(docs, { url: '', includeUriPrefix: '/test' });
4242
expect(Object.keys(docs.paths)).toMatchInlineSnapshot(`
4343
[
4444
"/test/a",
@@ -56,7 +56,7 @@ test('同时过滤多个路由', () => {
5656
'/foo/bar': {},
5757
});
5858

59-
filterUrl(docs, { path: '', includeUriPrefix: ['/test', '/foo'] });
59+
filterUrl(docs, { url: '', includeUriPrefix: ['/test', '/foo'] });
6060
expect(Object.keys(docs.paths)).toMatchInlineSnapshot(`
6161
[
6262
"/test/a",
@@ -75,7 +75,7 @@ test('支持正则表达式', () => {
7575
'/foo/bar': {},
7676
});
7777

78-
filterUrl(docs, { path: '', includeUriPrefix: [/\/a/] });
78+
filterUrl(docs, { url: '', includeUriPrefix: [/\/a/] });
7979
expect(Object.keys(docs.paths)).toMatchInlineSnapshot(`
8080
[
8181
"/test/a",

test/lib/read-config.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import { readConfig } from '../../src/lib/read-config';
33

44
test('从根目录获取', async () => {
55
expect(readConfig()).toMatchInlineSnapshot(`
6-
[
7-
{
8-
"path": "./openapi/openapi.json",
9-
},
10-
]
6+
{
7+
"url": "./openapi/openapi.json",
8+
}
119
`);
1210
});

0 commit comments

Comments
 (0)