Skip to content

Commit 8004595

Browse files
Merge pull request #35321 from timdeschryver/issue/35292
make snippet tablet-friendly
2 parents 29372ad + 1e3dc2f commit 8004595

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

aspnetcore/fundamentals/openapi/include-metadata.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ The following sample demonstrates how to set a description for a parameter.
176176

177177
```csharp
178178
[HttpGet("attributes")]
179-
public IResult Attributes([Description("This is a description.")] string name)
179+
public IResult Attributes(
180+
[Description("This is a description.")] string name)
180181
{
181182
return Results.Ok("Hello world!");
182183
}
@@ -218,9 +219,16 @@ The framework uses the <xref:Microsoft.AspNetCore.Http.Metadata.IEndpointMetadat
218219
```csharp
219220
public class Todo : IEndpointParameterMetadataProvider
220221
{
221-
public static void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder)
222+
public static void PopulateMetadata(
223+
ParameterInfo parameter,
224+
EndpointBuilder builder)
222225
{
223-
builder.Metadata.Add(new AcceptsMetadata(["application/xml", "text/xml"], typeof(Todo)));
226+
builder.Metadata.Add(
227+
new AcceptsMetadata(
228+
["application/xml", "text/xml"],
229+
typeof(Todo)
230+
)
231+
);
224232
}
225233
}
226234
```
@@ -238,7 +246,9 @@ Since `application/xml` is not a built-in content type, the `Todo` class must im
238246
```csharp
239247
public class Todo : IBindableFromHttpContext<Todo>
240248
{
241-
public static async ValueTask<Todo?> BindAsync(HttpContext context, ParameterInfo parameter)
249+
public static async ValueTask<Todo?> BindAsync(
250+
HttpContext context,
251+
ParameterInfo parameter)
242252
{
243253
var xmlDoc = await XDocument.LoadAsync(context.Request.Body, LoadOptions.None, context.RequestAborted);
244254
var serializer = new XmlSerializer(typeof(Todo));
@@ -400,9 +410,9 @@ All of the above attributes can be applied to individual action methods or to th
400410

401411
```csharp
402412
[HttpGet("/todos/{id}")]
403-
[ProducesResponseType<Todo>(StatusCodes.Status200OK,
413+
[ProducesResponseType<Todo>(StatusCodes.Status200OK,
404414
"application/json", Description = "Returns the requested Todo item.")]
405-
[ProducesResponseType(StatusCodes.Status404NotFound,
415+
[ProducesResponseType(StatusCodes.Status404NotFound,
406416
Description = "Requested Todo item not found.")]
407417
[ProducesDefault(Description = "Undocumented status code.")]
408418
public async Task<ActionResult<Todo>> GetTodoItem(string id, Todo todo)
@@ -422,9 +432,12 @@ In controller-based apps, ASP.NET responds with a ProblemDetails response type w
422432

423433
```csharp
424434
[HttpPut("/todos/{id}")]
425-
[ProducesResponseType<Todo>(StatusCodes.Status200OK, "application/json")]
426-
[ProducesResponseType<Todo>(StatusCodes.Status201Created, "application/json")]
427-
[ProducesResponseType<ProblemDetails>(StatusCodes.Status400BadRequest, "application/problem+json")]
435+
[ProducesResponseType<Todo>(StatusCodes.Status200OK,
436+
"application/json")]
437+
[ProducesResponseType<Todo>(StatusCodes.Status201Created,
438+
"application/json")]
439+
[ProducesResponseType<ProblemDetails>(StatusCodes.Status400BadRequest,
440+
"application/problem+json")]
428441
public async Task<ActionResult<Todo>> CreateOrReplaceTodo(string id, Todo todo)
429442
```
430443

@@ -623,14 +636,19 @@ A special case is when an enum type has the `[Flags]` attribute, which indicates
623636

624637
```csharp
625638
[Flags, JsonConverter(typeof(JsonStringEnumConverter<PizzaToppings>))]
626-
public enum PizzaToppings { Pepperoni = 1, Sausage = 2, Mushrooms = 4, Anchovies = 8 }
639+
public enum PizzaToppings {
640+
Pepperoni = 1,
641+
Sausage = 2,
642+
Mushrooms = 4,
643+
Anchovies = 8
644+
}
627645
```
628646

629647
An enum type without a [`[JsonConverter]`](xref:System.Text.Json.Serialization.JsonConverterAttribute) will be defined as `type: integer` in the generated schema.
630648

631649
**Note:** The [`[AllowedValues]`](xref:System.ComponentModel.DataAnnotations.AllowedValuesAttribute) attribute does not set the `enum` values of a property.
632650

633-
[Set JSON options globally](#set-json-serialization-options-globally) shows how to set the the `JsonStringEnumConverter` globally.
651+
[Set JSON options globally](#set-json-serialization-options-globally) shows how to set the `JsonStringEnumConverter` globally.
634652

635653
#### nullable
636654

@@ -670,19 +688,19 @@ A schema transformer can be used to override any default metadata or add additio
670688

671689
## Set JSON serialization options globally
672690

673-
The following code configures some JSON options globally, for Minimal APIs and Controler based APIs:
691+
The following code configures some JSON options globally, for Minimal APIs and Controller based APIs:
674692

675-
[!code-csharp[](~/fundamentals/openapi/samples/10.x/WebJson/Program.cs?highlight=8-29)]
693+
[!code-csharp[](~/fundamentals/openapi/samples/10.x/WebJson/Program.cs?highlight=9-29)]
676694

677695
## MVC JSON options and global JSON options
678696

679-
The following table shows the key Differences beween the MVC JSON options and global Minimal API JSON options:
697+
The following table shows the key differences beween the MVC JSON options and global Minimal API JSON options:
680698

681699
| **Aspect** | **MVC JSON Options** | **Global JSON Options** |
682700
|-----------------------|--------------------------------------------|-----------------------------------------------|
683-
| **Scope** | Limited to MVC controllers and endpoints. | Minimal Api's and OpenAPI docs. |
701+
| **Scope** | Limited to MVC controllers and endpoints. | Minimal APIs and OpenAPI docs. |
684702
| **Configuration** | `AddControllers().AddJsonOptions()` | `Configure<JsonOptions>()` |
685-
| **Purpose** | Handles serialization and deserializtion of JSON requests and responses in APIs. | Defines global JSON handling for Minimal APIs and OpenAPI schemas. |
703+
| **Purpose** | Handles serialization and deserialization of JSON requests and responses in APIs. | Defines global JSON handling for Minimal APIs and OpenAPI schemas. |
686704
| **Influence on OpenAPI** | None | Directly influences OpenAPI schema generation.|
687705

688706
---

aspnetcore/release-notes/aspnetcore-10/includes/openApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ app.MapOpenApi("/openapi/{documentName}.yaml");
8080

8181
Support for:
8282

83-
* YAML is currently only available for the the OpenAPI served from the OpenAPI endpoint.
83+
* YAML is currently only available for the OpenAPI served from the OpenAPI endpoint.
8484
* Generating OpenAPI documents in YAML format at build time is added in a future preview.
8585

8686
See [this PR](https://github.com/dotnet/aspnetcore/pull/58616) which added support for serving the generated OpenAPI document in YAML format.

0 commit comments

Comments
 (0)