问题描述
public class MyAppService : AsyncCrudAppService<Entity,Dto,Guid,GetAllRequest,CreateRequest,UpdateRequest,GetRequest,DeleteRequest>,IMyAppService
{
/// <summary>
/// Return cities associated with zip code
/// </summary>
/// <param name="zipCode">Zip code to search. If null all cities are returned.</param>
/// <returns>Cities associated with zip code.</returns>
/// <exception cref="EntityNotFoundException">If zip code is provided but no associated city is found</exception>
/// <response code="404">If no city with zip code found</response>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<GetCitiesByZipCodeResponse> GetCitiesByZipCode(int? zipCode = null)
{
...
}
}
即使我有一个描述端点做什么的摘要,它也没有以招摇的方式显示。向 Swagger 添加有关应用服务方法的丰富信息的正确方法是什么?
它确实获得了 ProducesResponseType(StatusCodes.Status404NotFound)
的效果,并显示 404 作为可能的响应。
Swagger for GetCitiesByZipCode
解决方法
AppServices 会自动转换为 Controllers。但是您的自定义 Swagger 属性已被剥离。如果您有这样的要求,则创建一个新的 MyContoller
并在 AppService
中调用您的 Controller
方法。并使用以下属性为您的 Appservice
禁用远程服务功能
[RemoteService(IsEnabled = false)]
https://docs.abp.io/en/abp/latest/API/Auto-API-Controllers#remoteservice-attribute