C# code generator for REST services

I wrote a code generator using NSwag for Epicor services. I was wondering if the community would be interested in the code to generate their own REST clients. The generator handles security and connection through a shared resource. I could create a GUI to make it a seamless application for client generation.

Currently the generator creates cs files and adds them to a project for all services however this can be filtered by selecting only the services you wish to utilize.

If the community is open I can post on Github with an MIT license.

I would add a GUI and some additional functionality, mostly configurable.

13 Likes

Hi Ed,
We welcome any tool that can help the community. Thank you!

And here it is, please let me know if you have any issues or you wish to contribute.

9 Likes

Very nice contribution!

Awesome!

Jos? C Gomez
Senior Software Engineer

can’t wait to take it for a spin!

Let me know if you need any instructions, I updated the UI today to make it easier to grab BAQs

How do you make authentication in your project? i don;t see any name\password setting…

Thank you for this.

Where do you want to place username and password? I use single sign on for the service user to generate the code and to run the client. What step do you wish to have credentials, both require you to change my code for your environment.

I see. Thanks

In the service class you can change the getWebClient method to generate a WebClient with your credentials, this is used to generate the client code.

In the ClientBase class I have added code samples for the different types of authentication. SSO, Bearer Token, User credentials. This is used by the generated code to create the HttpClient

I made a significant change in terms of adding username and password, I also gave a UI component to edit the client base. I did do some significant clean up effort to the code structure, so it is easier for others to dive in if they want.

3 Likes

Marvelous, thanks for putting this together.

When I use the tool, I get an internal server error (error 500). I also get the error in the browser when I browse to the URL displayed in the “API’s URL” field. https://myServer/myApp/api/swagger/v1/odata/

I’m able to make the REST calls manually with no problem. Maybe there’s an issue with my app server configuration?

1 Like

There was a bug when checking for a valid url, I have fixed and updated the code. Thank You

Getting closer…

Now I get an exception at line 81 of Service.cs.

ErpBOPartSvc
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
at CallSite.Target(Closure , CallSite , Object , String , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at EpicorSwaggerRESTGenerator.Models.service.d__9.MoveNext() in D:\Source\GitHub\EdWelsh\EpicorRESTClientGenerator\EpicorSwaggerRESTGenerator\Models\Service.cs:line 81

Can you open an issue on github?
Use the log file generated by the exception, it should be found in the assemblies / logs directory