RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.61k stars 1.22k forks source link

NSwag webapi2openapi not working in NSwag.MsBuild 14.0.7 #4897

Open rajarathinam93 opened 1 month ago

rajarathinam93 commented 1 month ago

Hi, I am migrating my app from .net 6.0 to .net 8.0. I have a web api project in my solution which i am serving through orchestrator WebApp. In the After-build event i was generating open api specification using NSwag webapi2openapi from the webapi assembly.

Now i see it's not supported anymore.

Can anyone help me with suitable solution or alternates.

Thanks!

xC0dex commented 1 month ago

Hey, you can use the aspnetcore2openapi command instead.

rajarathinam93 commented 1 month ago

@xC0dex I tried that, it seems to be working, but not finding any api's.

Like i mentioned i have all my endpoints under core api project and that is not having any webhost, its a simple class library.

I am serving those api's through main WebApp.

Looks like after building Main webapp aspnetcore2openapi unable to find any api's. or am i missing something?

Also, When i tried aspnetcore2openapi command on core api project, its complaining for no webhost exists.

rajarathinam93 commented 1 month ago

@xC0dex/others - Any input on my above query.

xC0dex commented 1 month ago

Hey @rajarathinam93, I think NSwag uses the ApiEndpointExplorer to get all the required information for building the OpenApi document. Does the Swagger UI contain all endpoints when you run the application when you run the WebApp? I guess you have to run the Nswag tool on the executable (In your case WebApp)

rajarathinam93 commented 4 weeks ago

@xC0dex - Thanks for the response.

NSwag does not generate endpoints on the executables of WebApp either. Swagger UI of WebApp also not showing any of the endpoints.

var webApiAssembly = typeof(ApiControllerBase).Assembly; var mvcBuilder = services.AddMvc().AddApplicationPart(webApiAssembly);

This is how webapi project assemblies has been added into main WebApp