简体   繁体   English

AsyncCrudAppService 在提供 TCreateInput 和 TUpdateInput 时打破了 Swagger

[英]AsyncCrudAppService Breaks Swagger When Providing TCreateInput and TUpdateInput

I recently downloaded a Single Page Web Application (Angular) from https://aspnetboilerplate.com/Templates using 3.x target version.我最近使用 3.x 目标版本从https://aspnetboilerplate.com/Templates下载了一个单页 Web 应用程序(Angular)。

I just simply added a few entities and then started to follow the steps on this page https://aspnetboilerplate.com/Pages/Documents/Application-Services我只是简单地添加了一些实体,然后开始按照此页面https://aspnetboilerplate.com/Pages/Documents/Application-Services上的步骤操作

Things do work well for me to Get, List, Update, and Delete entities when my app service class is just inheriting AsyncCrudAppService<Entities.PhoneBook, PhoneBookDto, long, GetAllPhoneBooksInput>, however when it is inheriting AsyncCrudAppService<Entities.PhoneBook, PhoneBookDto, long, GetAllPhoneBooksInput, CreatePhoneBookInput, and UpdatePhoneBookInput> the swagger definition will no longer load.当我的应用程序服务类仅继承 AsyncCrudAppService<Entities.PhoneBook, PhoneBookDto, long, GetAllPhoneBooksInput> 时,获取、列出、更新和删除实体对我来说效果很好,但是当它继承 AsyncCrudAppService<Entities.PhoneBook, PhoneBookDto 时, long、GetAllPhoneBooksInput、CreatePhoneBookInput 和 UpdatePhoneBookInput> 将不再加载 swagger 定义。

GitHub Repo: https://github.com/woodman231/MyPhoneBooks GitHub 存储库: https : //github.com/woodman231/MyPhoneBooks

(which currently does not work and will not load Swagger page). (目前不起作用,也不会加载 Swagger 页面)。

I can get the swagger page to load by removing CreatePhoneBookInput and UpdatePhoneBookInput from我可以通过从中删除 CreatePhoneBookInput 和 UpdatePhoneBookInput 来加载 swagger 页面

https://github.com/woodman231/MyPhoneBooks/blob/main/aspnet-core/src/MyPhoneBooks.Application/SimpleCrudAppServices/ISimplePhoneBookCrudAppService.cs#L9 https://github.com/woodman231/MyPhoneBooks/blob/main/aspnet-core/src/MyPhoneBooks.Application/SimpleCrudAppServices/ISimplePhoneBookCrudAppService.cs#L9

and

https://github.com/woodman231/MyPhoneBooks/blob/main/aspnet-core/src/MyPhoneBooks.Application/SimpleCrudAppServices/SimplePhoneBookCrudAppService.cs#L14 https://github.com/woodman231/MyPhoneBooks/blob/main/aspnet-core/src/MyPhoneBooks.Application/SimpleCrudAppServices/SimplePhoneBookCrudAppService.cs#L14

However, again I am still unable to create entities using this default implementation.但是,我仍然无法使用此默认实现创建实体。 Any ideas?有任何想法吗?

Ok I figured it out.好吧,我想通了。 I had also made a DIY AppService and some of the DTO Class Names associated with the DIY App Service clashed with the DTO Class Names associated with the Automated Service.我还制作了一个 DIY AppService,一些与 DIY App Service 相关的 DTO 类名称与与自动化服务相关的 DTO 类名称发生冲突。 It was acceptable in .NET since they were in different name spaces but once the swagger definition was configured I assume that there was multiple instances of the same DTO Defition.这在 .NET 中是可以接受的,因为它们位于不同的名称空间中,但是一旦配置了 swagger 定义,我假设有多个相同 DTO 定义的实例。 I checked the AbpLogs table but they didn't give me much details as to the specifics of the internal server error while loading the definition.我检查了 AbpLogs 表,但他们没有提供有关加载定义​​时内部服务器错误的详细信息的详细信息。 It sure would have been useful to know that.知道这一点肯定会很有用。

I have cloned your repo and run it and I figured out the error, first as I tell you in comments I verified the text log, and it said the next:我已经克隆了你的 repo 并运行了它,我发现了错误,首先我在评论中告诉你我验证了文本日志,它说下一个:

System.InvalidOperationException: Can't use schemaId "$CreatePhoneBookInput" for type "$MyPhoneBooks.SimpleCrudAppServices.Dtos.CreatePhoneBookInput". System.InvalidOperationException:不能将 schemaId“$CreatePhoneBookInput”用于类型“$MyPhoneBooks.SimpleCrudAppServices.Dtos.CreatePhoneBookInput”。 The same schemaId is already used for type "$MyPhoneBooks.PhoneBooks.Dtos.CreatePhoneBookInput"相同的 schemaId 已用于类型“$MyPhoneBooks.PhoneBooks.Dtos.CreatePhoneBookInput”

What happenig is that you have these two classes UpdatePhoneBookInput , CreatePhoneBookInput repeated in SanokeCrudAppServices\\Dtos and PhoneBooks\\Dtos发生的事情是你有这两个类UpdatePhoneBookInputCreatePhoneBookInputSanokeCrudAppServices\\DtosPhoneBooks\\Dtos

You have the classes in both folders with same exact name, and thats the problem, if you change the name in whatever place the swagger definition will load without errors, I have do it like this and everything works fine!您在两个文件夹中都有具有相同名称的类,这就是问题所在,如果您在 swagger 定义将加载而不会出错的任何位置更改名称,我已经这样做了,并且一切正常!

Change the name in one of the places, and all will be working fine在其中一个地方更改名称,一切都会正常工作

Personally I don't like to use a different Dto for Create and Update for me is easier to user just one Dto for all.就我个人而言,我不喜欢使用不同的DtoCreateUpdate对我来说更容易使用一个Dto

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM