Skip to content

OpenApiSchemaCustomizations.GenerateSwashbuckleSchemaFilter generates invalid code with newer Swashbuckle >10.0 #881

@JoschiZ

Description

@JoschiZ

Describe the bug

Swashbucke verison 10.0.0 changed to OpenAPI.NET v2.3 which brings quite some breaking changes to the public API.
See v10.0.0 for details.

Notable the interface ISchemaFilter changed from

public interface ISchemaFilter
{
    void Apply(OpenApiSchema schema, SchemaFilterContext context);
}

to

public interface ISchemaFilter
{
    void Apply(IOpenApiSchema schema, SchemaFilterContext context);
}

which leads to Vogen generating an uncompilable 'ISchemaFilter'

public class VogenSchemaFilterMapVogenTypesInReproduceVogenError : global::Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter
{
    private const BindingFlags _flags = BindingFlags.Public | BindingFlags.Instance;
// Symbol not found and unimplemented ISchemaFilter because of that.
    public void Apply(global::Microsoft.OpenApi.Models.OpenApiSchema schema, global::Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext context)
    {
....
}

The generated code has to generate global::Microsoft.OpenApi.IOpenApiSchema instead for the Apply method signature

Steps to reproduce

  1. Create a new project
  2. Add
        <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="10.1.0" />
        <PackageReference Include="Vogen" Version="8.0.4" />
  1. Set [assembly: VogenDefaults(openApiSchemaCustomizations: OpenApiSchemaCustomizations.GenerateSwashbuckleSchemaFilter)]
  2. Add a value object
  3. try to compile the code

Expected behaviour

Vogen should use global::Microsoft.OpenApi.IOpenApiSchema` instead of global::Microsoft.OpenApi.Models.OpenApiSchema` if the swagger gen version is >=10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions