diff --git a/docs/migrating-to-v10.md b/docs/migrating-to-v10.md index c9c0b4ddf2..dd8d638a3e 100644 --- a/docs/migrating-to-v10.md +++ b/docs/migrating-to-v10.md @@ -76,16 +76,22 @@ Migrating to Swashbuckle.AspNetCore v10+ will likely involve changes in the foll - Update any `using` directives that reference types from the `Microsoft.OpenApi.Models` namespace to use the new namespace `Microsoft.OpenApi`. - 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: - ```csharp - public void Apply(IOpenApiSchema schema, SchemaFilterContext context) - { + + + + ```cs + public void Apply(IOpenApiSchema schema, SchemaFilterContext context) + { if (schema is OpenApiSchema openApiSchema) { - // The properties are only mutable on the concrete type - openApiSchema.Type = JsonSchemaType.String; + // The properties are only mutable on the concrete type + openApiSchema.Type = JsonSchemaType.String; } - } + } ``` + snippet source | anchor + + - Update any use of `.Reference` properties (e.g. `OpenApiSchema.ReferenceV3`) to use the new `*Reference` class instead (e.g. `OpenApiSchemaReference`). - Replace usage of the `OpenApiSchema.Type` property using a string (e.g. `"string"` or `"boolean"`) with the `JsonSchemaType` flags enumeration. diff --git a/test/WebSites/DocumentationSnippets/MigrationSchemaFilter.cs b/test/WebSites/DocumentationSnippets/MigrationSchemaFilter.cs new file mode 100644 index 0000000000..ae9a7706be --- /dev/null +++ b/test/WebSites/DocumentationSnippets/MigrationSchemaFilter.cs @@ -0,0 +1,18 @@ +using Microsoft.OpenApi; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace DocumentationSnippets; + +public class MigrationSchemaFilter : ISchemaFilter +{ + // begin-snippet: Migrating-SchemaFilter + public void Apply(IOpenApiSchema schema, SchemaFilterContext context) + { + if (schema is OpenApiSchema openApiSchema) + { + // The properties are only mutable on the concrete type + openApiSchema.Type = JsonSchemaType.String; + } + } + // end-snippet +}