@@ -14,6 +14,7 @@ const examplesDir = path.join(__dirname, 'examples');
1414
1515let petstoreSdk ;
1616let readmeSdk ;
17+ let operationIdsSDK ;
1718const petstoreServerUrl = 'http://petstore.swagger.io/api' ;
1819
1920beforeEach ( async ( ) => {
@@ -26,6 +27,10 @@ beforeEach(async () => {
2627 require . resolve ( '@readme/oas-examples/3.0/json/readme.json' ) ,
2728 'utf8'
2829 ) ,
30+ [ `${ [ examplesDir ] } /operation-ids.json` ] : await realFs . readFile (
31+ require . resolve ( './__fixtures__/operation-ids.oas.json' ) ,
32+ 'utf8'
33+ ) ,
2934 [ `${ [ examplesDir ] } /uspto.json` ] : await realFs . readFile (
3035 require . resolve ( '@readme/oas-examples/3.0/json/uspto.json' ) ,
3136 'utf8'
@@ -39,6 +44,10 @@ beforeEach(async () => {
3944 const readme = path . join ( examplesDir , 'readme.json' ) ;
4045 await new Cache ( readme ) . saveFile ( ) ;
4146 readmeSdk = api ( readme ) ;
47+
48+ const operationIds = path . join ( examplesDir , 'operation-ids.json' ) ;
49+ await new Cache ( readme ) . saveFile ( ) ;
50+ operationIdsSDK = api ( operationIds ) ;
4251} ) ;
4352
4453afterEach ( ( ) => {
@@ -79,8 +88,11 @@ describe('#preloading', () => {
7988 'head' ,
8089 'patch' ,
8190 'trace' ,
91+ 'listDataSets' ,
8292 'list-data-sets' ,
93+ 'listSearchableFields' ,
8394 'list-searchable-fields' ,
95+ 'performSearch' ,
8496 'perform-search' ,
8597 ] ) ;
8698
@@ -113,8 +125,26 @@ describe('#accessors', () => {
113125 } ) . not . toThrow ( ) ;
114126 } ) ;
115127
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 ( ) ;
118148 } ) ;
119149
120150 it ( 'should work for other methods' , ( ) => {
0 commit comments