Skip to content

Composed models duplicate properties from base models. #1373

@tomtit

Description

@tomtit

Swagger version is 1.5.2 (the same issue in 1.5.4-SNAPSHOT).
Here is the classes hierarchy:

@ApiModel("MyProperty")
@JsonSubTypes({@JsonSubTypes.Type(value = UrlProperty.class), @JsonSubTypes.Type(value = ValueProperty.class)})
public static abstract class AbstractProperty {
    final String type;

    protected AbstractApiProperty(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }
}

@ApiModel
public static class UrlProperty extends AbstractProperty {
    final URL url;

    public UrlProperty(String type, String url) {
        super(type);
        try {
            this.url = new URL(url);
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException(e);
        }
    }

    public URL getUrl() {
        return url;
    }
}

@ApiModel
public static class ValueProperty extends AbstractProperty {
    final String value;

    public ValueProperty(String type, String value) {
        super(type);
        this.value = value;
    }

    public String getValue() {
        return value;
    }
}

Swagger definitions for these classes looks as follows:

{
  definitions":{
    "MyProperty":{
      "type":"object",
      "properties":{
        "type":{
          "type":"string"
        }
      }
    },
    "UrlProperty":{
      "allOf":[
        {
          "$ref":"#/definitions/MyProperty"
        },
        {
          "type":"object",
          "properties":{
            "type":{
              "type":"string"
            },
            "url":{
              "type":"string",
              "format":"url"
            }
          }
        }
      ]
    },
    "ValueProperty":{
      "allOf":[
        {
          "$ref":"#/definitions/MyProperty"
        },
        {
          "type":"object",
          "properties":{
            "type":{
              "type":"string"
            },
            "value":{
              "type":"string"
            }
          }
        }
      ]
    }
  }
}

I would expected to get UrlProperty and ValueProperty models without the type property, as this property is defined in the base model.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions