[Java] allOf with multiple values is not handled properly
I'm using 4.0.0 version with Maven plugin to generate jaxrs-spec.
<configuration>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<generateSupportingFiles>false</generateSupportingFiles>
<inputSpec>${project.build.directory}/classes/sample.yaml</inputSpec>
<skipValidateSpec>true</skipValidateSpec>
<generatorName>jaxrs-spec</generatorName>
<output>${project.build.directory}/generated-sources</output>
<configOptions>
<sourceFolder>java</sourceFolder>
<apiPackage>${api.package}</apiPackage>
<modelPackage>${model.package}</modelPackage>
<useGenericResponse>true</useGenericResponse>
<useBeanValidation>false</useBeanValidation>
<interfaceOnly>true</interfaceOnly>
<serializableModel>true</serializableModel>
</configOptions>
</configuration>
components:
schemas:
BaseRequest:
type: object
properties:
sampleField:
type: string
Payment:
type: object
properties:
paymentSampleField:
type: string
CreditTransferRequest:
allOf:
- $ref: '#/components/schemas/BaseRequest'
- $ref: '#/components/schemas/Payment'
The model generate doesn't use inheritance.
Generated Java class for CreditTransferRequest is:
...
public class CreditTransferRequest implements Serializable {
private String sampleField;
private String paymentSampleField;
...
BaseRequest class gets generated, but is not used for inheritance.
I'm not sure if this a bug or not but I expect to have a generated class like
...
public class CreditTransferRequest extends BaseRequest implements Serializable {
private String paymentSampleField;
...
I've got a similar behavior with the @typescript-angular@ generator using the cli generator
same for typescript-node
same for jaxrs-jersey. This problem did not exist in version 3.3.4. @wing328 any chances for a fix in next release?
Sorry guys if I'm bother you with such problems, but I think this should be a very basic and fundamental feauture of the code generator. Without it I can't generate proper Object definitions. Currently I have to stick with version 3.3.4 because non of the new versions fixed this problem nor the issue #2058 or any other issues I created and are still open. Is there any chance to get fixed this problems or should I look for an other generator?
Ouch, same problem here with Quarkus. Tried 4.2.3, no luck. Tried 5.1.1, no luck. 3.3.x is too old to have the Quarkus generator.
OK, found a workaround. I had to revert to version 4.2.1 and modify my spec file like this for the inheriting type:
components:
schemas:
EmployeeEntity:
type: object
allOf:
- $ref: "#/components/schemas/Employee"
properties:
assignments:
description: Projects for which the employee has been assigned to a SurveyGroup
items:
$ref: "#/components/schemas/EmployeeAssignment"
type: array
So, instead of having the allOf at the top level of the component schema, it was added as part of the object which does not match the examples from the specification standards HERE
I was mistaken... The properties after the allOf get left out. I tried to use something like this, but then it stops doing inheritance.
components:
schemas:
EmployeeEntity:
type: object
allOf:
- $ref: "#/components/schemas/Employee"
- type: object
properties:
assignments:
description: Projects for which the employee has been assigned to a SurveyGroup
items:
$ref: "#/components/schemas/EmployeeAssignment"
type: array
please consider using openapi normalizer with the rule REF_AS_PARENT_IN_ALLOF enabled: https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md#openapi-normalizer