如何从OpenAPI定义中生成Visual Basic .NET客户端?

发布于 2025-02-11 02:28:21 字数 239 浏览 0 评论 0原文

我需要从Visual Basic .NET项目(.NET Framework 3.5)调用REST API。他们给了我一个openapi .yaml文件。在Swagger编辑器中,我无法为Visual Basic生成客户端,仅用于C#。我试图将JSON从Swagger编辑器中导出,并将其粘贴在Visual Studio中,但是生成的班级似乎是不正确且不完整的。

有没有一种方法可以从OpenAPI定义中生成Visual Basic .NET客户端?

I need to call a REST API from a Visual Basic .NET project (.NET Framework 3.5). They gave me an OpenAPI .yaml file. In the Swagger Editor I can't generate the client for Visual Basic, only for C#. I tried to export the JSON from the Swagger Editor and paste it as a class in Visual Studio, but the generated class seems to be incorrect and incomplete.

Is there a way to generate a Visual Basic .NET client from an OpenAPI definition?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

む无字情书 2025-02-18 02:28:21

我发现了使用NSWAG库

https://github.com/ricososuter// nswag/wiki/offinglobalasax#集成

nuget intern

  • microsoft.owin.host.host.systemweb
  • nswag.aspnet.owin

webapiconfig.vb

RouteTable.Routes.MapOwinPath("swagger", Function(app) As Owin.IAppBuilder
                                                         Return app.UseSwaggerUi(GetType(WebApiApplication).Assembly, Function(opts) As SwaggerUiSettings(Of NSwag.Generation.WebApi.WebApiOpenApiDocumentGeneratorSettings)
                                                                                                                          opts.MiddlewareBasePath = "/swagger"
                                                                                                                          opts.GeneratorSettings.DefaultUrlTemplate = "api/{controller}/{action}/{id}"
                                                                                                                          Return opts
                                                                                                                      End Function)
    End Function)

web.config

<configuration>
 <appSettings>
  <add key="owin:AutomaticAppStartup" value="false" />
  <system.webServer>
    <handlers>
    <!-- Handler swagger -->
<add name="NSwag" path="swagger" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

I found something that works for me using NSwag library

https://github.com/RicoSuter/NSwag/wiki/OwinGlobalAsax#integration

nuget install

  • Microsoft.Owin.Host.SystemWeb
  • NSwag.AspNet.Owin

WebApiConfig.vb

RouteTable.Routes.MapOwinPath("swagger", Function(app) As Owin.IAppBuilder
                                                         Return app.UseSwaggerUi(GetType(WebApiApplication).Assembly, Function(opts) As SwaggerUiSettings(Of NSwag.Generation.WebApi.WebApiOpenApiDocumentGeneratorSettings)
                                                                                                                          opts.MiddlewareBasePath = "/swagger"
                                                                                                                          opts.GeneratorSettings.DefaultUrlTemplate = "api/{controller}/{action}/{id}"
                                                                                                                          Return opts
                                                                                                                      End Function)
    End Function)

Web.Config

<configuration>
 <appSettings>
  <add key="owin:AutomaticAppStartup" value="false" />
  <system.webServer>
    <handlers>
    <!-- Handler swagger -->
<add name="NSwag" path="swagger" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
恏ㄋ傷疤忘ㄋ疼 2025-02-18 02:28:21

VB.NET可以使用C#组件(DLL),Visual Studio很乐意构建混合的项目。

这使得使用来自完全vb.net的应用程序生成的C#客户端非常简单。您可以在相同的VS解决方案中将摇摇欲坠的代码添加到自己的独立项目中。

VB.Net can use C# assemblies (dlls), and Visual Studio is happy to build mixed projects.

This makes it fairly simple to use a C# client generated by Swagger from an app that is otherwise fully VB.Net. You can add the Swagger-generated code to it's own separate project in the same VS solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文