Swagger is a tool that makes it easier to create, document, and consume APIs (Application Programming Interface). It provides an interactive interface that allows developers and external consumers to view, test, and interact with an API's endpoints in an intuitive way. Through Swagger, it is possible to automatically generate API documentation from the source code, ensuring the documentation is always up to date and synchronized with the implementations. In addition, Swagger supports a wide range of programming languages and frameworks.
By default, Swagger is only accessible in the development environment. For production environments, enabling it is optional through configuration.
Behavior
| Environment | SwaggerEnabled Parameter | Authenticated User | Result |
|---|---|---|---|
| Development | N/A | Yes | ✓ Access granted |
| Development | N/A | No | 401 Unauthorized |
| Production | false (default) | Yes/No | 403 Forbidden |
| Production | true | Yes | ✓ Access granted |
| Production | true | No | 401 Unauthorized |
How to enable in production
Include this setting in the appsettings.json file:
{
"SwaggerEnabled": true
}
There are several authentication methods available in Swagger. The most commonly used are:
To open Swagger, use the endpoint: URL.../swagger/index.html
qablue.tech6cloud.com/swagger/index.html; (in this case, qablue is your domain name.)(IIS server)/(application name in IIS)/swagger/index.htmlThe URL provided before the API depends on your cloud domain or, in a local environment, on the settings configured in your IIS (Internet Information Services).
When you access the endpoint, a page containing all system APIs will open. Click
to expand the selected API.
For more information and ways to consume APIs, visit our help center: Data Integration
To access Swagger in a production environment, you need to enable the configuration in the appsettings.json file by setting "SwaggerEnabled": true. By default, Swagger is disabled in production for security reasons.
The 403 (Forbidden) error indicates that Swagger is disabled for the current environment. In production environments, Swagger needs to be explicitly enabled through the "SwaggerEnabled": true configuration in the appsettings.json file.
The 401 (Unauthorized) error means you are not authenticated in the system. You need to log in to the application before accessing Swagger, regardless of the environment (development or production).
Swagger supports three main authentication methods:
To execute an API in Swagger:
The default URL follows the format: URL.../swagger/index.html. In a cloud environment, it would be something like yourdomain.tech6cloud.com/swagger/index.html. In a local environment, it depends on the IIS configuration: (IIS server)/(application name in IIS)/swagger/index.html.
Swagger's response includes an HTTP status code and a description. 2xx codes indicate success, while 4xx or 5xx codes indicate errors. In case of failure, Swagger provides details about the error code and the reason for the failure.
Yes, Swagger automatically generates API documentation from the source code, ensuring that the documentation is always up to date and synchronized with the implementations.
Swagger exposes information about your API's structure and endpoints. For security reasons, it is disabled by default in production. Enable it only if there is a specific need and ensure that only authenticated users can access it.
Yes, Swagger displays all available APIs in the system, allowing you to view, test, and interact with each endpoint interactively. It is a comprehensive tool for developers and external consumers to test API functionalities.