Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 在Swagger文档中传递可接受的字符串值_Spring_Spring Boot_Swagger - Fatal编程技术网

Spring 在Swagger文档中传递可接受的字符串值

Spring 在Swagger文档中传递可接受的字符串值,spring,spring-boot,swagger,Spring,Spring Boot,Swagger,这里是SpringBoot(Java)。Swagger是否有任何可自定义/可配置的字段,允许您指定端点接受或返回的特定String值 例如,我可能有这样一个端点: POST /v1/{accountId}/preferences { "notificationTypes" : [ ] } …在其请求实体中接受通知类型的数组。也许我的服务器只允许AdminNotification和simplelert作为此notificationTypes的可能值,这意味着: POST /v1

这里是SpringBoot(Java)。Swagger是否有任何可自定义/可配置的字段,允许您指定端点接受或返回的特定
String

例如,我可能有这样一个端点:

POST /v1/{accountId}/preferences
{
    "notificationTypes" : [

    ]
}
…在其请求实体中接受
通知类型的数组。也许我的服务器只允许
AdminNotification
simplelert
作为此
notificationTypes
的可能值,这意味着:

POST /v1/{accountId}/preferences
{
    "notificationTypes" : [
        "SimpleAlert"
    ]
}
有效,但:

POST /v1/{accountId}/preferences
{
    "notificationTypes" : [
        "Hello"
    ]
}

抛出400个错误请求。我希望能够在我的招摇过市的文档中传达这一点这种配置可以通过注释实现吗?

我认为一个好的解决方案是使用可接受的值创建一个枚举。这样,它将自动在Swagger中描述:

@ApiModelProperty(value= "Accepted values are :")
public NotificationTypes notificationTypes;


public enum NotificationTypes {SimpleAlerts, AdminNotifications}
在生成的规范中,它给出了以下内容:


玩得开心

您可以使用类似-

通知类型:
类型:字符串
示例:[“simplelert”、“otherValue”]

看-

ref-

好主意,如果不对代码库进行大量重构,我就无法创建枚举,但是我将使用
@ApiModelProperty
注释来获取我需要的内容。。。非常感谢。