1.5.x: Definition of descendant classes using ApiModel.subTypes is not working
Definition of descendant classes is not reflected in the documentation. I'm using Swagger 1.5.2-M1.
Example of my base class
@ApiModel(description = "Basic class for timesheet entry", subTypes = {TimesheetProjectEntryWire.class, TimesheetAdminEntryWire.class}, discriminator = "type")
@JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonTypeIdResolver(TimesheetEntryTypeIdResolver.class)
public abstract class TimesheetEntryWireBase {}
one of the descendant classes is
@ApiModel(description = "Timesheet project entry object", parent = TimesheetEntryWireBase.class)
public class TimesheetProjectEntryWire extends TimesheetEntryWireBase {}
resulting documentation doesn't have descendant classes. Here is output json
"TimesheetEntryWireBase": {
"required": [
"entryDate",
"entryHours",
"id",
"isBillable",
"notes",
"type"
],
"properties": {
"type": {
"type": "string",
"description": "entry type",
"enum": [
"PROJECT",
"ADMINISTRATIVE",
"UNKNOWN"
]
},
"id": {
"type": "integer",
"format": "int64",
"description": "timesheet id"
},
"entryHours": {
"type": "number",
"format": "double",
"description": "number of hours spent"
},
"isBillable": {
"type": "boolean",
"description": "are hours billable?"
},
"notes": {
"type": "string",
"description": "text notes"
},
"entryDate": {
"type": "string",
"description": "entry date"
}
},
"description": "Basic class for timesheet entry",
"discriminator": "type"
}
What am I missing ?
This is expected, he subtype support is expected in M2, out shortly
Great! What's the ETA roughly ?
We are targeting 3/14 but it's possibly a week out.
Duplicate of #847.
I don't know if you guys had any updates on this but as of 3 days ago this bug was still present in develop_2.0 branch.
Reopening for now pending further investigation. I believe the behavior here has changed from 1.3.
I've just tested this. All works well.
Class structure:
@ApiModel(description = "Basic class for timesheet entry", subTypes = {TimesheetProjectEntryWire.class, TimesheetAdminEntryWire.class}, discriminator = "type")
@JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonTypeIdResolver(TimesheetEntryTypeIdResolver.class)
public abstract class TimesheetEntryWireBase {
}
@ApiModel(description = "Timesheet project entry object", parent = TimesheetEntryWireBase.class)
abstract public class TimesheetEntryTypeIdResolver extends TimesheetEntryWireBase implements TypeIdResolver {
}
@ApiModel(description = "Timesheet project entry object", parent = TimesheetEntryWireBase.class)
public class TimesheetAdminEntryWire extends TimesheetEntryWireBase {
}
@ApiModel(description = "Timesheet project entry object", parent = TimesheetEntryWireBase.class)
public class TimesheetProjectEntryWire extends TimesheetEntryWireBase {
}
JSON-output:
{
"TimesheetAdminEntryWire" : {
"allOf" : [ {
"$ref" : "#/definitions/TimesheetEntryWireBase"
}, {
"type" : "object",
"description" : "Timesheet project entry object"
} ]
},
"TimesheetEntryWireBase" : {
"type" : "object",
"discriminator" : "type",
"description" : "Basic class for timesheet entry"
},
"TimesheetProjectEntryWire" : {
"allOf" : [ {
"$ref" : "#/definitions/TimesheetEntryWireBase"
}, {
"type" : "object",
"description" : "Timesheet project entry object"
} ]
}
}
@cppexpert - closing this now as tested by @MDoumin. Please reopen if still an issue.
Hey, I'm trying to generate a python REST client based on Swagger documentation, using a swagger.json generated by swagger-maven-plugin-3.1.0 I have 2 DTOs that extend an abstract base class:
@ApiModel(subTypes = {FileSourceDTO.class, MemorySourceDTO.class}, discriminator = "classType")
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "classType")
@JsonSubTypes({
@JsonSubTypes.Type(value = FileSourceDTO.class, name = "FileSourceDTO"),
@JsonSubTypes.Type(value = MemorySourceDTO.class, name = "MemorySourceDTO") })
public abstract class LogSourceDTO implements BaseIdentifiableDTO<UUID> {..}
@ApiModel(description = "FileSourceDTO", parent = LogSourceDTO.class)
publi` class FileSourceDTO extends LogSourceDTO {..}
@ApiModel(description = "MemorySourceDTO", parent = LogSourceDTO.class)
public class MemorySourceDTO extends LogSourceDTO {..}
In the resulting REST client, the FileSourceDTO and MemorySourceDTO classes don't contain a 'classType' field (which should be in the REST request as it is generated and expected by jackson) even though it should.
In addition, when I called (using the generated python REST client) an API method that returns an object of one of the children classes, an object of the abstract LogSourceDTO class was actually created instread (losing all the additional fields the children class adds over it).
I tried adding the above @ApiModel annotations after reading the comments here, but it doesn't seem to solve this. Am I doing something wrong?
Many, many thanks.
@itayavra - if you're using the swagger-magen-plugin, you'd need to open an issue on that project.
Hey, I'm trying to generate a python REST client based on Swagger documentation, using a swagger.json generated by swagger-maven-plugin-3.1.0 I have 2 DTOs that extend an abstract base class:
@ApiModel(subTypes = {FileSourceDTO.class, MemorySourceDTO.class}, discriminator = "classType") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "classType") @JsonSubTypes({ @JsonSubTypes.Type(value = FileSourceDTO.class, name = "FileSourceDTO"), @JsonSubTypes.Type(value = MemorySourceDTO.class, name = "MemorySourceDTO") }) public abstract class LogSourceDTO implements BaseIdentifiableDTO<UUID> {..}@ApiModel(description = "FileSourceDTO", parent = LogSourceDTO.class) publi` class FileSourceDTO extends LogSourceDTO {..}@ApiModel(description = "MemorySourceDTO", parent = LogSourceDTO.class) public class MemorySourceDTO extends LogSourceDTO {..}In the resulting REST client, the FileSourceDTO and MemorySourceDTO classes don't contain a 'classType' field (which should be in the REST request as it is generated and expected by jackson) even though it should.
In addition, when I called (using the generated python REST client) an API method that returns an object of one of the children classes, an object of the abstract LogSourceDTO class was actually created instread (losing all the additional fields the children class adds over it).
I tried adding the above @apimodel annotations after reading the comments here, butble it doesn't seem to solve this. Am I doing something wrong?
Many, many thanks.
Are you able to get any work around it?