Swagger API文档 - 模型 List<枚举>

3

如何对这个类进行建模,以便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

我在Swagger Google Group中看到了这篇帖子,它引导我找到了这个答案:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接