This repository was archived by the owner on Nov 28, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +147
-58
lines changed Expand file tree Collapse file tree 4 files changed +147
-58
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "openapi" : " 3.0.0" ,
3
- "servers" : [
4
- {
5
- "url" : " http://httpbin.org"
6
- }
7
- ],
8
- "info" : {
9
- "version" : " 1.0.0" ,
10
- "title" : " An example of how we render $ref usage on resource parameters"
11
- },
12
- "paths" : {
13
- "/anything/{id}" : {
14
- "parameters" : [
15
- {
16
- "in" : " path" ,
17
- "name" : " id" ,
18
- "schema" : {
19
- "type" : " number"
20
- }
2
+ "openapi" : " 3.0.0" ,
3
+ "servers" : [
4
+ {
5
+ "url" : " http://httpbin.org"
6
+ }
7
+ ],
8
+ "info" : {
9
+ "version" : " 1.0.0" ,
10
+ "title" : " An example of how we render $ref usage on resource parameters"
11
+ },
12
+ "paths" : {
13
+ "/anything/{id}" : {
14
+ "parameters" : [
15
+ {
16
+ "in" : " path" ,
17
+ "name" : " id" ,
18
+ "schema" : {
19
+ "type" : " number"
21
20
}
22
- ],
23
- "get" : {
24
- "summary" : " Get anything" ,
25
- "description" : " " ,
26
- "responses" : {}
27
21
},
28
- "post" : {
29
- "summary" : " Post anything" ,
30
- "description" : " " ,
31
- "parameters" : [
32
- {
33
- "$ref" : " #/components/parameters/limitParam"
34
- }
35
- ],
36
- "responses" : {}
37
- }
38
- }
39
- },
40
- "components" : {
41
- "parameters" : {
42
- "limitParam" : {
43
- "in" : " query" ,
44
- "name" : " limit" ,
45
- "required" : false ,
22
+ {
23
+ "in" : " header" ,
24
+ "name" : " x-extra-id" ,
46
25
"schema" : {
47
- "type" : " integer" ,
48
- "minimum" : 1 ,
49
- "maximum" : 50 ,
50
- "default" : 20
51
- },
52
- "description" : " The numbers of items to return."
26
+ "type" : " string"
27
+ }
53
28
}
29
+ ],
30
+ "get" : {
31
+ "summary" : " Get anything" ,
32
+ "description" : " " ,
33
+ "responses" : {}
54
34
},
55
- "schemas" : {
56
- "string_enum" : {
57
- "name" : " string" ,
58
- "enum" : [
59
- " available" ,
60
- " pending" ,
61
- " sold"
62
- ],
63
- "type" : " string"
64
- }
35
+ "post" : {
36
+ "summary" : " Post anything" ,
37
+ "description" : " " ,
38
+ "parameters" : [
39
+ {
40
+ "$ref" : " #/components/parameters/limitParam"
41
+ }
42
+ ],
43
+ "responses" : {}
44
+ }
45
+ }
46
+ },
47
+ "components" : {
48
+ "parameters" : {
49
+ "limitParam" : {
50
+ "in" : " query" ,
51
+ "name" : " limit" ,
52
+ "required" : false ,
53
+ "schema" : {
54
+ "type" : " integer" ,
55
+ "minimum" : 1 ,
56
+ "maximum" : 50 ,
57
+ "default" : 20
58
+ },
59
+ "description" : " The numbers of items to return."
65
60
}
66
61
}
67
62
}
63
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "openapi" : " 3.0.0" ,
3
+ "servers" : [
4
+ {
5
+ "url" : " http://httpbin.org"
6
+ }
7
+ ],
8
+ "paths" : {
9
+ "/anything/{id}" : {
10
+ "parameters" : [
11
+ {
12
+ "in" : " path" ,
13
+ "name" : " id" ,
14
+ "schema" : {
15
+ "type" : " number"
16
+ }
17
+ },
18
+ {
19
+ "in" : " header" ,
20
+ "name" : " x-extra-id" ,
21
+ "schema" : {
22
+ "type" : " string"
23
+ }
24
+ }
25
+ ],
26
+ "post" : {
27
+ "summary" : " Post anything" ,
28
+ "description" : " " ,
29
+ "parameters" : [
30
+ {
31
+ "$ref" : " #/components/parameters/limitParam"
32
+ }
33
+ ],
34
+ "responses" : {}
35
+ }
36
+ }
37
+ },
38
+ "components" : {
39
+ "parameters" : {
40
+ "limitParam" : {
41
+ "in" : " query" ,
42
+ "name" : " limit" ,
43
+ "required" : false ,
44
+ "schema" : {
45
+ "type" : " integer" ,
46
+ "minimum" : 1 ,
47
+ "maximum" : 50 ,
48
+ "default" : 20
49
+ },
50
+ "description" : " The numbers of items to return."
51
+ }
52
+ }
53
+ }
54
+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ const extensions = require('@readme/oas-extensions');
3
3
const Oas = require ( 'oas' ) ;
4
4
5
5
const oasToHar = require ( '../src/index' ) ;
6
+ const commonParameters = require ( './fixtures/common-parameters' ) ;
6
7
7
8
const oas = new Oas ( ) ;
8
9
@@ -1111,6 +1112,32 @@ describe('formData values', () => {
1111
1112
} ) ;
1112
1113
} ) ;
1113
1114
1115
+ describe ( 'common parameters' , ( ) => {
1116
+ it ( 'should work for common parameters' , ( ) => {
1117
+ expect (
1118
+ oasToHar (
1119
+ new Oas ( commonParameters ) ,
1120
+ {
1121
+ ...commonParameters . paths [ '/anything/{id}' ] . post ,
1122
+ path : '/anything/{id}' ,
1123
+ method : 'post' ,
1124
+ } ,
1125
+ {
1126
+ path : { id : 1234 } ,
1127
+ header : { 'x-extra-id' : 'abcd' } ,
1128
+ query : { limit : 10 } ,
1129
+ } ,
1130
+ ) . log . entries [ 0 ] . request ,
1131
+ ) . toStrictEqual ( {
1132
+ headers : [ { name : 'x-extra-id' , value : 'abcd' } ] ,
1133
+ queryString : [ { name : 'limit' , value : '10' } ] ,
1134
+ postData : { } ,
1135
+ method : 'POST' ,
1136
+ url : 'http://httpbin.org/anything/1234' ,
1137
+ } ) ;
1138
+ } ) ;
1139
+ } ) ;
1140
+
1114
1141
describe ( 'auth' , ( ) => {
1115
1142
it ( 'should work for header' , ( ) => {
1116
1143
expect (
Original file line number Diff line number Diff line change @@ -88,6 +88,18 @@ module.exports = (
88
88
har . url = `https://try.readme.io/${ har . url } ` ;
89
89
}
90
90
91
+ if ( ! pathOperation . parameters ) {
92
+ // eslint-disable-next-line no-param-reassign
93
+ pathOperation . parameters = [ ] ;
94
+ }
95
+
96
+ // Does this operation have any common parameters?
97
+ if ( oas . paths && oas . paths [ pathOperation . path ] && oas . paths [ pathOperation . path ] . parameters ) {
98
+ oas . paths [ pathOperation . path ] . parameters . forEach ( param => {
99
+ pathOperation . parameters . push ( param ) ;
100
+ } ) ;
101
+ }
102
+
91
103
if ( pathOperation . parameters ) {
92
104
pathOperation . parameters . forEach ( ( param , i , params ) => {
93
105
if ( param . $ref ) {
You can’t perform that action at this time.
0 commit comments