Acontplus.ApiDocumentation 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Acontplus.ApiDocumentation --version 1.0.0
                    
NuGet\Install-Package Acontplus.ApiDocumentation -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Acontplus.ApiDocumentation" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Acontplus.ApiDocumentation" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Acontplus.ApiDocumentation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Acontplus.ApiDocumentation --version 1.0.0
                    
#r "nuget: Acontplus.ApiDocumentation, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Acontplus.ApiDocumentation@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Acontplus.ApiDocumentation&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Acontplus.ApiDocumentation&version=1.0.0
                    
Install as a Cake Tool

Acontplus.ApiDocumentation

This package provides a standardized and simple way to add API versioning and Swagger/OpenAPI documentation to an ASP.NET Core web API.


1. Installation

Install the package into your ASP.NET Core project using the .NET CLI:

dotnet add package Acontplus.ApiDocumentation

2. Usage

Step 2.1: Enable XML Documentation

To display your code comments (<summary>, <remarks>, etc.) in the Swagger UI, enable XML documentation generation in your API's .csproj file.

<PropertyGroup>
  <TargetFramework>net9.0</TargetFramework>
  <Nullable>enable</Nullable>
  <ImplicitUsings>enable</ImplicitUsings>
  
  
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

Step 2.2: Configure appsettings.json

Add a SwaggerInfo section to your appsettings.json file. This information will be displayed at the top of your Swagger documentation page. If this section is omitted, default values will be used.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "SwaggerInfo": {
    "ContactName": "Acontplus Development Team",
    "ContactEmail": "proyectos@acontplus.com",
    "ContactUrl": "[https://acontplus.com.ec](https://acontplus.com.ec)",
    "LicenseName": "MIT License",
    "LicenseUrl": "[https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)"
  }
}

Step 2.3: Configure Program.cs

In your Program.cs file, call the extension methods to register the services and configure the middleware.

using Acontplus.ApiDocumentation; // Add this using statement

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers();

// 1. Add API versioning and documentation services from the package.
builder.Services.AddApiVersioningAndDocumentation();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    // 2. Use the Swagger and versioning middleware from the package.
    app.UseApiVersioningAndDocumentation();
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

Step 2.4: Decorate Your Controllers

Apply versioning attributes to your API controllers. The [ApiVersion] attribute specifies which version(s) the controller belongs to. The route template must include the v{version:apiVersion} segment.

Example: Version 1.0 Controller
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;

namespace MyApi.Controllers.v1;

[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")]
public class DataController : ControllerBase
{
    /// <summary>
    /// Gets the version 1.0 data.
    /// </summary>
    /// <remarks>
    /// This is the first version of the endpoint.
    /// </remarks>
    /// <returns>A sample string for V1.</returns>
    [HttpGet]
    public string Get()
    {
        return "This is response from API version 1.0";
    }
}
Example: Version 2.0 Controller (with a deprecated version)
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;

namespace MyApi.Controllers.v2;

[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("2.0")]
[ApiVersion("1.5", Deprecated = true)] // This version is supported but marked as deprecated
public class DataController : ControllerBase
{
    /// <summary>
    /// Gets the version 2.0 data.
    /// </summary>
    /// <remarks>
    /// This is the newer, more complete endpoint.
    /// </remarks>
    /// <returns>A sample string for V2.</returns>
    [HttpGet]
    public string Get()
    {
        return "This is the enhanced response from API version 2.0";
    }
}

Author & Company

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 82 7/11/2025
1.0.3 76 7/11/2025
1.0.2 121 7/9/2025
1.0.1 134 6/30/2025
1.0.0 132 6/30/2025