ODATA-如何在Odatamodelbuilder ActionConfiguration中定义参数格式
使用.NET CORE 3.1中的ODATA4,我创建了一个操作来插入某些实体,并在操作中添加了一个附加参数:
public void Apply(ODataModelBuilder builder, ApiVersion apiVersion)
{
var ac = builder.EntityType<MyThing>().Collection.Action("BulkAddMyThing");
ac.Parameter(typeof(datetime), "RefDate").Required();
ac.CollectionParameter<MyThing>("MyThings");
这会导致摇摇晃晃的请求结构,看起来像这样:
{
"RefDate": "2022-05-24T16:05:34.050Z",
"MyThings": [
{
"Name": "string",
"Rank": "string",
"Level": "string",
}
]
}
我想做的是BE能够将倒退为日期,而没有时间/时区,但是我不知道如何在弹药参数上定义任何类型的验证或默认值,以便Swagger Doc显示“ 2022-05-24”例如。我认为一个字符串,而不是带有正则表达式的DateTime作为替代方案,但是在Swagger Doc中指定示例输入时仍然很难。
Using Odata4 in .net core 3.1, I have created an action to Bulk insert some entities, and added an additional parameter to the action:
public void Apply(ODataModelBuilder builder, ApiVersion apiVersion)
{
var ac = builder.EntityType<MyThing>().Collection.Action("BulkAddMyThing");
ac.Parameter(typeof(datetime), "RefDate").Required();
ac.CollectionParameter<MyThing>("MyThings");
which results in a request structure in swagger that looks like this:
{
"RefDate": "2022-05-24T16:05:34.050Z",
"MyThings": [
{
"Name": "string",
"Rank": "string",
"Level": "string",
}
]
}
What I'd like to do is be able to force the RefDate to be a date, without the time/timezone, but I can't figure out how to define any kind of validation or default values on the RefDate parameter so that the swagger doc shows "2022-05-24" for example. I considered a string instead of a datetime with a regex as an alternative, but I'd still have trouble specifying the example input in the swagger doc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用其他类型,而不是
dateTime
:microsoft.odata.edm.date
在您的情况下:
You should use different type, instead of
DateTime
:Microsoft.OData.Edm.Date
in your case: