![]() |
VOOZH | about |
dotnet add package AzureFunctionsOpenApiFluentValidationExtensions --version 1.0.0
NuGet\Install-Package AzureFunctionsOpenApiFluentValidationExtensions -Version 1.0.0
<PackageReference Include="AzureFunctionsOpenApiFluentValidationExtensions" Version="1.0.0" />
<PackageVersion Include="AzureFunctionsOpenApiFluentValidationExtensions" Version="1.0.0" />Directory.Packages.props
<PackageReference Include="AzureFunctionsOpenApiFluentValidationExtensions" />Project file
paket add AzureFunctionsOpenApiFluentValidationExtensions --version 1.0.0
#r "nuget: AzureFunctionsOpenApiFluentValidationExtensions, 1.0.0"
#:package AzureFunctionsOpenApiFluentValidationExtensions@1.0.0
#addin nuget:?package=AzureFunctionsOpenApiFluentValidationExtensions&version=1.0.0Install as a Cake Addin
#tool nuget:?package=AzureFunctionsOpenApiFluentValidationExtensions&version=1.0.0Install as a Cake Tool
Decorates the OpenApi Specification generated using Azure Functions OpenAPI Extension with FluentValidation rules loaded at runtime.
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).
Currently, only basic rules are supported and the regex dialect is not translated.
Add to your project:
<PackageReference Include="AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection" Version="1.0.0" />
Add to your OpenApi configuration:
DocumentFilters.AddAzureFunctionsOpenApiFluentValidationExtensions<Startup>();
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
};
}
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
};
}
Implement a new rule in AzureFunctionsOpenApiFluentValidationExtensions.Rules that extend Rule and define the required properties. This represents an internal representation of a rule.
Add a new case in AzureFunctionsOpenApiFluentValidationExtensions.ValidatorMapper that map from a FluentValidation type of a rule to the new modeled rule.
Extend AzureFunctionsOpenApiFluentValidationExtensions.FunctionsValidationDocumentFilter:
ApplySchemas method for the new rule to set the necessary properties of a field of a schema, based on the rule.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. |
Showing the top 1 NuGet packages that depend on AzureFunctionsOpenApiFluentValidationExtensions:
| Package | Downloads |
|---|---|
|
AzureFunctionsOpenApiFluentValidationExtensions.DependencyInjection
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 3,431 | 12/19/2023 |
| 0.2.0-preview.2 | 140 | 12/19/2023 |
| 0.2.0-preview.1 | 138 | 12/19/2023 |