abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.83k stars 3.42k forks source link

Swagger cannot read data types of NetTopologySuite #17367

Open tianxin8206 opened 1 year ago

tianxin8206 commented 1 year ago

Is there an existing issue for this?

Description

I using NTS types in my model,swagger is not displaying content properly.

Reproduction Steps

Entity Code:

using System;
using NetTopologySuite.Geometries;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;

namespace Desktop.Gis;

public class RoadwayInfo : Entity<Guid>, IHasCreationTime, ISoftDelete
{
    public LineString? TwoDimension { get; set; }

    public LineString? ThreeDimension { get; set; }

    public DateTime CreationTime { get; }

    public bool IsDeleted { get; }
}

DTO Code:

using System;
using System.Collections.Generic;
using NetTopologySuite.Geometries;
using Volo.Abp.Application.Dtos;

namespace Desktop.Gis;

public class RoadwayInfoDto : EntityDto<Guid>
{
    public LineString? TwoDimension { get; set; }

    public LineString? ThreeDimension { get; set; }

    public DateTime CreationTime { get; }

    public bool IsDeleted { get; }
}

Swagger Code:

private void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration)
{
    context.Services.AddAbpSwaggerGenWithOAuth(
        configuration["AuthServer:Authority"],
        new Dictionary<string, string>
        {
            {"Gis", "Gis API"}
        },
        options =>
        {
            options.SwaggerDoc("v1", new OpenApiInfo {Title = "Gis API", Version = "v1"});
            options.DocInclusionPredicate((_, _) => true);
            options.CustomSchemaIds(type => type.FullName);
            options.AddGeometry(GeoSerializeType.Geojson);
        });
}

app.UseSwagger();
app.UseAbpSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Gis API");

    var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
    c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
    c.OAuthScopes("Gis");
});

EntityFrameworkCoreModule Code:

public class GisEntityFrameworkCoreModule : AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        // https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic
        AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddAbpDbContext<GisDbContext>(options =>
        {
            /* Remove "includeAllEntities: true" to create
             * default repositories only for aggregate roots */
            options.AddDefaultRepositories(includeAllEntities: true);
        });

        Configure<AbpDbContextOptions>(options =>
        {
            /* The main point to change your DBMS.
             * See also GisMigrationsDbContextFactory for EF Core tooling. */
            options.UseNpgsql(o => o.UseNetTopologySuite());
        });
    }
}

NetTopologySuite version:2.5.0 Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite:7.0.4

Expected behavior

No response

Actual behavior

image Memory keeps increasing.

Regression?

No response

Known Workarounds

This problem was not found using an empty asp.net core mvc template.

Version

7.3.2

User Interface

MVC

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

maliming commented 1 year ago

You can continue to check what objects are increasing in memory.

Maybe related to https://github.com/dotnet/aspnetcore/issues/17979

tianxin8206 commented 1 year ago

image

After debugging with windbg, it has been found that ApiParameterDescription occupies a large amount of memory. I have uploaded the example code here, and you can also try to reproduce it. @maliming

maliming commented 1 year ago

hi

This is related to aspnetcore and swagger. We can't do anything.

See https://github.com/dotnet/aspnetcore/issues/17979