Reputation: 21
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?
Upvotes: 2
Views: 1460
Reputation: 415600
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.
Upvotes: -1
Reputation: 293
I found something that works for me using NSwag library
https://github.com/RicoSuter/NSwag/wiki/OwinGlobalAsax#integration
nuget install
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" />
Upvotes: 0