Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger asp.net core failed to load api definition #1432

Open
moodsharkh opened this issue Jun 8, 2022 · 0 comments
Open

swagger asp.net core failed to load api definition #1432

moodsharkh opened this issue Jun 8, 2022 · 0 comments

Comments

@moodsharkh
Copy link

Hello I am sorry to submit this issue but I have been stuck for 3 days looking for resolution online.
I am having this issue when I am dealing with Geometry datatypes when I change the property to string everything works like a charm
bellow you may see that I used schema filter to remove Ignored data member , and document filter to remove anything related to nettopology.

VERSION:

Swashbuckle.AspNetCore 6.1.4
Swashbuckle.Core 5.6.0

STEPS TO REPRODUCE:

Swagger Configuration Class

    public static IServiceCollection AddSwaggerModule(this IServiceCollection services)
    {
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v2", new OpenApiInfo { Title = "Test API", Version = "0.0.1" });
            c.SchemaFilter<MySwaggerSchemaFilter>();
            c.DocumentFilter<RemoveBogusDefinitionsDocumentFilter>();
            c.ResolveConflictingActions(x => x.First());
        });

        return services;
    }

    public static IApplicationBuilder UseApplicationSwagger(this IApplicationBuilder app)
    {
        app.UseSwagger(c =>
        {
            c.RouteTemplate = "{documentName}/api-docs";
        });
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/v2/api-docs", "Test API");
        });
        return app;
    }
}
public class MySwaggerSchemaFilter : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter
{
    public void Apply(OpenApiSchema schema, SchemaFilterContext context)
    {
        if (schema?.Properties == null)
        {
            return;
        }

        var ignoreDataMemberProperties = context.Type.GetProperties()
            .Where(t => t.GetCustomAttribute<IgnoreDataMemberAttribute>() != null);

        foreach (var ignoreDataMemberProperty in ignoreDataMemberProperties)
        {
            var propertyToHide = schema.Properties.Keys
                .SingleOrDefault(x => x.ToLower() == ignoreDataMemberProperty.Name.ToLower());

            if (propertyToHide != null)
            {
                schema.Properties.Remove(propertyToHide);
            }
        }
    }
}

public class RemoveBogusDefinitionsDocumentFilter : Swashbuckle.AspNetCore.SwaggerGen.IDocumentFilter
{
    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {
        swaggerDoc.Components.Schemas.Remove("Districts");
        swaggerDoc.Components.Schemas.Remove("Geometry");
        swaggerDoc.Components.Schemas.Remove("CoordinateSequenceFactory");
        swaggerDoc.Components.Schemas.Remove("GeometryOverlay");
        swaggerDoc.Components.Schemas.Remove("NtsGeometryServices");
        swaggerDoc.Components.Schemas.Remove("CoordinateEqualityComparer");
        swaggerDoc.Components.Schemas.Remove("NtsGeometryServices");
        swaggerDoc.Components.Schemas.Remove("GeometryFactory");
        swaggerDoc.Components.Schemas.Remove("OgcGeometryType");
        swaggerDoc.Components.Schemas.Remove("Coordinate");
        swaggerDoc.Components.Schemas.Remove("Point");
    }
}

Entity class

public class Districts : BaseEntity<long>
{
    public string DistrictsDesc { get; set; }
    public string DistrictsDescAr { get; set; }

    [IgnoreDataMember]
    [Column(TypeName = "geometry")]
    public Geometry GeoPoly { get;  set; }
    public IList<Records> Records { get; set; } = new List<Records>();
    public long? RegionsId { get; set; }
    public Regions Regions { get; set; }

    public long? CitiesId { get; set; }
    public Cities Cities { get; set; }

   
}

EXPECTED RESULT:

To Generate this model.

ACTUAL RESULT:

Stuck on loading and when the memory is full it throws out of memory exception.

ADDITIONAL DETAILS

Is there a way to stop Swagger Gen from trying to deal with datatypes other than document filters?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant