如何将Swagger设置为忽略创建方法上的ID属性? C#ASP.NET核心招摇
我该如何要求Swagger不要要求ID进行邮政方法(在DB中创建实体)?
{
"id": 0,
"name": "string",
"quantity": 0,
"typeId": 0,
"brandId": 0
}
我的SQL Server中有一个自动介入,因此我认为在Frontend上没有必要输入ID,并且ID不会有字段。但是,是否可以要求Swagger不要显示ID?
How can I ask Swagger not to ask id for POST method (creation of entity in DB)?
{
"id": 0,
"name": "string",
"quantity": 0,
"typeId": 0,
"brandId": 0
}
There is an auto-incrementation in my SQL Server, so I think on frontend it's not necessary to input Id and there will be no field for Id. But is it possible to ask swagger not to show id?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不需要在项目中的其他地方序列化模型,则可以尝试使用Jonignore属性
我尝试如下:
结果:

You could try with JsonIgnore attribute if you don't need to Serialize the model somewhere else in your project
I tried as below:
The result:

创建一个专用的Create DTO:
在您的控制器中创建一个从传入的
Create To To
对象创建DB实体的实例。Create a dedicated create dto:
and in your controller create an instance of your db entity from the incoming
CreateDto
object.现在有一种更好的方法。 您需要做两件事
在
There is a better way now with now. There are two things you need to do
See more about it in the Documentation