acacode / swagger-typescript-api

Generate the API Client for Fetch or Axios from an OpenAPI Specification
MIT License
3.38k stars 361 forks source link

Generated api class is hard to spy on #986

Open Sczlog opened 3 days ago

Sczlog commented 3 days ago

Current

In sta, generated Api class is using arrow function image when compile to js, the code will be like this image which has an empty prototype, will unable to modify prototype of Api class for testing or monkey patching.

For example, i am writing unit testing, I am not able to use jest.spyOn(api.prototype,'someApi') as it will throw no property on prototype, but have to mock import to replace entire class import like

const spy = jest.fn()
jest.mock('../path/to/sta',()=>{
    return {
        api: function(){
              return {
                  someApi: spy
              }
        }
    }
})

Expected

Using function expression in class, for example image compiled to image which have a modifiable prototype image