我将我的 netcore 2.1 项目升级到 2.2 并且我的 swagger 页面有问题。
以前在 swagger bad response 中,它只显示没有模型的“错误请求”。
但是在我升级到 net core 2.2 后,错误请求示例中显示了一个模型。下图。
我如何隐藏它以便它只显示“错误的请求”。
我已经使用 CustomApiConvention 进行了测试,但到目前为止还没有成功。
[HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesDefaultResponseType]
public async Task<ActionResult<Employee>> GetEmployee(int id)
{
var employee = await _context.Employee.FindAsync(id);
if (employee == null)
{
return NotFound();
}
return employee;
}
Run Code Online (Sandbox Code Playgroud)
我如何隐藏它以便它只显示“错误的请求”?
以下构造函数参数没有用于使用 moq 和 xunit 进行单元测试的匹配装置数据。
已经使用依赖注入和模拟来测试类。
//this is how i register the DI.
services.AddScoped<IWaktuSolatServiceApi, WaktuSolatServiceApi>();
public interface IWaktuSolatServiceApi
{
Task<Solat> GetAsyncSet();
}
// the unit test.
public class UnitTest1
{
Mock<IWaktuSolatServiceApi> waktu;
public UnitTest1(IWaktuSolatServiceApi waktu)
{
this.waktu = new Mock<IWaktuSolatServiceApi>();
}
[Fact]
public async Task ShoudReturn()
{
var request = new Solat
{
zone = "lala"
};
var response = waktu.Setup(x =>
x.GetAsyncSet()).Returns(Task.FromResult(request));
}
}
Run Code Online (Sandbox Code Playgroud)
但是我收到此错误以下构造函数参数没有匹配的夹具数据。