swagger-core
swagger-core copied to clipboard
Missing properties when using @ApiModel parent attribute
I use the following class structure:
@ApiModel(value = "Task." subTypes = { DetailedTask.class })
public class Task {
@ApiModelProperty(value = "The ID.")
private Long id;
@ApiModelProperty(value = "The name.")
private String name;
@ApiModelProperty(value = "The title.")
private String title;
// getters/setters ommited
}
@ApiModel(value = "DetailedTask.", parent = Task.class)
public class DetailedTask extends Task {
@ApiModelProperty(value = "The attachment")
private Attachment attachment;
// getter/setter ommited
}
@ApiModel(value = "Attachment.")
public class Attachment {
@ApiModelProperty(value = "The attachment ID.")
private Long id;
@ApiModelProperty(value = "The attachment name.")
private String name;
// getter/setter ommited
}
and
@Path("/task")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@OAuth2Protected
@Api(value = "/task", description = API_DESC)
public interface TaskFacade {
@GET
@Path("/task/{taskId}")
@ApiOperation(value = "This method returns task.", produces = MediaType.APPLICATION_JSON, notes = "The task ID must follow the regular expression: "
+ ID_NUMERIC, response = Task.class)
@NotNull
@Valid
Response getTask(@Context @NotNull @Valid final ClientContext clientContext,
@ApiParam(name = "taskId", value = "The task ID", required = true) @PathParam("taskId") @NotNull @Min(value = 1) final Long taskId);
@GET
@Path("/task/{taskId}/detail")
@ApiOperation(value = "This method returns detailed task.",
produces = MediaType.APPLICATION_JSON,
notes = "The task ID must follow regular expression: " + ID_NUMERIC,
response = DetailedTask.class)
@NotNull
@Valid
Response getDetailedTask(@Context @NotNull @Valid final ClientContext clientContext,
@ApiParam(name = "taskId", value = "The task ID", required = true) @PathParam("taskId") @NotNull @Min(value = 1) final Long taskId);
}
In this case in returned model, Attachment's properties are not visible
...
"models": {
"DetailedTask": {
"id": "DetailedTask",
"description": "",
"extends": "Task",
"properties": {
"name": {
"type": "string",
"description": "The name."
},
"id": {
"type": "integer",
"format": "int64",
"description": "The ID."
},
"title": {
"type": "string",
"description": "The title."
},
"attachment": {
"$ref": "Attachment",
"description": "The user ratings of the article"
}
}
},
"Task": {
"id": "Task",
"description": "",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "The ID."
},
"name": {
"type": "string",
"description": "The name."
},
"title": {
"type": "string",
"description": "The title."
}
},
"subTypes": ["DetailedTask"]
},
"Attachment": {
"id": "Attachment",
"description": "",
"properties": {
// HERE SHOULD BE VISIBLE TWO PROPERIES !!!
}
}
}
When I removed parent attribute form annotation @ApiModel in class DetailedTask then it works fine.
In my opinion the problem is related with method expand in ModelInheritenceUtil
Used swagger-core version: swagger-core_2.10-1.3.4
Not sure this is still an issue in 1.5, but should be checked.
Cannot reproduce on the develop_2.0 branch. This JSON was generated from the sample:
"Task.":{
"properties":{
"id":{
"type":"integer",
"format":"int64",
"description":"The ID."
},
"name":{
"type":"string",
"description":"The name."
},
"title":{
"type":"string",
"description":"The title."
}
}
},
"DetailedTask.":{
"allOf":[
{
"$ref":"#/definitions/Task."
},
{
"properties":{
"id":{
"type":"integer",
"format":"int64",
"description":"The ID."
},
"name":{
"type":"string",
"description":"The name."
},
"title":{
"type":"string",
"description":"The title."
},
"attachment":{
"description":"The attachment",
"$ref":"#/definitions/Attachment"
}
}
}
]
},
"Attachment.":{
"properties":{
"id":{
"type":"integer",
"format":"int64",
"description":"The attachment ID."
},
"name":{
"type":"string",
"description":"The attachment name."
}
}
}
Closing as no longer relevant.