Swagger Integration
Swagger (OpenAPI) is a language-agnostic specification for describing REST APIs. It allows both computers and humans to understand the capabilities of a REST API without direct access to the source code. Its main goals are to:
- Minimize the amount of work needed to connect decoupled services.
- Reduce the amount of time needed to accurately document a service.
ABP Framework offers a prebuilt module for full Swagger integration with small configurations.
Installation
This package is already installed by default with the startup template. So, most of the time, you don't need to install it manually.
If installation is needed, it is suggested to use the ABP CLI to install this package.
Using the ABP CLI
Open a command line window in the folder of the Web
or HttpApi.Host
project (.csproj file) and type the following command:
Manual Installation
If you want to manually install;
Add the Volo.Abp.Swashbuckle NuGet package to your
Web
orHttpApi.Host
project:Install-Package Volo.Abp.Swashbuckle
Add the
AbpSwashbuckleModule
to the dependency list of your module:
Configuration
First, we need to use AddAbpSwaggerGen
extension to configure Swagger in ConfigureServices
method of our module.
Then we can use Swagger UI by calling UseAbpSwaggerUI
method in the OnApplicationInitialization
method of our module.
Hide ABP Endpoints on Swagger UI
If you want to hide ABP's default endpoints, call the HideAbpEndpoints
method in your Swagger configuration as shown in the following example:
Using Swagger with OAUTH
For non MVC/Tiered applications, we need to configure Swagger with OAUTH to handle authorization.
ABP Framework uses OpenIddict by default. To get more information about OpenIddict, check this documentation.
To do that, we need to use AddAbpSwaggerGenWithOAuth
extension to configure Swagger with OAuth issuer and scopes in ConfigureServices
method of our module.
Then we can use Swagger UI by calling UseAbpSwaggerUI
method in the OnApplicationInitialization
method of our module.
Do not forget to set
OAuthClientId
andOAuthClientSecret
.