VOOZH about

URL: https://www.nuget.org/packages/AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection/

⇱ NuGet Gallery | AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection 1.0.0




👁 Image
AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection 1.0.0

dotnet add package AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection --version 1.0.0
 
 
NuGet\Install-Package AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection -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="AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection" Version="1.0.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection" Version="1.0.0" />
 
Directory.Packages.props
<PackageReference Include="AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection" />
 
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 AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection --version 1.0.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection, 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 AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection@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=AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection&version=1.0.0
 
Install as a Cake Addin
#tool nuget:?package=AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection&version=1.0.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AzureFunctionsOpenApiFluentValidationExtensions

Decorates the OpenApi Specification generated using Azure Functions OpenAPI Extension with FluentValidation rules loaded at runtime.

Motivation

The recommended library for generating the OpenAPI specification for Azure Functions is Azure Functions OpenAPI Extension. While the library can annotate the model when using Data Annotations it doesn't support FluentValidation.

As FluentValidation is a widely used library for building strongly-typed validation rules, this package fills the gap by decorating the OpenAPI Specification with the appropriate constraints for HTTP request models, based on the validation rules. It also allows to define rules for HTTP parameters in URLs (see Advanced Usage).

Limitations

Currently, only basic rules are supported and the regex dialect is not translated.

Quick Start

Add to your project:

<PackageReference Include="AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection" Version="1.0.0" />

Add to your OpenApi configuration:

DocumentFilters.AddAzureFunctionsOpenApiFluentValidationExtensions<Startup>();

Usage

Add to your project:

<PackageReference Include="AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection" Version="1.0.0" />

In your custom object to define the OpenApi configuration, use AddAzureFunctionsOpenApiFluentValidationExtensions on the DocumentFilters property.

public class OpenApiConfigurationOptions : DefaultOpenApiConfigurationOptions
{
 public OpenApiConfigurationOptions()
 {
 // Add all validators via reflection.
 DocumentFilters.AddAzureFunctionsOpenApiFluentValidationExtensions<Startup>(services =>
 {
 // Add dependencies required to build the validators.
 // Note the OpenAPI generator doesn't use the DI container.
 services.AddSingleton<IClock>(SystemClock.Instance);
 },
 options =>
 {
 // If any operation has query string parameters that you group into an object and use a validator,
 // add it here using the operation id specified for that function endpoint with [OpenApiOperation(operationId: nameof(MyOperation))]
 options.Operations.Add<MyRequestModel>(nameof(MyOperation));
 });
 }

 public override OpenApiInfo Info { get; set; } = new()
 {
 Version = "v1",
 Title = "NewDay 🥳 API"
 // something else
 };
}

Advanced Usage

Add to your project:

<PackageReference Include="AzureFunctionsOpenApiFluentValidationExtensions" Version="1.0.0" />

If you are not using DI in Azure Functions or using static Functions, you would need to manually register all the validators you are using.

public class OpenApiConfigurationOptions : DefaultOpenApiConfigurationOptions
{
 public OpenApiConfigurationOptions()
 {
 var builder = new FunctionsValidationDocumentFilterBuilder();

 // register a validator
 builder.AddValidator(new MyValidator());

 // register an operation which has query string parameters that you group into an object and use a validator,
 // add it here using the operation id specified for that function endpoint with [OpenApiOperation(operationId: nameof(MyOperation))]
 builder.AddOperationSchema<MyRequestModel>(nameof(MyOperation))

 var filter = builder.Build();

 DocumentFilters.Add(filter);
 }

 public override OpenApiInfo Info { get; set; } = new()
 {
 Version = "v1",
 Title = "NewDay 🥳 API"
 // something else
 };
}

Contributing

Handling new rules

  1. Implement a new rule in AzureFunctionsOpenApiFluentValidationExtensions.Rules that extend Rule and define the required properties. This represents an internal representation of a rule.

  2. Add a new case in AzureFunctionsOpenApiFluentValidationExtensions.ValidatorMapper that map from a FluentValidation type of a rule to the new modeled rule.

  3. Extend AzureFunctionsOpenApiFluentValidationExtensions.FunctionsValidationDocumentFilter:

    1. Add a new case in the ApplySchemas method for the new rule to set the necessary properties of a field of a schema, based on the rule.
    2. Add a new case in the ApplySchemasToOperations method for the new rule to set the necessary properties of a parameter of an operation, based on the rule.
Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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.0 3,384 12/19/2023
0.2.0-preview.2 134 12/19/2023
0.2.0-preview.1 137 12/19/2023