【问题标题】:Swagger Api Documentation - Model List<Enum>Swagger Api 文档 - 模型列表<Enum>
【发布时间】:2013-07-08 17:53:59
【问题描述】:

应该如何为 Swagger 建模此类以正确解释它?

public myEnum {
    alpha,
    bravo,
    charlie
}

public class myClass {
    public List<myEnum> myList { get; set; }
}

我不能简单地这样做:

{
    "myClass": {
        "id": "myClass",
        "properties": {
            "myList": {
                "type": "string", //??? it isn't a string, it's a List...
                "allowableValues": {
                    "valueType": "LIST",
                    "values": [
                        "alpha",
                        "bravo",
                        "charlie"
                    ]
                }
            }
        }
    }
}

这也没有意义:

{
    "myEnum": {
        "id": "myEnum",
        "properties": {
            //??? there aren't any...
        }
    },
    "myClass": {
        "id": "myClass",
        "properties": {
            "myList": {
                "type": "List",
                "items": {
                    "$ref": "myEnum"
                }
            }
        }
    }
}

【问题讨论】:

    标签: c# asp.net swagger


    【解决方案1】:

    遇到this post in the Swagger Google Group,这让我得到了这个答案:

    {
        "myClass": {
            "id": "myClass",
            "properties": {
                "myList": {
                    "type": "List",
                    "items": {
                        "type": "string"
                    },
                    "allowableValues": {
                        "valueType": "LIST",
                        "values": [
                            "alpha",
                            "bravo",
                            "charlie"
                        ]
                    }
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      相关资源
      最近更新 更多