最近,我一直在努力利用元数据页面,以使我们的文档更具响应性。我发现ApiMember似乎不适用于使用dotnet核心的项目。
这是我的DTO,已更新为包含dto定义的完整内容
using ServiceStack;
[Api("Test request")]
[Route("/test/{Input}","GET")]
[Route("/test")]
public class TestRequest:IReturn<TestResponse>
{
[ApiMember(Name="Parameter name", Description = "Parameter Description",
ParameterType = "body", DataType = "string", IsRequired = true)]
public string Input { get; set; }
}
public class TestResponse
{
public string Output { get; set; }
}
//Validator
public class TestRequestValidator : AbstractValidator<TestRequest>
{
public TestRequestValidator()
{
RuleFor(r => r.Input).NotEmpty();
}
}
我希望名称和描述应该出现在元数据页面中,但事实并非如此。我该怎么办?
而且,如果我可以提出第二个问题,因为我有完整的dto,我必须要求验证器(使用fluentvalidation lib)确实有效,但是,我如何将它连接到记录器?例如,当输入为空时,我希望记录器保留该信息,我该怎么办?
更新: 我回到了我的代码,我发现如果我改变我的DTO Testrequest它就可以了。具体来说,以下工作。
namespace web
{
[Api("Test request")]
[Route("/test/{Input}", "GET")]
[Route("/test")]
public class TestRequest : IReturn<TestResponse>
{
[ApiMember(Name = "Parameter name", Description = "Parameter Description",
ParameterType = "body", DataType = "string", IsRequired = true)]
public string Input { get; set; }
}
public class TestResponse
{
public string Output { get; set; }
}
}
这不是
[Api("Test request")]
[Route("/test/{Input}", "GET")]
[Route("/test")]
public class TestRequest : IReturn<TestResponse>
{
[ApiMember(Name = "Parameter name", Description = "Parameter Description",
ParameterType = "body", DataType = "string", IsRequired = true)]
public string Input { get; set; }
}
public class TestResponse
{
public string Output { get; set; }
}
答案 0 :(得分:0)
我刚刚创建了NetCoreApps/scratch项目来测试您的TestRequest服务:
void session::subscribirse(std::string a_which)
{
try
{
//We obtain a reference to the group of sockets subscribed to this service name
vector<weak_ptr<session>>& grupo = cloud::subscribed.at(a_which); //HERE
grupo.emplace_back(shared_from_this() );
}
catch(out_of_range& e) //The group didn't exist (no-one had subscribed to it yet)
{
vector<weak_ptr<session>> new_group;
new_group.emplace_back(shared_from_this());
cloud::subscribed.emplace(make_pair(a_which, new_group));
}
catch(...)
{
cout << "unexpected exception during subscribe\n";
}
subscriptions_.emplace_back(a_which);
consumed_ = true;
}
使用NuGet上最新的.NET Core v1.0.41正常工作:
如果您没有使用最新版本的.NET Core,则需要升级。