@@ -35,6 +35,7 @@ const docs = getBasicDocument({
3535 } ,
3636 { $ref : '#/components/parameters/refA' } ,
3737 { $ref : '#/components/parameters/refB' } ,
38+ { $ref : '#/components/parameters/refC' } ,
3839 ] ,
3940 } ,
4041 } ,
@@ -54,12 +55,18 @@ docs.components = {
5455 required : true ,
5556 schema : { type : 'integer' } ,
5657 } ,
58+ refC : {
59+ name : 'ref_c' ,
60+ in : 'path' ,
61+ required : true ,
62+ schema : { type : 'integer' , nullable : true } ,
63+ } ,
5764 } ,
5865} ;
5966
6067test ( '解析查询字符串' , ( ) => {
61- const result = parseParameters ( docs , docs . paths [ '/' ] ! , docs . paths [ '/' ] ! . get ! , 'query' ) ;
62- expect ( result ) . toMatchInlineSnapshot ( `
68+ expect ( parseParameters ( docs , docs . paths [ '/' ] ! , docs . paths [ '/' ] ! . get ! , 'query' , false ) )
69+ . toMatchInlineSnapshot ( `
6370 {
6471 "optional": false,
6572 "types": [
@@ -74,21 +81,55 @@ test('解析查询字符串', () => {
7481 ],
7582 }
7683 ` ) ;
84+
85+ expect ( parseParameters ( docs , docs . paths [ '/' ] ! , docs . paths [ '/' ] ! . get ! , 'query' , true ) )
86+ . toMatchInlineSnapshot ( `
87+ {
88+ "optional": false,
89+ "types": [
90+ "{ foo: (number | string.Number)
91+ ;
92+ bar?: (number | string.Number)
93+ ;
94+ ref_a?: (number | string.Number)
95+ ;
96+ bazz: (string)
97+ }",
98+ ],
99+ }
100+ ` ) ;
77101} ) ;
78102
79103test ( '解析路径参数' , ( ) => {
80- const result = parseParameters ( docs , docs . paths [ '/' ] ! , docs . paths [ '/' ] ! . get ! , 'path' ) ;
81- expect ( result ) . toMatchInlineSnapshot ( `
82- {
83- "optional": false,
84- "types": [
85- "{ id: (number)
86- ;
87- ref_b: (number)
88- }",
89- ],
90- }
91- ` ) ;
104+ expect ( parseParameters ( docs , docs . paths [ '/' ] ! , docs . paths [ '/' ] ! . get ! , 'path' , false ) )
105+ . toMatchInlineSnapshot ( `
106+ {
107+ "optional": false,
108+ "types": [
109+ "{ id: (number)
110+ ;
111+ ref_b: (number)
112+ ;
113+ ref_c: (number | null)
114+ }",
115+ ],
116+ }
117+ ` ) ;
118+
119+ expect ( parseParameters ( docs , docs . paths [ '/' ] ! , docs . paths [ '/' ] ! . get ! , 'path' , true ) )
120+ . toMatchInlineSnapshot ( `
121+ {
122+ "optional": false,
123+ "types": [
124+ "{ id: (number | string.Number)
125+ ;
126+ ref_b: (number | string.Number)
127+ ;
128+ ref_c: (number | string.Number | null)
129+ }",
130+ ],
131+ }
132+ ` ) ;
92133} ) ;
93134
94135test ( '未找到参数则变成可选' , ( ) => {
0 commit comments