简体   繁体   English

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?

[英]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.我使用了很多 ASP.NET Core web API,这些 API 使用了 swagger,当使用这些 API 时,有很多复制粘贴请求、响应和 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. 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 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我在 C# 中所知道的。

If this can work, what I hope I would gain is如果这可行,我希望我能得到的是

  1. No need to copy/paste external request, response and dtos as the无需复制/粘贴外部请求、响应和 dto 作为
  2. type provider would provide this Compile errors if the external API changes their types如果外部 API 更改其类型,类型提供程序将提供此编译错误
  3. Intellisense for easier coding Intellisense 更容易编码

Any input to if this is possible or if there are better solutions?是否有可能或是否有更好的解决方案?

As the Swagger TypeProvider is generative , this is possible.由于Swagger TypeProvider生成的,因此这可能的。

Other solutions include NSwag or a manual workflow using the generator on swagger.io其他解决方案包括NSwag或使用swagger.io上的生成器的手动工作流

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM