Search code examples
c#restasp.net-coref#type-providers

Can I create a API gateway in a F# class lib with type providers and use that in a C# solution to get intellisense on external Web Api using swagger?


I use a lot of ASP.NET Core web API's which use swagger and when consuming these API's there is a lot of copy pasting of Request, Response and Dto's.

F# have Type Providers https://fsharp.github.io/FSharp.Data/library/JsonProvider.html which sounds very good for consuming API's giving me intellisense and compile errors if types or names of external DTO's do not match.

If possible I would like to create a F# class lib which would use Type providers and point to the swagger json file to generate the classes, I would then like to use the F# class lib in my C# solution as there is no native Type provider from what I know in C# yet.

If this can work, what I hope I would gain is

  1. No need to copy/paste external request, response and dtos as the
  2. type provider would provide this Compile errors if the external API changes their types
  3. Intellisense for easier coding

Any input to if this is possible or if there are better solutions?


Solution

  • As the Swagger TypeProvider is generative, this is possible.

    Other solutions include NSwag or a manual workflow using the generator on swagger.io