简体   繁体   English

API文档中的自定义其他信息

[英]custom additional information in API documentation

在此处输入图片说明

I've read here about additional information of web API help page. 我在这里阅读有关Web API帮助页面的其他信息。 The data annotation actually provides the additional information for documentation. 数据注释实际上为文档提供了其他信息。 But I want to know that is there anyway to provide additional information without data annotations? 但是我想知道,是否仍可以在没有数据注释的情况下提供其他信息?

If yes then how? 如果是,那怎么办?

If not then is there anyway to override the additional information with data annotations for instance the 如果不是,那么无论如何都存在使用数据注释覆盖其他信息的情况,例如

[Required]

shows Required written in additional information but what if I want to show "This field is required" or something like that? 在其他信息中显示“必填”,但是如果我想显示“此字段必填”或类似内容怎么办?

Thanks 谢谢

EDIT see in picture I want to update that additional information without data annotation if possible. 编辑图片中的图片,如果可能的话,我想在没有数据注释的情况下更新该附加信息。

So the annotation allows you to further specify requirements, ie if you have the following model: 因此,注释使您可以进一步指定需求,即如果您具有以下模型:

public class MyModel {

    [Required(ErrorMessage = "You seriously need a name here bro")]
    public string Name{ get; set; }

}

You can then automatically have the validation message shown in your ASP.Net page like so: 然后,您可以自动在ASP.Net页面上显示验证消息,如下所示:

@model string
@Html.TextBoxFor(m => m)
@Html.ValidationMessageFor(model => model, "", new { @class = "text-danger"})

So basically, you add a field for the validation message that will be populated by ASP.Net when the Required attribute kicks in. 因此,基本上,您将为验证消息添加一个字段,当需要属性插入时,该字段将由ASP.Net填充。

You can edit the Required Attribute in the ModelDescriptionGenerator.cs 您可以在ModelDescriptionGenerator.cs编辑Required Attribute
Areas>HelpPage>ModelDescriptions>ModelDescriptionGenerator.cs
For example: 例如:

    [Required(ErrorMessage ="Must pass")]
    public string Name { get; set; }

I got: Additional information : Must pass 我得到:其他信息:必须通过

replace: 更换:

 { typeof(RequiredAttribute), a => "Required" }

with: 与:

{ typeof(RequiredAttribute), a => {
            RequiredAttribute b =(RequiredAttribute)a;
            return (b.ErrorMessage);
        }

see 看到

If you want to give custom additional information(using data annotation) then @Pedro G. Dias's answer is your solution but if you want to give additional information without using data annotation then I am afraid that it is not possible OR you have to use some alternative procedure to do so as commented by @DynamicVariable on your question. 如果您想提供自定义的其他信息(使用数据注释),那么@Pedro G. Dias的答案就是您的解决方案,但是如果您想提供其他信息而不使用数据注释,那么恐怕是不可能的,或者您必须使用一些方法@DynamicVariable对您的问题评论的替代过程。

PS. PS。 I've debugged documentation project to check and I found that addition information is actually provided by data annotations. 我调试了文档项目进行检查,发现附加信息实际上是由数据注释提供的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM