openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
550 stars 67 forks source link

Request not fired #133

Closed ioanna0 closed 1 year ago

ioanna0 commented 1 year ago

hi,

Have been debugging this for few hours already and tried different things but whatever I've tried I don't see the request been fired when calling operations on the client. The schema is generated successfully and I get all the nice autocompletion.

My example

const api = new OpenAPIClientAxios({
  definition: 'https://mycustomdomain/openapi.json',
withServer: {
     url: `mycustomserver/api`,
     description: 'custom server',
  },
});
api.init<CustomClient>();
const client = await api.getClient<CustomClient>();
const data = await client.customOperation();

even trying with this syntax, nothing happens:

client.paths['/api/custom-operation/'].get()

No error is presented on the console nor any request is fired in the network tab.

Any ideas on why would the client not fire a request on an operation method?

Had checked the baseUrls and and all the configs I could and everything look fine just that the request is not fired and unfortunately without any errors presented is hard to know what could be wrong.

anttiviljami commented 1 year ago

Could you log the result from calling the operation method please and share here?

ioanna0 commented 1 year ago

the js execution breaks when invoking the operation and thus never reaches the next line to log out the result unfortunately. also nothing is displayed on console window

anttiviljami commented 1 year ago

ok, sounds like you’re having problems with your browser dev setup if you’re not able to see why some code never executes. I’d check if all log levels are being displayed and no filters are applied to your console. If that doesn’t work, switch to a different browser. Could be a CORS issue when trying to load the openapi.json from a remote server.

Likely not an issue with the this library. Feel free to reach out if you find some unexpected errors.

ioanna0 commented 1 year ago

Thanks, I'm bypassing CORS issue by overriding the headers.

I've surrounded with try catch to and the error is now visible:

Axios is complaining for empty options

const request = api.getRequestConfigForOperation('custom_op', []);
  console.log('request ', request);
  try {
    const data = await client.custom_op();
    // console.log('data', data);
  } catch (e) {
    console.log('Error', e);
  }

Seems to complain for some empty options.

Request details here:

   "cookies":{
   }
"headers":{
      "Accept":"application/json, text/plain, */*"
   }"method":"get""path":"/api/custom-op/""pathParams":{
   }"payload":"undefined
query":{
   }"queryString":"""url":"https://custom-domain/api/custom-op/"
}
ioanna0 commented 1 year ago

Update: This was due to having axios lib in addition to openapi-client-axios. Deleted it and now works fine