添加新应用程序服务时 Swagger 崩溃

Swagger crashes when I add a new Application Service

Before you read , know that I have already looked at this post and... The problem is ALMOST the same, and I've tried the solution. So this post is not duplicated.

我们使用了 ASP.NET 样板启动模板。 我们开发了一些应用服务,其结构如下:

public interface IFooAppService : 
    IAsyncCrudAppService<FooDto, Guid, GetAllFooDto, CreateFooDto, UpdateFooDto>
    // Abp.Application.Services.IAsyncCrudAppService<...>
{
}

[AbpAuthorize("Authorize.Foo")]
public class FooAppService : 
    AsyncCrudAppService<Foo, FooDto, Guid, FooFilterInput, CreateFooDto, FooDto>,
    IFooAppService
{
    private readonly BarManager _barManager;
    public FooAppService(IBarManager barManager, IRepository<Foo, Guid> repository)
        : base (repository)
    {
        _barManager = barManager;
    }

    public override async Task<FooDto> Create(CreateFooDto input)
    {
        // create with repository
    }

    // other overridden Actions and Foo interface implementation
}

一切都与可用文档一致 here

所有方法都很有效,我可以使用所有 Swagger 功能。配置似乎没问题(我们为ABP注入一些post-JavaScript,...)等

最初,我有以下版本:

我们有 385 APIs.

我添加了一个新的 AppService Commitment 及其管理器、Dtos 等

在那一刻,当我开始大摇大摆地开始时,我的浏览器崩溃并显示一条消息,询问我是否要停止脚本(IE、Edge、Firefox、Chrome、... ).

在调试模式下,我没有关于可能抛出的异常的信息。

尝试过:

  1. 更新 Swashbuckle.AspNetCore NuGet 包(所有版本:1.2、2.X 和 3.0.0)

    • 在版本1.X中,我遇到了同样的问题。
    • 在2.5版本中,UI不显示。
    • 在其他版本中,显示UI,我可以使用所有方法,除了我的新方法,承诺。当我单击悬停他时,我只有微调器...浏览器冻结并询问我是否要停止脚本或等待。

在 Chrome、Chrome 上引发错误:

  1. 删除承诺的覆盖方法

以防我的代码在重写的方法中出错。

[AbpAuthorize("Authorize.Commitments")]
public class CommitmentAppService : 
    AsyncCrudAppService<Commitment, CommitmentDto, Guid, CommitmentFilterInput, CreateCommitmentDto, UpdateCommitmentDto>,
    ICommitmentAppService
{
    private readonly ICommitmentManager _commitmentManager;
    private readonly IFundManager _fooManager;
    private readonly ILimitedPartnerManager _barManager;

    public CommitmentAppService(
        ICommitmentManager commitmentManager,
        IFooManager fooManager,
        IBarManager barManager,
        IOneRepository<Commitment, Guid> repository)
        : base(repository)
    {
        _commitmentManager = commitmentManager;
        _fooManager = fooManager;
        _barManager = barManager;
        _commitmentManager = commitmentManager;
    }
    // nothing here
}

同样的结果。

  1. 仅使用一个 DTO (CommitmentDto) 而不是一组 DTO CommitmentDto、CreateCommitmentDto、UpdateCommitmentDto、...

    • AsyncCrudAppService<Commitment, CommitmentDto, Guid> 其中定义了实体、其 DTO 和 PK 类型
    • AsyncCrudAppService<Commitment, CommitmentDto, Guid, CommitmentFilterInput> 其中定义了实体、其默认 DTO、PK 类型和过滤器输入 DTO
    • AsyncCrudAppService<Commitment, CommitmentDto, Guid, CommitmentFilterInput, CommitmentDto> 其中定义了实体、其默认 DTO、PK 类型、过滤器输入 DTO 和创建实体 DTO
    • AsyncCrudAppService<Commitment, CommitmentDto, Guid, CommitmentFilterInput, CommitmentDto, CommitmentDto> 其中定义了实体、其默认 DTO、PK 类型、过滤器输入 DTO、创建实体 DTO 和更新实体 DTO

同样的结果。

  1. 使用其他 AsyncCrudAppService 实现

    • AsyncCrudAppService<Commitment, CommitmentDto, Guid>在哪里定义了实体,它的 DTO 和 PK 类型
    • AsyncCrudAppService<Commitment, CommitmentDto, Guid, CommitmentFilterInput> 其中定义了实体、其默认 DTO、PK 类型和过滤器输入 DTO
    • AsyncCrudAppService<Commitment, CommitmentDto, Guid, CommitmentFilterInput, CreateCommitmentDto> 其中定义了实体、其默认 DTO、PK 类型、过滤器输入 DTO 和创建实体 DTO
    • AsyncCrudAppService<Commitment, CommitmentDto, Guid, CommitmentFilterInput, CreateCommitmentDto, UpdateCommitmentDto> 其中定义了实体、其默认 DTO、PK 类型、过滤器输入 DTO、创建实体 DTO 和更新实体 DTO

同样的结果。

  1. 使用编辑器验证

Swagger(OpenApi,我知道...)在 https://editor.swagger.io/

提供在线编辑器

我已复制 swagger.json 并将其粘贴到编辑器中。 我有一些关于语义的错误(我认为这是由从 Json 到 Yaml 的转换引起的)。

Semantic error at paths./api/services/app/Foo/GetAll.get.responses.200.schema.$ref $ref values must be RFC3986-compliant percent-encoded URIs Jump to line 234

Semantic error at paths./api/services/app/Foo/GetAll.get.security.0.0 Security scope definition Funds.BankAccounts could not be resolved Jump to line 240

我没有发现 CommitmentAppService 的特殊错误。我可以展开除 Commitment 方法之外的所有项目...浏览器崩溃,blah blah blah

  1. 重命名对多多的承诺

  2. 删除一些方法 以验证 API 的数量对于 Swagger

    [=130 来说不是太大=]
  3. Import swagger.json in an Azure API Management 我可以扩展所有方法,甚至 Commitment 方法...但我不不知道如何使用我的数据库(而且不是我的objective,我想在本地调试)。

  4. 清理构造函数...也许我注入的项目之一是错误的?

public CommitmentAppService(IRepository<Commitment, Guid> repository) 
: base(repository)
{ /**/ }

没有...


如果有人有解决方案...

都是我的错!

我需要添加 Commitment 及其 Dtos 代码以了解我在哪里犯了错误...

[Table("Commitment")]
public class Commitment : FullAuditedEntity<Guid>, 
{
    public string Property1 { get; set; }
    public Foo Foo { get; set; }
    public Guid FooId { get; set; }
}

[AutoMapFrom(typeof(Commitment))]
[AutoMapTo(typeof(Commitment), MemberList = AutoMapper.MemberList.Source)]
public class CommitmentDto : EntityDto<Guid>
{
    public string Property1 { get; set; }
    public Foo Foo { get; set; }
    public Guid FooId { get; set; }
}

我在 CommitmentDto 中使用 entity 对象而不是 Dtos... 事实上,我需要使用 FooDto (而不是 Foo)在 CommitmentDto.