Skip to content

Derived classes without @ApiModel annotation are not added to Swagger definition #1372

@tomtit

Description

@tomtit

Swagger version is 1.5.2 (the same issue in 1.5.4-SNAPSHOT).
Derived classes (UrlProperty and ValueProperty) from the listing below are not added to Swagger definition:

@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;
    }
}

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;
    }
}

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;
    }
}

To get UrlProperty and ValueProperty in Swagger definition I have to remove the @ApiModel annotation from the declaration of the base class (AbstractProperty) or add @ApiModel without arguments to all derived classes.

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