├── test
└── AspNet.FluentValidation.Tests
│ ├── Usings.cs
│ ├── AspNet.FluentValidation.Tests.csproj
│ └── ValidationFilterTests.cs
├── .github
├── CODEOWNERS
└── workflows
│ ├── build.yml
│ └── publish.yml
├── src
└── AspNet.FluentValidation
│ ├── assets
│ └── icon.png
│ ├── ValidateAttribute.cs
│ ├── EndpointValidationMetadata.cs
│ ├── AspNet.FluentValidation.csproj
│ ├── ValidationFilterOptions.cs
│ ├── ValidationStrategies.cs
│ └── ValidationExtensions.cs
├── .config
└── dotnet-tools.json
├── .gitignore
├── Directory.Build.props
├── LICENSE
├── .vscode
├── launch.json
└── tasks.json
├── o9d-aspnet.sln
└── README.md
/test/AspNet.FluentValidation.Tests/Usings.cs:
--------------------------------------------------------------------------------
1 | global using Xunit;
2 | global using Shouldly;
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
2 | * @benfoster
--------------------------------------------------------------------------------
/src/AspNet.FluentValidation/assets/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/benfoster/o9d-aspnet/HEAD/src/AspNet.FluentValidation/assets/icon.png
--------------------------------------------------------------------------------
/.config/dotnet-tools.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "isRoot": true,
4 | "tools": {
5 | "cake.tool": {
6 | "version": "3.0.0",
7 | "commands": [
8 | "dotnet-cake"
9 | ]
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/AspNet.FluentValidation/ValidateAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace O9d.AspNet.FluentValidation;
2 |
3 | ///
4 | /// Attribute used to indicate an input parameter or class should be validated
5 | ///
6 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false, Inherited = true)]
7 | public sealed class ValidateAttribute : Attribute
8 | {
9 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | *.swp
3 | *.*~
4 | project.lock.json
5 | .DS_Store
6 | *.pyc
7 | nupkg/
8 |
9 | # User-specific files
10 | *.suo
11 | *.user
12 | *.userosscache
13 | *.sln.docstates
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | build/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 | [Oo]ut/
27 | msbuild.log
28 | msbuild.err
29 | msbuild.wrn
30 |
31 | # Cake - Uncomment if you are using it
32 | tools/**
33 | !tools/packages.config
34 |
35 | artifacts/
36 | BenchmarkDotNet.Artifacts/
--------------------------------------------------------------------------------
/src/AspNet.FluentValidation/EndpointValidationMetadata.cs:
--------------------------------------------------------------------------------
1 | namespace O9d.AspNet.FluentValidation;
2 |
3 | ///
4 | /// Marker metadata used to indicate that the endpoint input parameter should be validated
5 | ///
6 | public sealed class EndpointValidationMetadata
7 | {
8 | public EndpointValidationMetadata(Type[] typesToValidate)
9 | {
10 | if (typesToValidate is null)
11 | {
12 | throw new ArgumentNullException(nameof(typesToValidate));
13 | }
14 |
15 | TypesToValidate = typesToValidate;
16 | }
17 |
18 | public Type[] TypesToValidate { get; }
19 | }
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | latest
4 |
5 | enable
6 | nullable;
7 | true
8 |
9 |
10 | @benfoster
11 | o9d
12 | https://github.com/benfoster/o9d-aspnet
13 | https://github.com/benfoster/o9d-aspnet.git
14 | git
15 |
16 |
17 | normal
18 |
19 |
--------------------------------------------------------------------------------
/src/AspNet.FluentValidation/AspNet.FluentValidation.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net7.0
4 | enable
5 | enable
6 | O9d.AspNet.FluentValidation
7 | O9d.AspNet.FluentValidation
8 | O9d.AspNet.FluentValidation
9 | Fluent Validation extensions for ASP.NET Core Minimal APIs
10 | icon.png
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | pull_request:
5 | branches: [main]
6 |
7 | jobs:
8 | build:
9 | runs-on: ubuntu-latest
10 |
11 | steps:
12 | - uses: actions/checkout@v2
13 | with:
14 | fetch-depth: 0
15 | - name: Setup Java
16 | uses: actions/setup-java@v1
17 | with:
18 | java-version: 11.0.x
19 | - name: Setup .NET 7.0
20 | uses: actions/setup-dotnet@v1
21 | with:
22 | dotnet-version: 7.0.x
23 | - name: Restore tools
24 | run: dotnet tool restore
25 | - name: Run the build script
26 | uses: cake-build/cake-action@v1
27 | env:
28 | COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
29 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 | with:
32 | target: CI
33 | #verbosity: Diagnostic
34 | - name: Upload pre-release packages
35 | uses: actions/upload-artifact@v2
36 | with:
37 | name: packages
38 | path: artifacts/*.nupkg
39 |
--------------------------------------------------------------------------------
/src/AspNet.FluentValidation/ValidationFilterOptions.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 | using FluentValidation.Results;
3 | using Microsoft.AspNetCore.Http;
4 |
5 | namespace O9d.AspNet.FluentValidation;
6 |
7 | ///
8 | /// Options used to configure the Validation Filter
9 | ///
10 | public sealed class ValidationFilterOptions
11 | {
12 | ///
13 | /// Gets or sets the delegate used to determine whether the endpoint parameter is validateable
14 | ///
15 | public ValidationStrategy ShouldValidate { get; set; } = ValidationStrategies.HasValidateAttribute;
16 |
17 | ///
18 | /// Gets or sets the factory used to create a HTTP result when validation fails. Defaults to a HTTP 422 Validation Problem.
19 | ///
20 | public Func InvalidResultFactory { get; set; } = CreateValidationProblemResult;
21 |
22 | private static IResult CreateValidationProblemResult(ValidationResult validationResult)
23 | => Results.ValidationProblem(validationResult.ToDictionary(), statusCode: (int)HttpStatusCode.UnprocessableEntity);
24 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Ben Foster
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | push:
5 | branches: [main]
6 | tags: ["*"]
7 |
8 | jobs:
9 | publish:
10 | name: Build and publish
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v2
14 | with:
15 | fetch-depth: 0
16 | - name: Setup Java
17 | uses: actions/setup-java@v1
18 | with:
19 | java-version: 11.0.x
20 | - name: Setup .NET 7.0
21 | uses: actions/setup-dotnet@v1
22 | with:
23 | dotnet-version: 7.0.x
24 | - name: Restore tools
25 | run: dotnet tool restore
26 | - name: Run the build script
27 | uses: cake-build/cake-action@v1
28 | env:
29 | COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
30 | NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
31 | NUGET_API_URL: https://api.nuget.org/v3/index.json
32 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
33 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 | NUGET_PRE_API_KEY: ${{ secrets.GITHUB_TOKEN }}
35 | NUGET_PRE_API_URL: https://nuget.pkg.github.com/benfoster/index.json
36 | with:
37 | target: Publish
38 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | // Use IntelliSense to find out which attributes exist for C# debugging
6 | // Use hover for the description of the existing attributes
7 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
8 | "name": ".NET Core Launch (console)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/test/AspNet.FluentValidation.Tests/bin/Debug/net7.0/AspNet.FluentValidation.Tests.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}/test/AspNet.FluentValidation.Tests",
16 | // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17 | "console": "internalConsole",
18 | "stopAtEntry": false
19 | },
20 | {
21 | "name": ".NET Core Attach",
22 | "type": "coreclr",
23 | "request": "attach"
24 | }
25 | ]
26 | }
--------------------------------------------------------------------------------
/test/AspNet.FluentValidation.Tests/AspNet.FluentValidation.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net7.0
4 | enable
5 | enable
6 | false
7 |
8 |
9 |
10 |
11 |
12 | runtime; build; native; contentfiles; analyzers; buildtransitive
13 | all
14 |
15 |
16 | runtime; build; native; contentfiles; analyzers; buildtransitive
17 | all
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/test/AspNet.FluentValidation.Tests/AspNet.FluentValidation.Tests.csproj",
11 | "/property:GenerateFullPaths=true",
12 | "/consoleloggerparameters:NoSummary"
13 | ],
14 | "problemMatcher": "$msCompile"
15 | },
16 | {
17 | "label": "publish",
18 | "command": "dotnet",
19 | "type": "process",
20 | "args": [
21 | "publish",
22 | "${workspaceFolder}/test/AspNet.FluentValidation.Tests/AspNet.FluentValidation.Tests.csproj",
23 | "/property:GenerateFullPaths=true",
24 | "/consoleloggerparameters:NoSummary"
25 | ],
26 | "problemMatcher": "$msCompile"
27 | },
28 | {
29 | "label": "watch",
30 | "command": "dotnet",
31 | "type": "process",
32 | "args": [
33 | "watch",
34 | "run",
35 | "--project",
36 | "${workspaceFolder}/test/AspNet.FluentValidation.Tests/AspNet.FluentValidation.Tests.csproj"
37 | ],
38 | "problemMatcher": "$msCompile"
39 | }
40 | ]
41 | }
--------------------------------------------------------------------------------
/src/AspNet.FluentValidation/ValidationStrategies.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | namespace O9d.AspNet.FluentValidation;
4 |
5 | ///
6 | /// Represents a strategy used to determine whether the provided endpoint details are validateable.
7 | ///
8 | /// The endpoint parameter
9 | /// The endpoint metadata
10 | /// True if the parameter is validateable, otherwise False
11 | public delegate bool ValidationStrategy(ParameterInfo parameterInfo, IList