Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

Support response types #33

Closed LucaDe closed 5 years ago

LucaDe commented 5 years ago

Currently response types are not typed (e.g. return type is always Promise< any >). It would be great to have these typed as well :)

I might look into this myself, when I find time!

Manweill commented 5 years ago

@LucaDe Similar to #26. upgrade swagger-axios-codegen@latest

LucaDe commented 5 years ago

@Manweill It's not working on v.0.7.0. Sample:


const { codegen } = require('swagger-axios-codegen')

codegen({
  methodNameMode: 'operationId',
  remoteUrl:'https://webhook.apaleo.com/swagger/notification-v1/swagger.json',
  include: [
    'Subscriptions'
  ],
});
Manweill commented 5 years ago

I think i see what happen with it. I rebuild and publish, fix in v0.7.1.

LucaDe commented 5 years ago

@Manweill
Thanks for rebuilding and publishing. Still same behaviour, response type is generated and added to GET requests, but not to POST/DELETE etc.

Manweill commented 5 years ago

@LucaDe It has.

static createOrUpdateEquipment(
    params: {
      /**  */
      input?: CreateOrUpdateEquipmentInput;
    } = {} as any,
    options: IRequestOptions = {}
  ): Promise<number> {
    return new Promise((resolve, reject) => {
      let url = '/api/services/app/Equipment/CreateOrUpdateEquipment';

      const configs: IRequestConfig = getConfigs('post', 'application/json', url, options);

      let data = { ...params['input'] };

      configs.data = data;
      axios(configs, resolve, reject);
    });
  }
LucaDe commented 5 years ago

@Manweill Could you check with my provided sample above? It should generate the SubscriptionCreatedResponseModel and add it to subscriptionsPost(..): Promise

LucaDe commented 5 years ago

@Manweill I just flew over the code for response type generation. It seems that you're only providing response types for a status code of 200. In my case the API returns a 201 as Statuscode, when a new Entity is created.

Manweill commented 5 years ago

I think it may be because I only deal with HttpCode 200. I check with your swagger JSON. The Post method success HttpCode is 201. I think it can add HttpCode is 20X response type. But, How to deal with Delete method

Manweill commented 5 years ago

@LucaDe Yeah, because my company's success code is only 200

LucaDe commented 5 years ago

I don't see why there should be a problem with DELETE methods. I will open a PR to accept 2XX status codes

Manweill commented 5 years ago

OK, Welcome PR~

Manweill commented 5 years ago

@LucaDe Use yarn link with develop

Manweill commented 5 years ago

@LucaDe Published.