swagger @ApiModelProperty example value for List property

前端 未结 9 2348
温柔的废话
温柔的废话 2020-12-14 00:10

I have one class in which there is one property which is List

public class MyClass {
    ....
    @ApiModelProperty(position = 2)
         


        
9条回答
  •  感情败类
    2020-12-14 01:05

    This seems to not be supported by the Swagger API. In the mean time you can use this Springfox Plugin to generate a singleton list example (one value list) https://github.com/aaitmouloud/springfox-collection-example-plugin

    Just add this to you pom.xml

    
        com.github.aaitmouloud
        springfox-collection-example-plugin
        2.9.2
    
    

    And import the right classes to your Spring context

    @ComponentScan({"springfox.collection.example.plugins"})
    

    You should then declares a single value example on your property and it will be transformed to a singleton list example by the plugin (works for all java.util.Collection classes)

    @ApiModelProperty(value ="my property description", example = "2019-12-20T12:00:00")
    @NotNull
    private List dates;
    

    Disclaimer: I am the author of this plugin.

提交回复
热议问题