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 11{
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"
2120 }
22- ],
23- "get" : {
24- "summary" : " Get anything" ,
25- "description" : " " ,
26- "responses" : {}
2721 },
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" ,
4625 "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+ }
5328 }
29+ ],
30+ "get" : {
31+ "summary" : " Get anything" ,
32+ "description" : " " ,
33+ "responses" : {}
5434 },
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."
6560 }
6661 }
6762 }
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');
33const Oas = require ( 'oas' ) ;
44
55const oasToHar = require ( '../src/index' ) ;
6+ const commonParameters = require ( './fixtures/common-parameters' ) ;
67
78const oas = new Oas ( ) ;
89
@@ -1111,6 +1112,32 @@ describe('formData values', () => {
11111112 } ) ;
11121113} ) ;
11131114
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+
11141141describe ( 'auth' , ( ) => {
11151142 it ( 'should work for header' , ( ) => {
11161143 expect (
Original file line number Diff line number Diff line change @@ -88,6 +88,18 @@ module.exports = (
8888 har . url = `https://try.readme.io/${ har . url } ` ;
8989 }
9090
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+
91103 if ( pathOperation . parameters ) {
92104 pathOperation . parameters . forEach ( ( param , i , params ) => {
93105 if ( param . $ref ) {
You can’t perform that action at this time.
0 commit comments