Skip to content

Commit 85c998a

Browse files
committed
WN: P1
1 parent 3e65e28 commit 85c998a

File tree

1 file changed

+26
-2
lines changed
  • aspnetcore/release-notes/aspnetcore-10/includes

1 file changed

+26
-2
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Some of the changes you will see in the generated OpenAPI document include:
1212
- Nullable types no longer have the `nullable: true` property in the schema.
1313
- Instead of a `nullable: true` property, they have a `type` keyword whose value is an array that includes `null` as one of the types.
1414

15-
With this feature, the default OpenAPI version for generated documents is`3.1` . The version can be changed by explicitly setting the [OpenApiVersion](/dotnet/api/microsoft.aspnetcore.openapi.openapioptions.openapiversion) property of the [OpenApiOptions](/dotnet/api/microsoft.aspnetcore.openapi.openapioptions) in the `configureOptions` delegate parameter of [AddOpenApi](/dotnet/api/microsoft.extensions.dependencyinjection.openapiservicecollectionextensions.addopenapi).
15+
With this feature, the default OpenAPI version for generated documents is`3.1`. The version can be changed by explicitly setting the [OpenApiVersion](/dotnet/api/microsoft.aspnetcore.openapi.openapioptions.openapiversion) property of the [OpenApiOptions](/dotnet/api/microsoft.aspnetcore.openapi.openapioptions) in the `configureOptions` delegate parameter of [AddOpenApi](/dotnet/api/microsoft.extensions.dependencyinjection.openapiservicecollectionextensions.addopenapi).
1616

1717
```csharp
1818
builder.Services.AddOpenApi(options =>
@@ -35,7 +35,7 @@ OpenAPI 3.1 support was primarly added in the following [PR](https://github.com/
3535

3636
Support for OpenAPI 3.1 requires an update to the underlying OpenAPI.NET library to a new major version, 2.0. This new version has some breaking changes from the previous version. The breaking changes may impact apps if they have any document, operation, or schema transformers.
3737

38-
One of the most significant changes is that the `OpenApiAny` class has been dropped in favor of using `JsonNode` directly.If your transformers use `OpenApiAny`, you will need to update them to use `JsonNode` instead. For example, a schema transformer to add an example in .NET 9 might look like the following:
38+
One of the most significant changes is that the `OpenApiAny` class has been dropped in favor of using `JsonNode` directly. Transformers that use `OpenApiAny` need to be updated to use `JsonNode`. For example, a schema transformer to add an example in .NET 9 might look like the following:
3939

4040
```csharp
4141
options.AddSchemaTransformer((schema, context, cancellationToken) =>
@@ -73,6 +73,30 @@ In .NET 10 the transformer to do the same task will look like the following:
7373
});
7474
```
7575

76+
The following example shows the changes in diff format.
77+
78+
```diff
79+
options.AddSchemaTransformer((schema, context, cancellationToken) =>
80+
{
81+
if (context.JsonTypeInfo.Type == typeof(WeatherForecast))
82+
{
83+
- schema.Example = new OpenApiObject
84+
+ schema.Example = new JsonObject
85+
{
86+
- ["date"] = new OpenApiString(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")),
87+
+ ["date"] = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"),
88+
- ["temperatureC"] = new OpenApiInteger(0),
89+
+ ["temperatureC"] = 0,
90+
- ["temperatureF"] = new OpenApiInteger(32),
91+
+ ["temperatureF"] = 32,
92+
- ["summary"] = new OpenApiString("Bracing"),
93+
+ []"summary"] = "Bracing",
94+
};
95+
}
96+
return Task.CompletedTask;
97+
});
98+
```
99+
76100
Note that these changes are necessary even when only congfiguring the OpenAPI version to 3.0.
77101

78102
### OpenAPI in Yaml

0 commit comments

Comments
 (0)