Swagger XML setting attribute by annotations

Viewed 333

I would like to create a Swagger model that has a property which should be represented as an attribute when formatted as XML.

Here is my Swagger model class

@ApiModel
@JacksonXmlRootElement(localName = "LeadInformation")
public class LeadRequestVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(notes = "Request type", required = true, example="POST")
    @JacksonXmlProperty(localName = "RequestType", isAttribute = true)
    private String requestType;

    public String getRequestType() {
        return requestType;
    }

    public void setRequestType(String requestType) {
        this.requestType = requestType;
    }
}

In the Swagger UI this is being shown as

<?xml version="1.0"?>
<LeadRequestVO>
  <RequestType>POST</RequestType>
</LeadRequestVO>

But I would like "RequestType" to instead be an XML attribute:

<?xml version="1.0"?>
<LeadRequestVO RequestType="POST"></LeadRequestVO>

From what I've read, I need to add the following to the Swagger specification for this

xml:
    attribute: true

Is there any way to do this with the Swagger annotations? Any advise or alternatives are welcomed and thanks in advance!

0 Answers
Related