使用json.net生成JSON模式时向属性添加描述

时间:2013-02-11 12:00:23

标签: c# json.net

是否可以向属性添加描述属性?

我正在使用json.net来生成架构:

var shema = new Newtonsoft.Json.Schema.JsonSchemaGenerator();
var sh = shema.Generate(typeof(APIDocumentation.AlertDTO), false).ToString();

我想为用户添加一些简单的文档,以了解每个字段的含义。 现在我可以使用[JsonObject(Description =“my description”)]向类添加description属性,但它不能与class中的属性一起使用。是否有可能做类似的事情:

[JsonObject(Description = "My description")]
public class AlertDTO
{
    [SomeAttribute(Description="Property description")]
    public string Type { get; set; }

}

或者有可能采用VS样式注释并将它们添加到JSON模式作为描述?

1 个答案:

答案 0 :(得分:2)

您可以使用System.ComponentModel命名空间中的Description属性。

我花了一些时间才找到,但文档中有一个示例:https://www.newtonsoft.com/jsonschema/help/html/GenerateWithDescriptions.htm

相关问题