3
votes

I'm using Swagger to generate documentation for my jax-rs based API. In one of my models I have the following property:

@XmlElementWrapper(name = "clip_list")
@XmlElement(name = "clip")
public List<Clip> mClips = new ArrayList<Clip>();

However the JSON model generated in the UI is as follows:

"clip": [
    {
    "duration":"",
    "url":"",
    "thumb":"",
    }
]

So obviously the XmlElementWrapper annotation is not parsed. How can I force Swagger to correctly nest elements?

The output should be like :

"clip_list": [
    {
    "duration":"",
    "url":"",
    "thumb":"",
    }
]
2

2 Answers

0
votes

The output looks correct. For more details, have a look at this issue in the Swagger repository.

You could try using the @ApiModelProperty annotation to manipulate the metadata of a model property, as following:

@XmlElement(name = "clip")
@ApiModelProperty(value = "clip_list")
@XmlElementWrapper(name = "clip_list")
public List<Clip> mClips = new ArrayList<Clip>();

For more details about the @ApiModelProperty API, have a look at the javadocs.

0
votes

Soved the issue. Just exclude the following dependencies from swagger dependency.

          <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.jaxrs</groupId>
                    <artifactId>jackson-jaxrs-json-provider</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-client</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-server</artifactId>
                </exclusion>
          </exclusions>

After excluding these i was able to get the annotations working.