【问题标题】:Adding description to properties while generating JSON schema using json.net在使用 json.net 生成 JSON 模式时向属性添加描述
【发布时间】:2013-02-11 12:00:22
【问题描述】:

是否可以在属性中添加描述属性?

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

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

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

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

}

或者也许有一种方法可以将 VS 样式的 cmets 添加到 JSON 模式中作为描述?

【问题讨论】:

  • 您找到解决方案了吗?

标签: c# json.net


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 2012-05-03
    • 2016-02-07
    • 1970-01-01
    相关资源
    最近更新 更多