Skip to content

Commit 62f63ad

Browse files
committed
test: 优化 jsDoc 多行显示
1 parent adfdfdd commit 62f63ad

File tree

6 files changed

+115
-11
lines changed

6 files changed

+115
-11
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
- [ ] 3.1 的完全支持 https://www.apimatic.io/blog/2021/09/migrating-to-and-from-openapi-3-1
1212
- [ ] 支持 query 多参格式 https://swagger.io/docs/specification/serialization/
1313
- [ ] 支持忽略未显式在 path 中的参数
14-
- [ ] 修正单值 JSDOC 位置 status: /**...*/ type -> /**...*/ status: type
14+
- [ ] 修正单根值类型提升

test/example-dest/3.0/pet-store.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* @version 1.0.19
44
* @contact <apiteam@swagger.io>
55
* @description This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
6-
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
7-
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
8-
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
9-
10-
Some useful links:
11-
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
12-
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
6+
* Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
7+
* You can now help us improve the API whether it's by making changes to the definition itself or to the code.
8+
* That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
9+
*
10+
* Some useful links:
11+
* - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
12+
* - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
1313
*/
1414

1515
import axios from "axios";

test/example-dest/3.1/pet-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @version 1.0.6
44
* @contact <apiteam@swagger.io>
55
* @description This is a sample Pet Store Server based on the OpenAPI 3.1 specification.
6-
You can find out more about
7-
Swagger at [http://swagger.io](http://swagger.io).
6+
* You can find out more about
7+
* Swagger at [http://swagger.io](http://swagger.io).
88
* @summary Pet Store 3.1
99
* @see {@link http://swagger.io Find out more about Swagger}
1010
*/

test/printer/arg.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Printer } from '../../src/printer';
2+
3+
test('top', () => {
4+
const printer = new Printer({
5+
openapi: '3.1.0',
6+
info: {
7+
title: 'test',
8+
version: '1.0.0',
9+
},
10+
paths: {
11+
'/': {
12+
get: {
13+
deprecated: true,
14+
description: 'aaa\nbbb\nccc',
15+
summary: 'test1',
16+
operationId: 'test2',
17+
requestBody: {
18+
content: {
19+
'*': {
20+
schema: {
21+
type: 'string',
22+
description: 'test4',
23+
deprecated: true,
24+
default: 'test5',
25+
example: 'test6',
26+
},
27+
},
28+
},
29+
},
30+
},
31+
},
32+
},
33+
});
34+
35+
expect(
36+
printer.print({
37+
hideImports: true,
38+
hideHeaders: true,
39+
hideFooters: true,
40+
hideInfo: true,
41+
hideHelpers: true,
42+
}),
43+
).toMatchInlineSnapshot(`
44+
"/**
45+
* @deprecated
46+
* @description aaa
47+
* bbb
48+
* ccc
49+
* @summary test1
50+
* @param data test4
51+
* @param [config] request config
52+
*/
53+
export async function test2(data:string,config?:AxiosRequestConfig): AxiosPromise<unknown> {
54+
return axios({
55+
method: "get",
56+
url: \`/\`,
57+
data: data,
58+
...config
59+
});
60+
}"
61+
`);
62+
});

test/printer/jsdoc.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { JsDoc } from '../../src/printer/JsDoc';
2+
3+
test('multiple', () => {
4+
const jsDoc = new JsDoc([
5+
{
6+
name: 't1',
7+
},
8+
{
9+
name: 't2',
10+
description: 't2 description',
11+
},
12+
{
13+
name: 't3',
14+
description: 't3 description 1\n\nt3 description 2',
15+
externalDocs: {
16+
url: 'https://example.com',
17+
description: 'external docs 1\nexternal docs 2',
18+
},
19+
},
20+
]);
21+
jsDoc.addComments({
22+
description: 'aaa\nbbb\nccc',
23+
deprecated: true,
24+
summary: 'summary',
25+
tags: ['t1', 't2', 't3'],
26+
});
27+
expect(jsDoc.print()).toMatchInlineSnapshot(`
28+
"/**
29+
* @description aaa
30+
* bbb
31+
* ccc
32+
* @deprecated
33+
* @summary summary
34+
* @see t1
35+
* @see t2 t2 description
36+
* @see t3 t3 description 1
37+
*
38+
* t3 description 2 {@link https://example.com external docs 1
39+
* external docs 2}
40+
*/"
41+
`);
42+
});

test/schemas/nullable.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test('nullable + array', () => {
4141
// console.log(type);
4242
expect(type).toMatchInlineSnapshot(`
4343
"{
44-
"t0":((T1[])|(null));
44+
"t0":((Array<T1>)|(null));
4545
}"
4646
`);
4747
});

0 commit comments

Comments
 (0)