我们可以使用Swagger的描述符手动添加这些类型,并在服务上注释它们。以下是一个示例:
public class MyCreateInputDto
{
// Add a Swagger description for this type
[SwaggerSchema(Description = "Input type for creating a new entity")]
public string Name { get; set; }
}
public class MyUpdateInputDto
{
// Add a Swagger description for this type
[SwaggerSchema(Description = "Input type for updating an existing entity")]
public int Id { get; set; }
// Add a Swagger description for this property
[SwaggerSchema(Description = "New name for the entity")]
public string Name { get; set; }
}
public interface IMyAppServiceAsync : IAsyncCrudAppService
{
// Add a Swagger description for this method
[SwaggerOperation(Summary = "Creates a new entity", OperationId = "MyAppService.Create")]
Task Create([FromBody] MyCreateInputDto input);
// Add a Swagger description for this method
[SwaggerOperation(Summary = "Updates an existing entity by ID", OperationId = "MyAppService.Update")]
Task Update(int id, [FromBody] MyUpdateInputDto input);
}
在代码中添加这些描述符后,Swagger将正确显示这些类型并提供有关如何填充它们的信息。