REST client generator

Inspired by Ed Welsh’s C# client generator, I’ve developed my own generator with a rather different design philosophy. Mine is also under the MIT license.

  • Designed for easy setup and rapid iteration. Just add the NuGet package to your project and edit the config file it creates. If you ever need to change which clients are generated, just edit the config file and rebuild.
  • Gives you complete control over NSwag generator settings.
  • Allows you to generate clients for Epicor services that were hidden before 10.2.300. (See Nicholas Whitall’s answer here.)
  • Generates clients for any Swagger API. (In theory, anyway. I’ve only used it with Epicor and Magento.)
  • Uses a newer version of NSwag that generates less buggy code.
  • Enhances NSwag’s handling of base URLs. (NSwag issues #1837 and #1850.)
  • Generates clients directly into the target project. This allows you to combine your own classes with generated partial classes.
  • Generates into /obj by default, so generated code will not be in source control.

The default settings do not produce drop-in replacements for clients generated by Ed’s version. This is partly due to NSwag’s own defaults changing to address NSwag issue #1097. With the defaults I’ve set, the lifecycle of the HttpClient used to construct a REST client is not the REST client’s concern.

5 Likes

Since my original post, I’ve added a couple options to work around what I consider bugs in Epicor’s API spec generation.

  • Epicor specifies numeric properties in a way that NSwag interprets as a double in C# clients. The ConvertNumbersToDecimal option converts all double to decimal for accuracy when working with currency.
  • Epicor specifies all properties of a baqType as required and not nullable, even when they should be nullable because the database column is nullable or they came from an outer join. This causes NSwag to generate a C# client that chokes on null values returned by the BAQ. The IgnoreRequired option removes all required properties, causing them to default to nullable.