zijianhuang / webapiclientgen

Strongly Typed Client API Generators generate strongly typed client APIs in C# .NET and in TypeScript for jQuery and Angular 2+ from ASP.NET Web API and .NET Core Web API
MIT License
167 stars 38 forks source link

Integration with abp framework #98

Closed yanxiaodi closed 3 years ago

yanxiaodi commented 4 years ago

Hi, I'm trying to generate web api clients for abp framwork. FYI: https://abp.io/

Currently I have a issue regarding the ModelBinding parameters for GET method. For some reason, abp uses dynamic controllers and ModelBinding for some GET requests, eg. GetListAsync in some services. I got errors like:

Fonlow.Web.Meta.CodeGenException: 'Web API AbpServiceProxyScript/GetAll is defined with invalid parameters: Not support ParameterBinder FromUri with a class parameter Volo.Abp.AspNetCore.Mvc.ProxyScripting.ServiceProxyGenerationModel.'

Inner Exception
ArgumentException: Not support ParameterBinder FromUri with a class parameter Volo.Abp.AspNetCore.Mvc.ProxyScripting.ServiceProxyGenerationModel.

I checked the source code of webapiclientgen. In MetaTransform class, there are some methods to check the parameter type. If the parameterBinder is FromUri, and the below conditions are met:

(!isValueType && !isNullablePrimitive && !isArrayType && !parameterType.IsEnum))

The method will throw an exception. However, the parameter actually can be attached in the url path. Just because the ParameterType is not a simple type so it fails. I'm wondering if we could investigate it for this specific scenario because abp is a good example of the modern ASP.NET Core applications. I'm happy to provide helps. Thanks.

zijianhuang commented 4 years ago

Presumably you are aware of pros and cons of using a complex type in GET query with ModelBinding, you may make a fork to extend WebApiClientGen or introduce ModelBinding to WebApiClientGen directly. Then let's see how well this could go. Likely I am not making any significant change of WebApiClientGen in next few months, so your fork should be easily pulled and merged later.

However, please be aware of the technical scope of WebApiClientGen:

  1. It aims to be something like SvcUtil.exe of WCF.
  2. It has no intention to replace Swagger tool chains.
  3. The whole design is optimized for RPC, not REST, since I consider REST is too much technical details, not friendly to business modeling. Application developers may ignore the RESTful concept for complex business application programming.
  4. The overhead of application programming with the CodeGen should be kept to minimum for the sake of RAD in both service side and client sides.
zijianhuang commented 3 years ago

too old, no progress