wkennedy / swagger4spring-web

Swagger support for Spring MVC
89 stars 46 forks source link

Using Lists inside a model schema #92

Open JamesAlger opened 9 years ago

JamesAlger commented 9 years ago

I am having real problems, getting my schema to play ball with Swagger using this project. and attempting to display the model schema for any List of Objects.

My rest api data is similar to the following for many of my cases: Assume I have a java.util.List of class SubObject { int id, String name }

{
    metadata : { ... }
    content : [
        { id: id1, name:name1 },  
        { id: id2, name:name2 }    .
    ]
}

Taking the swagger4spring-web-example project as a base, assume that instead of a Person having a category, it has a List of Categories attached to it with a getter setter.

@ApiModelProperty(value = "..", notes = "...", required = true, dataType="list[category]")
private List<Category> category;

When I look at the generated Schema I get:

...
Person: {
   ...
   category: {
    type: "List",
    qualifiedType: "List",
    position: 0,
    required: true,
    description: "Category of this person",
    allowableValues: { },
    items: {
        type: null,
        ref: "category",
        qualifiedType: "com.knappsack.swagger4springweb.models.Category"
    }
}
... 

Note that under items the type is null. When trying to display it I get:

image

I hate tried changing the datatype in every way I can think of, but can't get it to work.

Any idea what I'm missing?

Thanks.