Skip to content

Commit 64062b1

Browse files
Prob validation prep (#33329)
* Prob validation prep * Prob validation prep * Prob validation prep * Prob validation prep
1 parent 90794b9 commit 64062b1

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#define SECOND // FIRST SECOND
2+
#if NEVER
3+
#elif FIRST
4+
// <snippet_1>
5+
using Microsoft.AspNetCore.Http;
6+
7+
var app = WebApplication.Create();
8+
9+
var todos = app.MapGroup("/todos")
10+
.ProducesProblem();
11+
12+
todos.MapGet("/", () => new Todo(1, "Create sample app", false));
13+
todos.MapPost("/", (Todo todo) => Results.Ok(todo));
14+
15+
app.Run();
16+
17+
record Todo(int Id, string Title, bool IsCompleted);
18+
// </snippet_1>
19+
#elif SECOND
20+
// <snippet_2>
21+
using Microsoft.AspNetCore.Http;
22+
23+
var app = WebApplication.Create();
24+
25+
app.MapGet("/", () =>
26+
{
27+
var extensions = new List<KeyValuePair<string, object>> { new("test", "value") };
28+
return TypedResults.Problem("This is an error with extensions",
29+
extensions: extensions);
30+
});
31+
// </snippet_2>
32+
#endif
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Support calling `ProducesProblem` and `ProducesValidationProblem` on route groups
2+
3+
The `ProducesProblem` and `ProducesValidationProblem` extension methods have been updated to support application on route groups, as in the sample below. These methods can be used to indicate that all endpoints in a route group can return `ProblemDetails` or `ValidationProblemDetails` responses for the purposes of OpenAPI metadata.
4+
5+
:::code language="csharp" source="~/fundamentals/openapi/samples/9.x/ProducesProblem/Program.cs" id="snippet_1" :::
6+
7+
## `Problem` and `ValidationProblem` result types support construction with `IEnumerable<KeyValuePair<string, object?>>` values
8+
9+
Prior to this preview, constructing `Problem` and `ValidationProblem` result types in minimal APIs required that the `errors` and `extensions` properties be initialized with an implementation of `IDictionary<string, object?>`. Starting in this release, these construction APIs support overloads that consume `IEnumerable<KeyValuePair<string, object?>>`.
10+
11+
:::code language="csharp" source="~/fundamentals/openapi/samples/9.x/ProducesProblem/Program.cs" id="snippet_2" :::
12+
13+
Thanks to GitHub user "joegoldman2" for this contribution!

0 commit comments

Comments
 (0)