Zanella.Api 1.0.1

dotnet add package Zanella.Api --version 1.0.1
                    
NuGet\Install-Package Zanella.Api -Version 1.0.1
                    
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="Zanella.Api" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zanella.Api" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Zanella.Api" />
                    
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 Zanella.Api --version 1.0.1
                    
#r "nuget: Zanella.Api, 1.0.1"
                    
#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 Zanella.Api@1.0.1
                    
#: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=Zanella.Api&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Zanella.Api&version=1.0.1
                    
Install as a Cake Tool

Zanella.Utilities

Contains basic utilities for API projects

Dependencies

Asp.Versioning.Mvc.ApiExplorer 7.0.0 Swashbuckle.AspNetCore.SwaggerGen 6.5.0 Swashbuckle.AspNetCore.SwaggerUI 6.5.0

Installation

Use nuget manager to install.

Usage


public class DefaultResponses : IDefaultResponses
{
    public IEnumerable<ResponseSchemaDefinition> ResponseSchemaDefinitions => new[]
    {
        new ResponseSchemaDefinition()
        {
            Description = "Bad Request",
            StatusCode = (int)HttpStatusCode.BadRequest,
            Type = typeof(ErrorDTO),
        },
        new ResponseSchemaDefinition()
        {
            Description = "Unauthorized",
            StatusCode = (int)HttpStatusCode.Unauthorized,
            Type = typeof(ErrorDTO),
        },
        new ResponseSchemaDefinition()
        {
            Description = "Validation Error",
            StatusCode = 422,
            Type = typeof(CustomProblemDetails),
            MediaTypes = new string[]
            {
                "application/problem+json"
            },
        },
        new ResponseSchemaDefinition()
        {
            Description = "Internal Server Error",
            StatusCode = (int)HttpStatusCode.InternalServerError,
            Type = typeof(ErrorDTO),
        },
    };
}


public class ApiInfoProvider : IApiInfoProvider
{
    public OpenApiInfo DefaultOpenApiInfo => new OpenApiInfo()
    {
        Title = "API Versioning and Swagger",
        Description = "ApiVersioningSwagger",
        Contact = new OpenApiContact()
        {
            Name = "Administrator",
            Email = "admin@email.com"
        }
    };

    public string DefaultDescriptionIfDeprecated()
    {
        return DefaultOpenApiInfo.Description + "<br/> This API version has been deprecated.";
    }
}

// class Program.cs
using Zanella.Api.Extensions;

/// ...
// Add versioning
var versioningBuilder = builder.Services.AddApiVersioning(p =>
{
    p.DefaultApiVersion = new ApiVersion(2, 0);
    p.ReportApiVersions = true;
    p.AssumeDefaultVersionWhenUnspecified = true;
});
versioningBuilder.AddApiExplorer(p =>
{
    p.GroupNameFormat = "'v'VVV";
    p.SubstituteApiVersionInUrl = true;
});
// Add filter for model state validation
builder.Services.AddModelStateValidation();
// Add swagger
builder.Services.AddEndpointsApiExplorer();
// Add versioning for swagger
builder.Services.AddSwaggerVersioning<ApiInfoProvider>();
// Add common default responses
builder.Services.AddSwaggerDefaultResponses<DefaultResponses>();
builder.Services.AddSwaggerGen(options =>
{
    // Add versioning
    options.AddVersionDefaultValues();
    // Add default responses
    options.AddDefaultResponses();
    // Add JWT header
    options.AddJWTSecurity("JWT Authorization Header");
});

/// ...
// Use swagger with versioning
app.UseSwagger();
var apiVersionDescriptionProvider = app.Services.GetService<IApiVersionDescriptionProvider>();
app.UseSwaggerUI(options =>
{
    options.AddVersionEndpoints(apiVersionDescriptionProvider);
});

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.1 211 8/19/2023
1.0.0 208 7/7/2023

fix Documentation