Swagger Api文档 - 模型列表<enum> </enum>

时间:2013-07-08 17:54:00

标签: c# asp.net swagger

如何为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"
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

遇到this post in the Swagger Google Group,这引出了我的回答:

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