[BUG] Inheritance is broken
Created by: jonrimmer
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output?
Description
Basic inheritance, as described in the OpenAPI spec does not work.
Instead of creating a class / interface hierarchy using inheritance to represent the composition, all properties are flattened into the subclass.
openapi-generator version
4.0.0-20190508.072036-627 or master
OpenAPI declaration file content or url
schema.yaml:
openapi: "3.0.1"
info:
version: 1.0.0
title: Inheritance test
paths:
/order:
get:
summary: Product order details
operationId: getOrder
responses:
'500':
description: Successful load
content:
application/json:
schema:
$ref: '#/components/schemas/ExtendedErrorModel'
components:
schemas:
BasicErrorModel:
type: object
required:
- message
- code
properties:
message:
type: string
code:
type: integer
minimum: 100
maximum: 600
ExtendedErrorModel:
allOf:
- $ref: '#/components/schemas/BasicErrorModel'
- type: object
required:
- rootCause
properties:
rootCause:
type: string
Expected output
The following class/interface hierarchy: to be generated:
-
BasicErrorModel
<-ExtendedErrorModel
Actual output
Three unrelated classes/interfaces:
BasicErrorModel
ExtendedErrorModel
ExtendedErrorModelAllOf
Command line used for generation
java -jar openapi-generator-cli.jar generate -i ./schema.yaml -g typescript-angular -o src
I have also tried with the Java generator, and it creates the same hierarchy, so it is not just a Typescript problem.
Steps to reproduce
- Copy the above yaml into
schema.yaml
locally. - Run the command above.
- Examine the generated code.
Suggest a fix
I'm not familiar with the codebase, but it appears that getParentName
in ModelUtils.java
only considers a class as a viable parent for inheritance if it has a discriminator, but the above inheritance pattern does not use discriminators.