@@ -14,6 +14,7 @@ const examplesDir = path.join(__dirname, 'examples');
14
14
15
15
let petstoreSdk ;
16
16
let readmeSdk ;
17
+ let operationIdsSDK ;
17
18
const petstoreServerUrl = 'http://petstore.swagger.io/api' ;
18
19
19
20
beforeEach ( async ( ) => {
@@ -26,6 +27,10 @@ beforeEach(async () => {
26
27
require . resolve ( '@readme/oas-examples/3.0/json/readme.json' ) ,
27
28
'utf8'
28
29
) ,
30
+ [ `${ [ examplesDir ] } /operation-ids.json` ] : await realFs . readFile (
31
+ require . resolve ( './__fixtures__/operation-ids.oas.json' ) ,
32
+ 'utf8'
33
+ ) ,
29
34
[ `${ [ examplesDir ] } /uspto.json` ] : await realFs . readFile (
30
35
require . resolve ( '@readme/oas-examples/3.0/json/uspto.json' ) ,
31
36
'utf8'
@@ -39,6 +44,10 @@ beforeEach(async () => {
39
44
const readme = path . join ( examplesDir , 'readme.json' ) ;
40
45
await new Cache ( readme ) . saveFile ( ) ;
41
46
readmeSdk = api ( readme ) ;
47
+
48
+ const operationIds = path . join ( examplesDir , 'operation-ids.json' ) ;
49
+ await new Cache ( readme ) . saveFile ( ) ;
50
+ operationIdsSDK = api ( operationIds ) ;
42
51
} ) ;
43
52
44
53
afterEach ( ( ) => {
@@ -79,8 +88,11 @@ describe('#preloading', () => {
79
88
'head' ,
80
89
'patch' ,
81
90
'trace' ,
91
+ 'listDataSets' ,
82
92
'list-data-sets' ,
93
+ 'listSearchableFields' ,
83
94
'list-searchable-fields' ,
95
+ 'performSearch' ,
84
96
'perform-search' ,
85
97
] ) ;
86
98
@@ -113,8 +125,26 @@ describe('#accessors', () => {
113
125
} ) . not . toThrow ( ) ;
114
126
} ) ;
115
127
116
- it ( 'should work with operationIds that have contain spaces' , ( ) => {
117
- expect ( typeof petstoreSdk [ 'find pet by id' ] ) . toBe ( 'function' ) ;
128
+ it ( 'should work with operationIds that have contain spaces' , async ( ) => {
129
+ const mock = nock ( petstoreServerUrl ) . get ( '/pets/1234' ) . twice ( ) . reply ( 200 , 'it worked!' ) ;
130
+
131
+ await expect ( petstoreSdk [ 'find pet by id' ] ( { id : 1234 } ) ) . resolves . toBe ( 'it worked!' ) ;
132
+
133
+ // Because we don't want people using ugly operationIDs like the above we transform them into
134
+ // JS-friendly method accessors also.
135
+ await expect ( petstoreSdk . findPetById ( { id : 1234 } ) ) . resolves . toBe ( 'it worked!' ) ;
136
+ mock . done ( ) ;
137
+ } ) ;
138
+
139
+ it ( 'should work with operationIds that contain hyphens' , async ( ) => {
140
+ const mock = nock ( 'https://httpbin.org' ) . get ( '/anything' ) . twice ( ) . reply ( 200 , 'it worked!' ) ;
141
+
142
+ await expect ( operationIdsSDK [ 'get-pet' ] ( ) ) . resolves . toBe ( 'it worked!' ) ;
143
+
144
+ // Because we don't want people using ugly operationIDs like the above we transform them into
145
+ // JS-friendly method accessors also.
146
+ await expect ( operationIdsSDK . getPet ( ) ) . resolves . toBe ( 'it worked!' ) ;
147
+ mock . done ( ) ;
118
148
} ) ;
119
149
120
150
it ( 'should work for other methods' , ( ) => {
0 commit comments