Forum Discussion

jdang67's avatar
jdang67
New Contributor
11 months ago

How to use Swagger with WebApi-Mvc project?

Hello Everyone

 

I'm inheriting a WebApi-Mvc project where the return of the public methods of the controller is the Razor page.
I'm not sure if it's possible to integrate Swagger with this project to provide some documentation. Or is there any way we can manually integrate with just a few methods from a few controllers?

 

Thanks,

 

Jdang

2 Replies

  • Hi jdang67 ,

     

    I'm no .NET expert, but the go-to library for Swagger is Swashbuckle (https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-7.0&tabs=visual-studio) .

     

    Integrating that would be a good first step, especially to see how far you can get with automated approaches. 

     

    Ultimately there are two steps, getting the API details (ie: describing your API) which is what Swashbuckle helps to do.

    Then the second part is displaying that description (known as an OpenAPI file/definition) in some documentation tool (typically SwaggerUI, but there are others). The second step can be entirely independent of the server stack using, which is where you can manually describe the definition and then render it inside Razor pages or outside of it.

     

    Hope that helps get things going!

     

     

    • jdang67's avatar
      jdang67
      New Contributor

      I have been using Swagger for many years for WebApi, not WebApi MVC,  So far, there is no luck yet.