[BUG] Problem with setting example in field from parent object when using allOf
Description
There is a problem with java generator, when there is object that has couple of properties and then there is another object that extends with allOf and providing example values for parent properties java generator generates getters for parent and child properties. The type of id from child should have the type from parent.
The generated code is:
public class CaseEvent {
public static final String JSON_PROPERTY_ID = "id";
private Integer id;
...
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
public class CaseStatusEvent extends CaseEvent {
public static final String JSON_PROPERTY_ID = "id";
private Object id;
public static final String JSON_PROPERTY_TYPE = "type";
protected Object type;
public static final String JSON_PROPERTY_OLD_STATUS = "oldStatus";
private CaseStatus oldStatus;
public static final String JSON_PROPERTY_NEW_STATUS = "newStatus";
private CaseStatus newStatus;
public Object getId() {
return id;
}
public void setId(Object id) {
this.id = id;
}
public Object getType() {
return type;
}
public void setType(Object type) {
this.type = type;
}
}
Reported error when compiling: return type java.lang.Object is not compatible with java.lang.Integer
Swagger editor correctly resolves it as:
id, integer, example: 1 id of the caseEvent
date, string, example: 2019-01-10T10:25:13.000Z format is ISO 8601 "YYYY-MM-DDTHH:mm:ss.sssZ"
caseId, integer, example: 1 id of the case
user, User{...}
type*, stringEnum:Array [ 6 ]
openapi-generator version
Using openapi-generator-maven-plugin:5.0.0-beta2 (the same issue with 4.3.0).
OpenAPI declaration file content or url
From: https://ethereum.scorechain.com/swagger.json https://bitcoin.scorechain.com/api_doc/ -> search for CaseStatusEvent
CaseEvent:
type: object
properties:
id:
type: integer
description: id of the caseEvent
example: 1
date:
type: string
description: 'format is ISO 8601 "YYYY-MM-DDTHH:mm:ss.sssZ"'
example: '2019-01-10T10:25:13.000Z'
caseId:
type: integer
description: id of the case
example: 1
user:
$ref: '#/definitions/User'
type:
type: string
enum:
- CaseNoteEvent
- CaseAddressEvent
- CaseTxEvent
- CaseStatusEvent
- CaseAssignmentEvent
- CaseReportEvent
discriminator: type
required:
- type
CaseStatusEvent:
allOf:
- $ref: '#/definitions/CaseEvent'
- type: object
properties:
id:
example: 50
type:
example: CaseStatusEvent
oldStatus:
$ref: '#/definitions/CaseStatus'
newStatus:
$ref: '#/definitions/CaseStatus'
Hi there! Just want to know if there Is anything new about this topic from 2020.
The described use case is very common when you have, ie, defined a ResponseTemplate por a API REST and the only thing that changes between responses is the code example and de message returned
Thanks! :)