Skip to content

Commit 6202ca9

Browse files
authored
Add clarifying example in migration guide to v10 (#3672)
Added a concrete example on how to check for concrete types in order to mutate model properties in the migration guide.
1 parent d12336c commit 6202ca9

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

docs/migrating-to-v10.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,18 @@ Migrating to Swashbuckle.AspNetCore v10+ will likely involve changes in the foll
7373

7474
- Update any NuGet package references for Swashbuckle.AspNetCore and Microsoft.OpenApi to v10.0.0+ and v2.3.0+ respectively.
7575
- Update any `using` directives that reference types from the `Microsoft.OpenApi.Models` namespace to use the new namespace `Microsoft.OpenApi`.
76-
- Update model references (e.g. `OpenApiSchema`) to use the new interfaces (e.g. `IOpenApiSchema`) and the relevant concrete types to mutate them (e.g. `OpenApiSchema`).
76+
- Update model references (e.g. `OpenApiSchema`) to use the new interfaces (e.g. `IOpenApiSchema`) and use the relevant concrete types to mutate them (e.g. `OpenApiSchema`). An example of this is shown below for an `ISchemaFilter` implementation:
77+
78+
```csharp
79+
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
80+
{
81+
if (schema is OpenApiSchema openApiSchema)
82+
{
83+
// The properties are only mutable on the concrete type
84+
openApiSchema.Type = JsonSchemaType.String;
85+
}
86+
}
87+
```
7788
- Update any use of `.Reference` properties (e.g. `OpenApiSchema.ReferenceV3`) to use the new `*Reference` class instead (e.g. `OpenApiSchemaReference`).
7889
- Replace usage of the `OpenApiSchema.Type` property using a string (e.g. `"string"` or `"boolean"`) with the `JsonSchemaType` flags enumeration.
7990
- Replace usage of the `OpenApiSchema.Nullable` property by OR-ing the `JsonSchemaType.Null` value to `OpenApiSchema.Type` (e.g. `schema.Type |= JsonSchemaType.Null;`).

0 commit comments

Comments
 (0)